]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-3.0-3.15.10-201408212335.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.15.10-201408212335.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..f2438cb 100644
38753 --- a/drivers/char/random.c
38754 +++ b/drivers/char/random.c
38755 @@ -284,9 +284,6 @@
38756 /*
38757 * To allow fractional bits to be tracked, the entropy_count field is
38758 * denominated in units of 1/8th bits.
38759 - *
38760 - * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
38761 - * credit_entropy_bits() needs to be 64 bits wide.
38762 */
38763 #define ENTROPY_SHIFT 3
38764 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
38765 @@ -433,9 +430,9 @@ struct entropy_store {
38766 };
38767
38768 static void push_to_pool(struct work_struct *work);
38769 -static __u32 input_pool_data[INPUT_POOL_WORDS];
38770 -static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
38771 -static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
38772 +static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
38773 +static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38774 +static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38775
38776 static struct entropy_store input_pool = {
38777 .poolinfo = &poolinfo_table[0],
38778 @@ -524,8 +521,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
38779 input_rotate = (input_rotate + (i ? 7 : 14)) & 31;
38780 }
38781
38782 - ACCESS_ONCE(r->input_rotate) = input_rotate;
38783 - ACCESS_ONCE(r->add_ptr) = i;
38784 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
38785 + ACCESS_ONCE_RW(r->add_ptr) = i;
38786 smp_wmb();
38787
38788 if (out)
38789 @@ -632,7 +629,7 @@ retry:
38790 /* The +2 corresponds to the /4 in the denominator */
38791
38792 do {
38793 - unsigned int anfrac = min(pnfrac, pool_size/2);
38794 + u64 anfrac = min(pnfrac, pool_size/2);
38795 unsigned int add =
38796 ((pool_size - entropy_count)*anfrac*3) >> s;
38797
38798 @@ -1176,7 +1173,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
38799
38800 extract_buf(r, tmp);
38801 i = min_t(int, nbytes, EXTRACT_SIZE);
38802 - if (copy_to_user(buf, tmp, i)) {
38803 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
38804 ret = -EFAULT;
38805 break;
38806 }
38807 @@ -1566,7 +1563,7 @@ static char sysctl_bootid[16];
38808 static int proc_do_uuid(struct ctl_table *table, int write,
38809 void __user *buffer, size_t *lenp, loff_t *ppos)
38810 {
38811 - struct ctl_table fake_table;
38812 + ctl_table_no_const fake_table;
38813 unsigned char buf[64], tmp_uuid[16], *uuid;
38814
38815 uuid = table->data;
38816 @@ -1596,7 +1593,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
38817 static int proc_do_entropy(ctl_table *table, int write,
38818 void __user *buffer, size_t *lenp, loff_t *ppos)
38819 {
38820 - ctl_table fake_table;
38821 + ctl_table_no_const fake_table;
38822 int entropy_count;
38823
38824 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
38825 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
38826 index 7cc1fe22..b602d6b 100644
38827 --- a/drivers/char/sonypi.c
38828 +++ b/drivers/char/sonypi.c
38829 @@ -54,6 +54,7 @@
38830
38831 #include <asm/uaccess.h>
38832 #include <asm/io.h>
38833 +#include <asm/local.h>
38834
38835 #include <linux/sonypi.h>
38836
38837 @@ -490,7 +491,7 @@ static struct sonypi_device {
38838 spinlock_t fifo_lock;
38839 wait_queue_head_t fifo_proc_list;
38840 struct fasync_struct *fifo_async;
38841 - int open_count;
38842 + local_t open_count;
38843 int model;
38844 struct input_dev *input_jog_dev;
38845 struct input_dev *input_key_dev;
38846 @@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
38847 static int sonypi_misc_release(struct inode *inode, struct file *file)
38848 {
38849 mutex_lock(&sonypi_device.lock);
38850 - sonypi_device.open_count--;
38851 + local_dec(&sonypi_device.open_count);
38852 mutex_unlock(&sonypi_device.lock);
38853 return 0;
38854 }
38855 @@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
38856 {
38857 mutex_lock(&sonypi_device.lock);
38858 /* Flush input queue on first open */
38859 - if (!sonypi_device.open_count)
38860 + if (!local_read(&sonypi_device.open_count))
38861 kfifo_reset(&sonypi_device.fifo);
38862 - sonypi_device.open_count++;
38863 + local_inc(&sonypi_device.open_count);
38864 mutex_unlock(&sonypi_device.lock);
38865
38866 return 0;
38867 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
38868 index b9a57fa..5bb9e38 100644
38869 --- a/drivers/char/tpm/tpm_acpi.c
38870 +++ b/drivers/char/tpm/tpm_acpi.c
38871 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
38872 virt = acpi_os_map_memory(start, len);
38873 if (!virt) {
38874 kfree(log->bios_event_log);
38875 + log->bios_event_log = NULL;
38876 printk("%s: ERROR - Unable to map memory\n", __func__);
38877 return -EIO;
38878 }
38879
38880 - memcpy_fromio(log->bios_event_log, virt, len);
38881 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
38882
38883 acpi_os_unmap_memory(virt, len);
38884 return 0;
38885 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
38886 index 59f7cb2..bac8b6d 100644
38887 --- a/drivers/char/tpm/tpm_eventlog.c
38888 +++ b/drivers/char/tpm/tpm_eventlog.c
38889 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
38890 event = addr;
38891
38892 if ((event->event_type == 0 && event->event_size == 0) ||
38893 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
38894 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
38895 return NULL;
38896
38897 return addr;
38898 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
38899 return NULL;
38900
38901 if ((event->event_type == 0 && event->event_size == 0) ||
38902 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
38903 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
38904 return NULL;
38905
38906 (*pos)++;
38907 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
38908 int i;
38909
38910 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
38911 - seq_putc(m, data[i]);
38912 + if (!seq_putc(m, data[i]))
38913 + return -EFAULT;
38914
38915 return 0;
38916 }
38917 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
38918 index 60aafb8..10c08e0 100644
38919 --- a/drivers/char/virtio_console.c
38920 +++ b/drivers/char/virtio_console.c
38921 @@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
38922 if (to_user) {
38923 ssize_t ret;
38924
38925 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
38926 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
38927 if (ret)
38928 return -EFAULT;
38929 } else {
38930 @@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
38931 if (!port_has_data(port) && !port->host_connected)
38932 return 0;
38933
38934 - return fill_readbuf(port, ubuf, count, true);
38935 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
38936 }
38937
38938 static int wait_port_writable(struct port *port, bool nonblock)
38939 diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
38940 index 57a078e..c17cde8 100644
38941 --- a/drivers/clk/clk-composite.c
38942 +++ b/drivers/clk/clk-composite.c
38943 @@ -146,7 +146,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
38944 struct clk *clk;
38945 struct clk_init_data init;
38946 struct clk_composite *composite;
38947 - struct clk_ops *clk_composite_ops;
38948 + clk_ops_no_const *clk_composite_ops;
38949
38950 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
38951 if (!composite) {
38952 diff --git a/drivers/clk/socfpga/clk-gate.c b/drivers/clk/socfpga/clk-gate.c
38953 index 501d513..fb0ecf9 100644
38954 --- a/drivers/clk/socfpga/clk-gate.c
38955 +++ b/drivers/clk/socfpga/clk-gate.c
38956 @@ -22,6 +22,7 @@
38957 #include <linux/mfd/syscon.h>
38958 #include <linux/of.h>
38959 #include <linux/regmap.h>
38960 +#include <asm/pgtable.h>
38961
38962 #include "clk.h"
38963
38964 @@ -175,7 +176,7 @@ static int socfpga_clk_prepare(struct clk_hw *hwclk)
38965 return 0;
38966 }
38967
38968 -static struct clk_ops gateclk_ops = {
38969 +static clk_ops_no_const gateclk_ops __read_only = {
38970 .prepare = socfpga_clk_prepare,
38971 .recalc_rate = socfpga_clk_recalc_rate,
38972 .get_parent = socfpga_clk_get_parent,
38973 @@ -209,8 +210,10 @@ static void __init __socfpga_gate_init(struct device_node *node,
38974 socfpga_clk->hw.reg = clk_mgr_base_addr + clk_gate[0];
38975 socfpga_clk->hw.bit_idx = clk_gate[1];
38976
38977 - gateclk_ops.enable = clk_gate_ops.enable;
38978 - gateclk_ops.disable = clk_gate_ops.disable;
38979 + pax_open_kernel();
38980 + *(void **)&gateclk_ops.enable = clk_gate_ops.enable;
38981 + *(void **)&gateclk_ops.disable = clk_gate_ops.disable;
38982 + pax_close_kernel();
38983 }
38984
38985 rc = of_property_read_u32(node, "fixed-divider", &fixed_div);
38986 diff --git a/drivers/clk/socfpga/clk-pll.c b/drivers/clk/socfpga/clk-pll.c
38987 index de6da95..c98278b 100644
38988 --- a/drivers/clk/socfpga/clk-pll.c
38989 +++ b/drivers/clk/socfpga/clk-pll.c
38990 @@ -21,6 +21,7 @@
38991 #include <linux/io.h>
38992 #include <linux/of.h>
38993 #include <linux/of_address.h>
38994 +#include <asm/pgtable.h>
38995
38996 #include "clk.h"
38997
38998 @@ -76,7 +77,7 @@ static u8 clk_pll_get_parent(struct clk_hw *hwclk)
38999 CLK_MGR_PLL_CLK_SRC_MASK;
39000 }
39001
39002 -static struct clk_ops clk_pll_ops = {
39003 +static clk_ops_no_const clk_pll_ops __read_only = {
39004 .recalc_rate = clk_pll_recalc_rate,
39005 .get_parent = clk_pll_get_parent,
39006 };
39007 @@ -120,8 +121,10 @@ static __init struct clk *__socfpga_pll_init(struct device_node *node,
39008 pll_clk->hw.hw.init = &init;
39009
39010 pll_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
39011 - clk_pll_ops.enable = clk_gate_ops.enable;
39012 - clk_pll_ops.disable = clk_gate_ops.disable;
39013 + pax_open_kernel();
39014 + *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
39015 + *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
39016 + pax_close_kernel();
39017
39018 clk = clk_register(NULL, &pll_clk->hw.hw);
39019 if (WARN_ON(IS_ERR(clk))) {
39020 diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
39021 index 000e4e0..4770351 100644
39022 --- a/drivers/cpufreq/acpi-cpufreq.c
39023 +++ b/drivers/cpufreq/acpi-cpufreq.c
39024 @@ -676,8 +676,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39025 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
39026 per_cpu(acfreq_data, cpu) = data;
39027
39028 - if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
39029 - acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39030 + if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
39031 + pax_open_kernel();
39032 + *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39033 + pax_close_kernel();
39034 + }
39035
39036 result = acpi_processor_register_performance(data->acpi_data, cpu);
39037 if (result)
39038 @@ -810,7 +813,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39039 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
39040 break;
39041 case ACPI_ADR_SPACE_FIXED_HARDWARE:
39042 - acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39043 + pax_open_kernel();
39044 + *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39045 + pax_close_kernel();
39046 break;
39047 default:
39048 break;
39049 @@ -904,8 +909,10 @@ static void __init acpi_cpufreq_boost_init(void)
39050 if (!msrs)
39051 return;
39052
39053 - acpi_cpufreq_driver.boost_supported = true;
39054 - acpi_cpufreq_driver.boost_enabled = boost_state(0);
39055 + pax_open_kernel();
39056 + *(bool *)&acpi_cpufreq_driver.boost_supported = true;
39057 + *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
39058 + pax_close_kernel();
39059
39060 cpu_notifier_register_begin();
39061
39062 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
39063 index dcac12d..f12df60 100644
39064 --- a/drivers/cpufreq/cpufreq.c
39065 +++ b/drivers/cpufreq/cpufreq.c
39066 @@ -2024,7 +2024,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
39067 }
39068
39069 mutex_lock(&cpufreq_governor_mutex);
39070 - list_del(&governor->governor_list);
39071 + pax_list_del(&governor->governor_list);
39072 mutex_unlock(&cpufreq_governor_mutex);
39073 return;
39074 }
39075 @@ -2240,7 +2240,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
39076 return NOTIFY_OK;
39077 }
39078
39079 -static struct notifier_block __refdata cpufreq_cpu_notifier = {
39080 +static struct notifier_block cpufreq_cpu_notifier = {
39081 .notifier_call = cpufreq_cpu_callback,
39082 };
39083
39084 @@ -2280,13 +2280,17 @@ int cpufreq_boost_trigger_state(int state)
39085 return 0;
39086
39087 write_lock_irqsave(&cpufreq_driver_lock, flags);
39088 - cpufreq_driver->boost_enabled = state;
39089 + pax_open_kernel();
39090 + *(bool *)&cpufreq_driver->boost_enabled = state;
39091 + pax_close_kernel();
39092 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39093
39094 ret = cpufreq_driver->set_boost(state);
39095 if (ret) {
39096 write_lock_irqsave(&cpufreq_driver_lock, flags);
39097 - cpufreq_driver->boost_enabled = !state;
39098 + pax_open_kernel();
39099 + *(bool *)&cpufreq_driver->boost_enabled = !state;
39100 + pax_close_kernel();
39101 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39102
39103 pr_err("%s: Cannot %s BOOST\n",
39104 @@ -2342,8 +2346,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39105
39106 pr_debug("trying to register driver %s\n", driver_data->name);
39107
39108 - if (driver_data->setpolicy)
39109 - driver_data->flags |= CPUFREQ_CONST_LOOPS;
39110 + if (driver_data->setpolicy) {
39111 + pax_open_kernel();
39112 + *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
39113 + pax_close_kernel();
39114 + }
39115
39116 write_lock_irqsave(&cpufreq_driver_lock, flags);
39117 if (cpufreq_driver) {
39118 @@ -2358,8 +2365,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39119 * Check if driver provides function to enable boost -
39120 * if not, use cpufreq_boost_set_sw as default
39121 */
39122 - if (!cpufreq_driver->set_boost)
39123 - cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39124 + if (!cpufreq_driver->set_boost) {
39125 + pax_open_kernel();
39126 + *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39127 + pax_close_kernel();
39128 + }
39129
39130 ret = cpufreq_sysfs_create_file(&boost.attr);
39131 if (ret) {
39132 diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
39133 index e1c6433..31203ae 100644
39134 --- a/drivers/cpufreq/cpufreq_governor.c
39135 +++ b/drivers/cpufreq/cpufreq_governor.c
39136 @@ -191,7 +191,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39137 struct dbs_data *dbs_data;
39138 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
39139 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
39140 - struct od_ops *od_ops = NULL;
39141 + const struct od_ops *od_ops = NULL;
39142 struct od_dbs_tuners *od_tuners = NULL;
39143 struct cs_dbs_tuners *cs_tuners = NULL;
39144 struct cpu_dbs_common_info *cpu_cdbs;
39145 @@ -257,7 +257,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39146
39147 if ((cdata->governor == GOV_CONSERVATIVE) &&
39148 (!policy->governor->initialized)) {
39149 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39150 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39151
39152 cpufreq_register_notifier(cs_ops->notifier_block,
39153 CPUFREQ_TRANSITION_NOTIFIER);
39154 @@ -277,7 +277,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39155
39156 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
39157 (policy->governor->initialized == 1)) {
39158 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39159 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39160
39161 cpufreq_unregister_notifier(cs_ops->notifier_block,
39162 CPUFREQ_TRANSITION_NOTIFIER);
39163 diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
39164 index bfb9ae1..e1d3a7e 100644
39165 --- a/drivers/cpufreq/cpufreq_governor.h
39166 +++ b/drivers/cpufreq/cpufreq_governor.h
39167 @@ -205,7 +205,7 @@ struct common_dbs_data {
39168 void (*exit)(struct dbs_data *dbs_data);
39169
39170 /* Governor specific ops, see below */
39171 - void *gov_ops;
39172 + const void *gov_ops;
39173 };
39174
39175 /* Governor Per policy data */
39176 @@ -225,7 +225,7 @@ struct od_ops {
39177 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
39178 unsigned int freq_next, unsigned int relation);
39179 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
39180 -};
39181 +} __no_const;
39182
39183 struct cs_ops {
39184 struct notifier_block *notifier_block;
39185 diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
39186 index 18d4091..434be15 100644
39187 --- a/drivers/cpufreq/cpufreq_ondemand.c
39188 +++ b/drivers/cpufreq/cpufreq_ondemand.c
39189 @@ -521,7 +521,7 @@ static void od_exit(struct dbs_data *dbs_data)
39190
39191 define_get_cpu_dbs_routines(od_cpu_dbs_info);
39192
39193 -static struct od_ops od_ops = {
39194 +static struct od_ops od_ops __read_only = {
39195 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
39196 .powersave_bias_target = generic_powersave_bias_target,
39197 .freq_increase = dbs_freq_increase,
39198 @@ -576,14 +576,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
39199 (struct cpufreq_policy *, unsigned int, unsigned int),
39200 unsigned int powersave_bias)
39201 {
39202 - od_ops.powersave_bias_target = f;
39203 + pax_open_kernel();
39204 + *(void **)&od_ops.powersave_bias_target = f;
39205 + pax_close_kernel();
39206 od_set_powersave_bias(powersave_bias);
39207 }
39208 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
39209
39210 void od_unregister_powersave_bias_handler(void)
39211 {
39212 - od_ops.powersave_bias_target = generic_powersave_bias_target;
39213 + pax_open_kernel();
39214 + *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
39215 + pax_close_kernel();
39216 od_set_powersave_bias(0);
39217 }
39218 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
39219 diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
39220 index 870eecc..787bbca 100644
39221 --- a/drivers/cpufreq/intel_pstate.c
39222 +++ b/drivers/cpufreq/intel_pstate.c
39223 @@ -125,10 +125,10 @@ struct pstate_funcs {
39224 struct cpu_defaults {
39225 struct pstate_adjust_policy pid_policy;
39226 struct pstate_funcs funcs;
39227 -};
39228 +} __do_const;
39229
39230 static struct pstate_adjust_policy pid_params;
39231 -static struct pstate_funcs pstate_funcs;
39232 +static struct pstate_funcs *pstate_funcs;
39233
39234 struct perf_limits {
39235 int no_turbo;
39236 @@ -530,7 +530,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
39237
39238 cpu->pstate.current_pstate = pstate;
39239
39240 - pstate_funcs.set(cpu, pstate);
39241 + pstate_funcs->set(cpu, pstate);
39242 }
39243
39244 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
39245 @@ -552,12 +552,12 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
39246 {
39247 sprintf(cpu->name, "Intel 2nd generation core");
39248
39249 - cpu->pstate.min_pstate = pstate_funcs.get_min();
39250 - cpu->pstate.max_pstate = pstate_funcs.get_max();
39251 - cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
39252 + cpu->pstate.min_pstate = pstate_funcs->get_min();
39253 + cpu->pstate.max_pstate = pstate_funcs->get_max();
39254 + cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
39255
39256 - if (pstate_funcs.get_vid)
39257 - pstate_funcs.get_vid(cpu);
39258 + if (pstate_funcs->get_vid)
39259 + pstate_funcs->get_vid(cpu);
39260 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate);
39261 }
39262
39263 @@ -847,9 +847,9 @@ static int intel_pstate_msrs_not_valid(void)
39264 rdmsrl(MSR_IA32_APERF, aperf);
39265 rdmsrl(MSR_IA32_MPERF, mperf);
39266
39267 - if (!pstate_funcs.get_max() ||
39268 - !pstate_funcs.get_min() ||
39269 - !pstate_funcs.get_turbo())
39270 + if (!pstate_funcs->get_max() ||
39271 + !pstate_funcs->get_min() ||
39272 + !pstate_funcs->get_turbo())
39273 return -ENODEV;
39274
39275 rdmsrl(MSR_IA32_APERF, tmp);
39276 @@ -863,7 +863,7 @@ static int intel_pstate_msrs_not_valid(void)
39277 return 0;
39278 }
39279
39280 -static void copy_pid_params(struct pstate_adjust_policy *policy)
39281 +static void copy_pid_params(const struct pstate_adjust_policy *policy)
39282 {
39283 pid_params.sample_rate_ms = policy->sample_rate_ms;
39284 pid_params.p_gain_pct = policy->p_gain_pct;
39285 @@ -875,11 +875,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
39286
39287 static void copy_cpu_funcs(struct pstate_funcs *funcs)
39288 {
39289 - pstate_funcs.get_max = funcs->get_max;
39290 - pstate_funcs.get_min = funcs->get_min;
39291 - pstate_funcs.get_turbo = funcs->get_turbo;
39292 - pstate_funcs.set = funcs->set;
39293 - pstate_funcs.get_vid = funcs->get_vid;
39294 + pstate_funcs = funcs;
39295 }
39296
39297 #if IS_ENABLED(CONFIG_ACPI)
39298 diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
39299 index 529cfd9..0e28fff 100644
39300 --- a/drivers/cpufreq/p4-clockmod.c
39301 +++ b/drivers/cpufreq/p4-clockmod.c
39302 @@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39303 case 0x0F: /* Core Duo */
39304 case 0x16: /* Celeron Core */
39305 case 0x1C: /* Atom */
39306 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39307 + pax_open_kernel();
39308 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39309 + pax_close_kernel();
39310 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
39311 case 0x0D: /* Pentium M (Dothan) */
39312 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39313 + pax_open_kernel();
39314 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39315 + pax_close_kernel();
39316 /* fall through */
39317 case 0x09: /* Pentium M (Banias) */
39318 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
39319 @@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39320
39321 /* on P-4s, the TSC runs with constant frequency independent whether
39322 * throttling is active or not. */
39323 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39324 + pax_open_kernel();
39325 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39326 + pax_close_kernel();
39327
39328 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
39329 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
39330 diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
39331 index 9bb42ba..b01b4a2 100644
39332 --- a/drivers/cpufreq/sparc-us3-cpufreq.c
39333 +++ b/drivers/cpufreq/sparc-us3-cpufreq.c
39334 @@ -18,14 +18,12 @@
39335 #include <asm/head.h>
39336 #include <asm/timer.h>
39337
39338 -static struct cpufreq_driver *cpufreq_us3_driver;
39339 -
39340 struct us3_freq_percpu_info {
39341 struct cpufreq_frequency_table table[4];
39342 };
39343
39344 /* Indexed by cpu number. */
39345 -static struct us3_freq_percpu_info *us3_freq_table;
39346 +static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
39347
39348 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
39349 * in the Safari config register.
39350 @@ -156,16 +154,27 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
39351
39352 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
39353 {
39354 - if (cpufreq_us3_driver)
39355 - us3_freq_target(policy, 0);
39356 + us3_freq_target(policy, 0);
39357
39358 return 0;
39359 }
39360
39361 +static int __init us3_freq_init(void);
39362 +static void __exit us3_freq_exit(void);
39363 +
39364 +static struct cpufreq_driver cpufreq_us3_driver = {
39365 + .init = us3_freq_cpu_init,
39366 + .verify = cpufreq_generic_frequency_table_verify,
39367 + .target_index = us3_freq_target,
39368 + .get = us3_freq_get,
39369 + .exit = us3_freq_cpu_exit,
39370 + .name = "UltraSPARC-III",
39371 +
39372 +};
39373 +
39374 static int __init us3_freq_init(void)
39375 {
39376 unsigned long manuf, impl, ver;
39377 - int ret;
39378
39379 if (tlb_type != cheetah && tlb_type != cheetah_plus)
39380 return -ENODEV;
39381 @@ -178,55 +187,15 @@ static int __init us3_freq_init(void)
39382 (impl == CHEETAH_IMPL ||
39383 impl == CHEETAH_PLUS_IMPL ||
39384 impl == JAGUAR_IMPL ||
39385 - impl == PANTHER_IMPL)) {
39386 - struct cpufreq_driver *driver;
39387 -
39388 - ret = -ENOMEM;
39389 - driver = kzalloc(sizeof(*driver), GFP_KERNEL);
39390 - if (!driver)
39391 - goto err_out;
39392 -
39393 - us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
39394 - GFP_KERNEL);
39395 - if (!us3_freq_table)
39396 - goto err_out;
39397 -
39398 - driver->init = us3_freq_cpu_init;
39399 - driver->verify = cpufreq_generic_frequency_table_verify;
39400 - driver->target_index = us3_freq_target;
39401 - driver->get = us3_freq_get;
39402 - driver->exit = us3_freq_cpu_exit;
39403 - strcpy(driver->name, "UltraSPARC-III");
39404 -
39405 - cpufreq_us3_driver = driver;
39406 - ret = cpufreq_register_driver(driver);
39407 - if (ret)
39408 - goto err_out;
39409 -
39410 - return 0;
39411 -
39412 -err_out:
39413 - if (driver) {
39414 - kfree(driver);
39415 - cpufreq_us3_driver = NULL;
39416 - }
39417 - kfree(us3_freq_table);
39418 - us3_freq_table = NULL;
39419 - return ret;
39420 - }
39421 + impl == PANTHER_IMPL))
39422 + return cpufreq_register_driver(&cpufreq_us3_driver);
39423
39424 return -ENODEV;
39425 }
39426
39427 static void __exit us3_freq_exit(void)
39428 {
39429 - if (cpufreq_us3_driver) {
39430 - cpufreq_unregister_driver(cpufreq_us3_driver);
39431 - kfree(cpufreq_us3_driver);
39432 - cpufreq_us3_driver = NULL;
39433 - kfree(us3_freq_table);
39434 - us3_freq_table = NULL;
39435 - }
39436 + cpufreq_unregister_driver(&cpufreq_us3_driver);
39437 }
39438
39439 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
39440 diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
39441 index 6723f03..3465190 100644
39442 --- a/drivers/cpufreq/speedstep-centrino.c
39443 +++ b/drivers/cpufreq/speedstep-centrino.c
39444 @@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
39445 !cpu_has(cpu, X86_FEATURE_EST))
39446 return -ENODEV;
39447
39448 - if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
39449 - centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39450 + if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
39451 + pax_open_kernel();
39452 + *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39453 + pax_close_kernel();
39454 + }
39455
39456 if (policy->cpu != 0)
39457 return -ENODEV;
39458 diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
39459 index 136d6a2..06e373d 100644
39460 --- a/drivers/cpuidle/driver.c
39461 +++ b/drivers/cpuidle/driver.c
39462 @@ -202,7 +202,7 @@ static int poll_idle(struct cpuidle_device *dev,
39463
39464 static void poll_idle_init(struct cpuidle_driver *drv)
39465 {
39466 - struct cpuidle_state *state = &drv->states[0];
39467 + cpuidle_state_no_const *state = &drv->states[0];
39468
39469 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
39470 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
39471 diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
39472 index ca89412..a7b9c49 100644
39473 --- a/drivers/cpuidle/governor.c
39474 +++ b/drivers/cpuidle/governor.c
39475 @@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
39476 mutex_lock(&cpuidle_lock);
39477 if (__cpuidle_find_governor(gov->name) == NULL) {
39478 ret = 0;
39479 - list_add_tail(&gov->governor_list, &cpuidle_governors);
39480 + pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
39481 if (!cpuidle_curr_governor ||
39482 cpuidle_curr_governor->rating < gov->rating)
39483 cpuidle_switch_governor(gov);
39484 diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
39485 index efe2f17..b8124f9 100644
39486 --- a/drivers/cpuidle/sysfs.c
39487 +++ b/drivers/cpuidle/sysfs.c
39488 @@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
39489 NULL
39490 };
39491
39492 -static struct attribute_group cpuidle_attr_group = {
39493 +static attribute_group_no_const cpuidle_attr_group = {
39494 .attrs = cpuidle_default_attrs,
39495 .name = "cpuidle",
39496 };
39497 diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
39498 index 12fea3e..1e28f47 100644
39499 --- a/drivers/crypto/hifn_795x.c
39500 +++ b/drivers/crypto/hifn_795x.c
39501 @@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
39502 MODULE_PARM_DESC(hifn_pll_ref,
39503 "PLL reference clock (pci[freq] or ext[freq], default ext)");
39504
39505 -static atomic_t hifn_dev_number;
39506 +static atomic_unchecked_t hifn_dev_number;
39507
39508 #define ACRYPTO_OP_DECRYPT 0
39509 #define ACRYPTO_OP_ENCRYPT 1
39510 @@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
39511 goto err_out_disable_pci_device;
39512
39513 snprintf(name, sizeof(name), "hifn%d",
39514 - atomic_inc_return(&hifn_dev_number)-1);
39515 + atomic_inc_return_unchecked(&hifn_dev_number)-1);
39516
39517 err = pci_request_regions(pdev, name);
39518 if (err)
39519 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
39520 index 2042ec3..a9ce67f 100644
39521 --- a/drivers/devfreq/devfreq.c
39522 +++ b/drivers/devfreq/devfreq.c
39523 @@ -616,7 +616,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
39524 goto err_out;
39525 }
39526
39527 - list_add(&governor->node, &devfreq_governor_list);
39528 + pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
39529
39530 list_for_each_entry(devfreq, &devfreq_list, node) {
39531 int ret = 0;
39532 @@ -704,7 +704,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
39533 }
39534 }
39535
39536 - list_del(&governor->node);
39537 + pax_list_del((struct list_head *)&governor->node);
39538 err_out:
39539 mutex_unlock(&devfreq_list_lock);
39540
39541 diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
39542 index 5239677..1cb71a8 100644
39543 --- a/drivers/dma/sh/shdma-base.c
39544 +++ b/drivers/dma/sh/shdma-base.c
39545 @@ -267,8 +267,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
39546 schan->slave_id = -EINVAL;
39547 }
39548
39549 - schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
39550 - sdev->desc_size, GFP_KERNEL);
39551 + schan->desc = kcalloc(sdev->desc_size,
39552 + NR_DESCS_PER_CHANNEL, GFP_KERNEL);
39553 if (!schan->desc) {
39554 ret = -ENOMEM;
39555 goto edescalloc;
39556 diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
39557 index dda7e75..0a4c867 100644
39558 --- a/drivers/dma/sh/shdmac.c
39559 +++ b/drivers/dma/sh/shdmac.c
39560 @@ -513,7 +513,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
39561 return ret;
39562 }
39563
39564 -static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
39565 +static struct notifier_block sh_dmae_nmi_notifier = {
39566 .notifier_call = sh_dmae_nmi_handler,
39567
39568 /* Run before NMI debug handler and KGDB */
39569 diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
39570 index 592af5f..bb1d583 100644
39571 --- a/drivers/edac/edac_device.c
39572 +++ b/drivers/edac/edac_device.c
39573 @@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
39574 */
39575 int edac_device_alloc_index(void)
39576 {
39577 - static atomic_t device_indexes = ATOMIC_INIT(0);
39578 + static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
39579
39580 - return atomic_inc_return(&device_indexes) - 1;
39581 + return atomic_inc_return_unchecked(&device_indexes) - 1;
39582 }
39583 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
39584
39585 diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
39586 index 01fae82..1dd8289 100644
39587 --- a/drivers/edac/edac_mc_sysfs.c
39588 +++ b/drivers/edac/edac_mc_sysfs.c
39589 @@ -152,7 +152,7 @@ static const char * const edac_caps[] = {
39590 struct dev_ch_attribute {
39591 struct device_attribute attr;
39592 int channel;
39593 -};
39594 +} __do_const;
39595
39596 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
39597 struct dev_ch_attribute dev_attr_legacy_##_name = \
39598 @@ -1009,14 +1009,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
39599 }
39600
39601 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
39602 + pax_open_kernel();
39603 if (mci->get_sdram_scrub_rate) {
39604 - dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39605 - dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39606 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39607 + *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39608 }
39609 if (mci->set_sdram_scrub_rate) {
39610 - dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39611 - dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39612 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39613 + *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39614 }
39615 + pax_close_kernel();
39616 err = device_create_file(&mci->dev,
39617 &dev_attr_sdram_scrub_rate);
39618 if (err) {
39619 diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
39620 index 2cf44b4d..6dd2dc7 100644
39621 --- a/drivers/edac/edac_pci.c
39622 +++ b/drivers/edac/edac_pci.c
39623 @@ -29,7 +29,7 @@
39624
39625 static DEFINE_MUTEX(edac_pci_ctls_mutex);
39626 static LIST_HEAD(edac_pci_list);
39627 -static atomic_t pci_indexes = ATOMIC_INIT(0);
39628 +static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
39629
39630 /*
39631 * edac_pci_alloc_ctl_info
39632 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
39633 */
39634 int edac_pci_alloc_index(void)
39635 {
39636 - return atomic_inc_return(&pci_indexes) - 1;
39637 + return atomic_inc_return_unchecked(&pci_indexes) - 1;
39638 }
39639 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
39640
39641 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
39642 index e8658e4..22746d6 100644
39643 --- a/drivers/edac/edac_pci_sysfs.c
39644 +++ b/drivers/edac/edac_pci_sysfs.c
39645 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
39646 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
39647 static int edac_pci_poll_msec = 1000; /* one second workq period */
39648
39649 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
39650 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
39651 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
39652 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
39653
39654 static struct kobject *edac_pci_top_main_kobj;
39655 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
39656 @@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
39657 void *value;
39658 ssize_t(*show) (void *, char *);
39659 ssize_t(*store) (void *, const char *, size_t);
39660 -};
39661 +} __do_const;
39662
39663 /* Set of show/store abstract level functions for PCI Parity object */
39664 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
39665 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39666 edac_printk(KERN_CRIT, EDAC_PCI,
39667 "Signaled System Error on %s\n",
39668 pci_name(dev));
39669 - atomic_inc(&pci_nonparity_count);
39670 + atomic_inc_unchecked(&pci_nonparity_count);
39671 }
39672
39673 if (status & (PCI_STATUS_PARITY)) {
39674 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39675 "Master Data Parity Error on %s\n",
39676 pci_name(dev));
39677
39678 - atomic_inc(&pci_parity_count);
39679 + atomic_inc_unchecked(&pci_parity_count);
39680 }
39681
39682 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39683 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39684 "Detected Parity Error on %s\n",
39685 pci_name(dev));
39686
39687 - atomic_inc(&pci_parity_count);
39688 + atomic_inc_unchecked(&pci_parity_count);
39689 }
39690 }
39691
39692 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39693 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
39694 "Signaled System Error on %s\n",
39695 pci_name(dev));
39696 - atomic_inc(&pci_nonparity_count);
39697 + atomic_inc_unchecked(&pci_nonparity_count);
39698 }
39699
39700 if (status & (PCI_STATUS_PARITY)) {
39701 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39702 "Master Data Parity Error on "
39703 "%s\n", pci_name(dev));
39704
39705 - atomic_inc(&pci_parity_count);
39706 + atomic_inc_unchecked(&pci_parity_count);
39707 }
39708
39709 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39710 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39711 "Detected Parity Error on %s\n",
39712 pci_name(dev));
39713
39714 - atomic_inc(&pci_parity_count);
39715 + atomic_inc_unchecked(&pci_parity_count);
39716 }
39717 }
39718 }
39719 @@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
39720 if (!check_pci_errors)
39721 return;
39722
39723 - before_count = atomic_read(&pci_parity_count);
39724 + before_count = atomic_read_unchecked(&pci_parity_count);
39725
39726 /* scan all PCI devices looking for a Parity Error on devices and
39727 * bridges.
39728 @@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
39729 /* Only if operator has selected panic on PCI Error */
39730 if (edac_pci_get_panic_on_pe()) {
39731 /* If the count is different 'after' from 'before' */
39732 - if (before_count != atomic_read(&pci_parity_count))
39733 + if (before_count != atomic_read_unchecked(&pci_parity_count))
39734 panic("EDAC: PCI Parity Error");
39735 }
39736 }
39737 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
39738 index 51b7e3a..aa8a3e8 100644
39739 --- a/drivers/edac/mce_amd.h
39740 +++ b/drivers/edac/mce_amd.h
39741 @@ -77,7 +77,7 @@ struct amd_decoder_ops {
39742 bool (*mc0_mce)(u16, u8);
39743 bool (*mc1_mce)(u16, u8);
39744 bool (*mc2_mce)(u16, u8);
39745 -};
39746 +} __no_const;
39747
39748 void amd_report_gart_errors(bool);
39749 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
39750 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
39751 index 57ea7f4..af06b76 100644
39752 --- a/drivers/firewire/core-card.c
39753 +++ b/drivers/firewire/core-card.c
39754 @@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
39755 const struct fw_card_driver *driver,
39756 struct device *device)
39757 {
39758 - static atomic_t index = ATOMIC_INIT(-1);
39759 + static atomic_unchecked_t index = ATOMIC_INIT(-1);
39760
39761 - card->index = atomic_inc_return(&index);
39762 + card->index = atomic_inc_return_unchecked(&index);
39763 card->driver = driver;
39764 card->device = device;
39765 card->current_tlabel = 0;
39766 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
39767
39768 void fw_core_remove_card(struct fw_card *card)
39769 {
39770 - struct fw_card_driver dummy_driver = dummy_driver_template;
39771 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
39772
39773 card->driver->update_phy_reg(card, 4,
39774 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
39775 diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
39776 index 2c6d5e1..a2cca6b 100644
39777 --- a/drivers/firewire/core-device.c
39778 +++ b/drivers/firewire/core-device.c
39779 @@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
39780 struct config_rom_attribute {
39781 struct device_attribute attr;
39782 u32 key;
39783 -};
39784 +} __do_const;
39785
39786 static ssize_t show_immediate(struct device *dev,
39787 struct device_attribute *dattr, char *buf)
39788 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
39789 index eb6935c..3cc2bfa 100644
39790 --- a/drivers/firewire/core-transaction.c
39791 +++ b/drivers/firewire/core-transaction.c
39792 @@ -38,6 +38,7 @@
39793 #include <linux/timer.h>
39794 #include <linux/types.h>
39795 #include <linux/workqueue.h>
39796 +#include <linux/sched.h>
39797
39798 #include <asm/byteorder.h>
39799
39800 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
39801 index f477308..2795f24 100644
39802 --- a/drivers/firewire/core.h
39803 +++ b/drivers/firewire/core.h
39804 @@ -111,6 +111,7 @@ struct fw_card_driver {
39805
39806 int (*stop_iso)(struct fw_iso_context *ctx);
39807 };
39808 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
39809
39810 void fw_card_initialize(struct fw_card *card,
39811 const struct fw_card_driver *driver, struct device *device);
39812 diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
39813 index 586f2f7..3545ad2 100644
39814 --- a/drivers/firewire/ohci.c
39815 +++ b/drivers/firewire/ohci.c
39816 @@ -2049,10 +2049,12 @@ static void bus_reset_work(struct work_struct *work)
39817 be32_to_cpu(ohci->next_header));
39818 }
39819
39820 +#ifndef CONFIG_GRKERNSEC
39821 if (param_remote_dma) {
39822 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
39823 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
39824 }
39825 +#endif
39826
39827 spin_unlock_irq(&ohci->lock);
39828
39829 @@ -2584,8 +2586,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
39830 unsigned long flags;
39831 int n, ret = 0;
39832
39833 +#ifndef CONFIG_GRKERNSEC
39834 if (param_remote_dma)
39835 return 0;
39836 +#endif
39837
39838 /*
39839 * FIXME: Make sure this bitmask is cleared when we clear the busReset
39840 diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
39841 index 94a58a0..f5eba42 100644
39842 --- a/drivers/firmware/dmi-id.c
39843 +++ b/drivers/firmware/dmi-id.c
39844 @@ -16,7 +16,7 @@
39845 struct dmi_device_attribute{
39846 struct device_attribute dev_attr;
39847 int field;
39848 -};
39849 +} __do_const;
39850 #define to_dmi_dev_attr(_dev_attr) \
39851 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
39852
39853 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
39854 index 17afc51..0ef90cd 100644
39855 --- a/drivers/firmware/dmi_scan.c
39856 +++ b/drivers/firmware/dmi_scan.c
39857 @@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
39858 if (buf == NULL)
39859 return -1;
39860
39861 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
39862 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
39863
39864 dmi_unmap(buf);
39865 return 0;
39866 diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
39867 index 1491dd4..aa910db 100644
39868 --- a/drivers/firmware/efi/cper.c
39869 +++ b/drivers/firmware/efi/cper.c
39870 @@ -41,12 +41,12 @@
39871 */
39872 u64 cper_next_record_id(void)
39873 {
39874 - static atomic64_t seq;
39875 + static atomic64_unchecked_t seq;
39876
39877 - if (!atomic64_read(&seq))
39878 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
39879 + if (!atomic64_read_unchecked(&seq))
39880 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
39881
39882 - return atomic64_inc_return(&seq);
39883 + return atomic64_inc_return_unchecked(&seq);
39884 }
39885 EXPORT_SYMBOL_GPL(cper_next_record_id);
39886
39887 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
39888 index af20f17..4e4e545 100644
39889 --- a/drivers/firmware/efi/efi.c
39890 +++ b/drivers/firmware/efi/efi.c
39891 @@ -120,14 +120,16 @@ static struct attribute_group efi_subsys_attr_group = {
39892 };
39893
39894 static struct efivars generic_efivars;
39895 -static struct efivar_operations generic_ops;
39896 +static efivar_operations_no_const generic_ops __read_only;
39897
39898 static int generic_ops_register(void)
39899 {
39900 - generic_ops.get_variable = efi.get_variable;
39901 - generic_ops.set_variable = efi.set_variable;
39902 - generic_ops.get_next_variable = efi.get_next_variable;
39903 - generic_ops.query_variable_store = efi_query_variable_store;
39904 + pax_open_kernel();
39905 + *(void **)&generic_ops.get_variable = efi.get_variable;
39906 + *(void **)&generic_ops.set_variable = efi.set_variable;
39907 + *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
39908 + *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
39909 + pax_close_kernel();
39910
39911 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
39912 }
39913 diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
39914 index 50ea412..caccd6e9 100644
39915 --- a/drivers/firmware/efi/efivars.c
39916 +++ b/drivers/firmware/efi/efivars.c
39917 @@ -456,7 +456,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
39918 static int
39919 create_efivars_bin_attributes(void)
39920 {
39921 - struct bin_attribute *attr;
39922 + bin_attribute_no_const *attr;
39923 int error;
39924
39925 /* new_var */
39926 diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
39927 index 2f569aa..c95f4fb 100644
39928 --- a/drivers/firmware/google/memconsole.c
39929 +++ b/drivers/firmware/google/memconsole.c
39930 @@ -155,7 +155,10 @@ static int __init memconsole_init(void)
39931 if (!found_memconsole())
39932 return -ENODEV;
39933
39934 - memconsole_bin_attr.size = memconsole_length;
39935 + pax_open_kernel();
39936 + *(size_t *)&memconsole_bin_attr.size = memconsole_length;
39937 + pax_close_kernel();
39938 +
39939 return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
39940 }
39941
39942 diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
39943 index 8765bd6..2e5b147 100644
39944 --- a/drivers/gpio/gpio-em.c
39945 +++ b/drivers/gpio/gpio-em.c
39946 @@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
39947 struct em_gio_priv *p;
39948 struct resource *io[2], *irq[2];
39949 struct gpio_chip *gpio_chip;
39950 - struct irq_chip *irq_chip;
39951 + irq_chip_no_const *irq_chip;
39952 const char *name = dev_name(&pdev->dev);
39953 int ret;
39954
39955 diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
39956 index 7030422..42a3fe9 100644
39957 --- a/drivers/gpio/gpio-ich.c
39958 +++ b/drivers/gpio/gpio-ich.c
39959 @@ -94,7 +94,7 @@ struct ichx_desc {
39960 * this option allows driver caching written output values
39961 */
39962 bool use_outlvl_cache;
39963 -};
39964 +} __do_const;
39965
39966 static struct {
39967 spinlock_t lock;
39968 diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
39969 index 03c9148..c66e753 100644
39970 --- a/drivers/gpio/gpio-rcar.c
39971 +++ b/drivers/gpio/gpio-rcar.c
39972 @@ -355,7 +355,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
39973 struct gpio_rcar_priv *p;
39974 struct resource *io, *irq;
39975 struct gpio_chip *gpio_chip;
39976 - struct irq_chip *irq_chip;
39977 + irq_chip_no_const *irq_chip;
39978 struct device *dev = &pdev->dev;
39979 const char *name = dev_name(dev);
39980 int ret;
39981 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
39982 index 66cbcc1..0c5e622 100644
39983 --- a/drivers/gpio/gpio-vr41xx.c
39984 +++ b/drivers/gpio/gpio-vr41xx.c
39985 @@ -224,7 +224,7 @@ static int giu_get_irq(unsigned int irq)
39986 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
39987 maskl, pendl, maskh, pendh);
39988
39989 - atomic_inc(&irq_err_count);
39990 + atomic_inc_unchecked(&irq_err_count);
39991
39992 return -EINVAL;
39993 }
39994 diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
39995 index f48817d..d35d7f8 100644
39996 --- a/drivers/gpio/gpiolib.c
39997 +++ b/drivers/gpio/gpiolib.c
39998 @@ -1458,8 +1458,10 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip)
39999 }
40000
40001 if (gpiochip->irqchip) {
40002 - gpiochip->irqchip->irq_request_resources = NULL;
40003 - gpiochip->irqchip->irq_release_resources = NULL;
40004 + pax_open_kernel();
40005 + *(void **)&gpiochip->irqchip->irq_request_resources = NULL;
40006 + *(void **)&gpiochip->irqchip->irq_release_resources = NULL;
40007 + pax_close_kernel();
40008 gpiochip->irqchip = NULL;
40009 }
40010 }
40011 @@ -1524,8 +1526,10 @@ int gpiochip_irqchip_add(struct gpio_chip *gpiochip,
40012 gpiochip->irqchip = NULL;
40013 return -EINVAL;
40014 }
40015 - irqchip->irq_request_resources = gpiochip_irq_reqres;
40016 - irqchip->irq_release_resources = gpiochip_irq_relres;
40017 + pax_open_kernel();
40018 + *(void **)&irqchip->irq_request_resources = gpiochip_irq_reqres;
40019 + *(void **)&irqchip->irq_release_resources = gpiochip_irq_relres;
40020 + pax_close_kernel();
40021
40022 /*
40023 * Prepare the mapping since the irqchip shall be orthogonal to
40024 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
40025 index d8b7099..8a314a5 100644
40026 --- a/drivers/gpu/drm/drm_crtc.c
40027 +++ b/drivers/gpu/drm/drm_crtc.c
40028 @@ -3500,7 +3500,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
40029 goto done;
40030 }
40031
40032 - if (copy_to_user(&enum_ptr[copied].name,
40033 + if (copy_to_user(enum_ptr[copied].name,
40034 &prop_enum->name, DRM_PROP_NAME_LEN)) {
40035 ret = -EFAULT;
40036 goto done;
40037 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
40038 old mode 100644
40039 new mode 100755
40040 index 8218078..9960928a
40041 --- a/drivers/gpu/drm/drm_drv.c
40042 +++ b/drivers/gpu/drm/drm_drv.c
40043 @@ -233,7 +233,7 @@ module_exit(drm_core_exit);
40044 /**
40045 * Copy and IOCTL return string to user space
40046 */
40047 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
40048 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
40049 {
40050 int len;
40051
40052 @@ -342,7 +342,7 @@ long drm_ioctl(struct file *filp,
40053 struct drm_file *file_priv = filp->private_data;
40054 struct drm_device *dev;
40055 const struct drm_ioctl_desc *ioctl = NULL;
40056 - drm_ioctl_t *func;
40057 + drm_ioctl_no_const_t func;
40058 unsigned int nr = DRM_IOCTL_NR(cmd);
40059 int retcode = -EINVAL;
40060 char stack_kdata[128];
40061 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
40062 index e1eba0b..98f69f9 100644
40063 --- a/drivers/gpu/drm/drm_fops.c
40064 +++ b/drivers/gpu/drm/drm_fops.c
40065 @@ -89,7 +89,7 @@ int drm_open(struct inode *inode, struct file *filp)
40066 return PTR_ERR(minor);
40067
40068 dev = minor->dev;
40069 - if (!dev->open_count++)
40070 + if (local_inc_return(&dev->open_count) == 1)
40071 need_setup = 1;
40072
40073 /* share address_space across all char-devs of a single device */
40074 @@ -106,7 +106,7 @@ int drm_open(struct inode *inode, struct file *filp)
40075 return 0;
40076
40077 err_undo:
40078 - dev->open_count--;
40079 + local_dec(&dev->open_count);
40080 drm_minor_release(minor);
40081 return retcode;
40082 }
40083 @@ -430,7 +430,7 @@ int drm_release(struct inode *inode, struct file *filp)
40084
40085 mutex_lock(&drm_global_mutex);
40086
40087 - DRM_DEBUG("open_count = %d\n", dev->open_count);
40088 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
40089
40090 if (dev->driver->preclose)
40091 dev->driver->preclose(dev, file_priv);
40092 @@ -439,10 +439,10 @@ int drm_release(struct inode *inode, struct file *filp)
40093 * Begin inline drm_release
40094 */
40095
40096 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
40097 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
40098 task_pid_nr(current),
40099 (long)old_encode_dev(file_priv->minor->kdev->devt),
40100 - dev->open_count);
40101 + local_read(&dev->open_count));
40102
40103 /* Release any auth tokens that might point to this file_priv,
40104 (do that under the drm_global_mutex) */
40105 @@ -543,7 +543,7 @@ int drm_release(struct inode *inode, struct file *filp)
40106 * End inline drm_release
40107 */
40108
40109 - if (!--dev->open_count) {
40110 + if (local_dec_and_test(&dev->open_count)) {
40111 retcode = drm_lastclose(dev);
40112 if (drm_device_is_unplugged(dev))
40113 drm_put_dev(dev);
40114 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
40115 index 3d2e91c..d31c4c9 100644
40116 --- a/drivers/gpu/drm/drm_global.c
40117 +++ b/drivers/gpu/drm/drm_global.c
40118 @@ -36,7 +36,7 @@
40119 struct drm_global_item {
40120 struct mutex mutex;
40121 void *object;
40122 - int refcount;
40123 + atomic_t refcount;
40124 };
40125
40126 static struct drm_global_item glob[DRM_GLOBAL_NUM];
40127 @@ -49,7 +49,7 @@ void drm_global_init(void)
40128 struct drm_global_item *item = &glob[i];
40129 mutex_init(&item->mutex);
40130 item->object = NULL;
40131 - item->refcount = 0;
40132 + atomic_set(&item->refcount, 0);
40133 }
40134 }
40135
40136 @@ -59,7 +59,7 @@ void drm_global_release(void)
40137 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
40138 struct drm_global_item *item = &glob[i];
40139 BUG_ON(item->object != NULL);
40140 - BUG_ON(item->refcount != 0);
40141 + BUG_ON(atomic_read(&item->refcount) != 0);
40142 }
40143 }
40144
40145 @@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40146 struct drm_global_item *item = &glob[ref->global_type];
40147
40148 mutex_lock(&item->mutex);
40149 - if (item->refcount == 0) {
40150 + if (atomic_read(&item->refcount) == 0) {
40151 item->object = kzalloc(ref->size, GFP_KERNEL);
40152 if (unlikely(item->object == NULL)) {
40153 ret = -ENOMEM;
40154 @@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40155 goto out_err;
40156
40157 }
40158 - ++item->refcount;
40159 + atomic_inc(&item->refcount);
40160 ref->object = item->object;
40161 mutex_unlock(&item->mutex);
40162 return 0;
40163 @@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
40164 struct drm_global_item *item = &glob[ref->global_type];
40165
40166 mutex_lock(&item->mutex);
40167 - BUG_ON(item->refcount == 0);
40168 + BUG_ON(atomic_read(&item->refcount) == 0);
40169 BUG_ON(ref->object != item->object);
40170 - if (--item->refcount == 0) {
40171 + if (atomic_dec_and_test(&item->refcount)) {
40172 ref->release(ref);
40173 item->object = NULL;
40174 }
40175 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
40176 index 7473035..a48b9c5 100644
40177 --- a/drivers/gpu/drm/drm_info.c
40178 +++ b/drivers/gpu/drm/drm_info.c
40179 @@ -75,10 +75,13 @@ int drm_vm_info(struct seq_file *m, void *data)
40180 struct drm_local_map *map;
40181 struct drm_map_list *r_list;
40182
40183 - /* Hardcoded from _DRM_FRAME_BUFFER,
40184 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
40185 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
40186 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
40187 + static const char * const types[] = {
40188 + [_DRM_FRAME_BUFFER] = "FB",
40189 + [_DRM_REGISTERS] = "REG",
40190 + [_DRM_SHM] = "SHM",
40191 + [_DRM_AGP] = "AGP",
40192 + [_DRM_SCATTER_GATHER] = "SG",
40193 + [_DRM_CONSISTENT] = "PCI"};
40194 const char *type;
40195 int i;
40196
40197 @@ -89,7 +92,7 @@ int drm_vm_info(struct seq_file *m, void *data)
40198 map = r_list->map;
40199 if (!map)
40200 continue;
40201 - if (map->type < 0 || map->type > 5)
40202 + if (map->type >= ARRAY_SIZE(types))
40203 type = "??";
40204 else
40205 type = types[map->type];
40206 @@ -261,7 +264,11 @@ int drm_vma_info(struct seq_file *m, void *data)
40207 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
40208 vma->vm_flags & VM_LOCKED ? 'l' : '-',
40209 vma->vm_flags & VM_IO ? 'i' : '-',
40210 +#ifdef CONFIG_GRKERNSEC_HIDESYM
40211 + 0);
40212 +#else
40213 vma->vm_pgoff);
40214 +#endif
40215
40216 #if defined(__i386__)
40217 pgprot = pgprot_val(vma->vm_page_prot);
40218 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
40219 index 2f4c4343..dd12cd2 100644
40220 --- a/drivers/gpu/drm/drm_ioc32.c
40221 +++ b/drivers/gpu/drm/drm_ioc32.c
40222 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
40223 request = compat_alloc_user_space(nbytes);
40224 if (!access_ok(VERIFY_WRITE, request, nbytes))
40225 return -EFAULT;
40226 - list = (struct drm_buf_desc *) (request + 1);
40227 + list = (struct drm_buf_desc __user *) (request + 1);
40228
40229 if (__put_user(count, &request->count)
40230 || __put_user(list, &request->list))
40231 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
40232 request = compat_alloc_user_space(nbytes);
40233 if (!access_ok(VERIFY_WRITE, request, nbytes))
40234 return -EFAULT;
40235 - list = (struct drm_buf_pub *) (request + 1);
40236 + list = (struct drm_buf_pub __user *) (request + 1);
40237
40238 if (__put_user(count, &request->count)
40239 || __put_user(list, &request->list))
40240 @@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
40241 return 0;
40242 }
40243
40244 -drm_ioctl_compat_t *drm_compat_ioctls[] = {
40245 +drm_ioctl_compat_t drm_compat_ioctls[] = {
40246 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
40247 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
40248 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
40249 @@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
40250 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40251 {
40252 unsigned int nr = DRM_IOCTL_NR(cmd);
40253 - drm_ioctl_compat_t *fn;
40254 int ret;
40255
40256 /* Assume that ioctls without an explicit compat routine will just
40257 @@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40258 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
40259 return drm_ioctl(filp, cmd, arg);
40260
40261 - fn = drm_compat_ioctls[nr];
40262 -
40263 - if (fn != NULL)
40264 - ret = (*fn) (filp, cmd, arg);
40265 + if (drm_compat_ioctls[nr] != NULL)
40266 + ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
40267 else
40268 ret = drm_ioctl(filp, cmd, arg);
40269
40270 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
40271 index 4c24c3a..c903cab 100644
40272 --- a/drivers/gpu/drm/drm_stub.c
40273 +++ b/drivers/gpu/drm/drm_stub.c
40274 @@ -455,7 +455,7 @@ void drm_unplug_dev(struct drm_device *dev)
40275
40276 drm_device_set_unplugged(dev);
40277
40278 - if (dev->open_count == 0) {
40279 + if (local_read(&dev->open_count) == 0) {
40280 drm_put_dev(dev);
40281 }
40282 mutex_unlock(&drm_global_mutex);
40283 diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
40284 index c22c309..ae758c3 100644
40285 --- a/drivers/gpu/drm/drm_sysfs.c
40286 +++ b/drivers/gpu/drm/drm_sysfs.c
40287 @@ -505,7 +505,7 @@ static void drm_sysfs_release(struct device *dev)
40288 */
40289 int drm_sysfs_device_add(struct drm_minor *minor)
40290 {
40291 - char *minor_str;
40292 + const char *minor_str;
40293 int r;
40294
40295 if (minor->type == DRM_MINOR_CONTROL)
40296 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
40297 index d4d16ed..8fb0b51 100644
40298 --- a/drivers/gpu/drm/i810/i810_drv.h
40299 +++ b/drivers/gpu/drm/i810/i810_drv.h
40300 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
40301 int page_flipping;
40302
40303 wait_queue_head_t irq_queue;
40304 - atomic_t irq_received;
40305 - atomic_t irq_emitted;
40306 + atomic_unchecked_t irq_received;
40307 + atomic_unchecked_t irq_emitted;
40308
40309 int front_offset;
40310 } drm_i810_private_t;
40311 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
40312 index eedb023..25076a4 100644
40313 --- a/drivers/gpu/drm/i915/i915_dma.c
40314 +++ b/drivers/gpu/drm/i915/i915_dma.c
40315 @@ -1280,7 +1280,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
40316 bool can_switch;
40317
40318 spin_lock(&dev->count_lock);
40319 - can_switch = (dev->open_count == 0);
40320 + can_switch = (local_read(&dev->open_count) == 0);
40321 spin_unlock(&dev->count_lock);
40322 return can_switch;
40323 }
40324 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40325 index 20fef6c..76c78fb 100644
40326 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40327 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40328 @@ -886,9 +886,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
40329
40330 static int
40331 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
40332 - int count)
40333 + unsigned int count)
40334 {
40335 - int i;
40336 + unsigned int i;
40337 unsigned relocs_total = 0;
40338 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
40339
40340 diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
40341 index 3c59584..500f2e9 100644
40342 --- a/drivers/gpu/drm/i915/i915_ioc32.c
40343 +++ b/drivers/gpu/drm/i915/i915_ioc32.c
40344 @@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
40345 (unsigned long)request);
40346 }
40347
40348 -static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40349 +static drm_ioctl_compat_t i915_compat_ioctls[] = {
40350 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
40351 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
40352 [DRM_I915_GETPARAM] = compat_i915_getparam,
40353 @@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40354 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40355 {
40356 unsigned int nr = DRM_IOCTL_NR(cmd);
40357 - drm_ioctl_compat_t *fn = NULL;
40358 int ret;
40359
40360 if (nr < DRM_COMMAND_BASE)
40361 return drm_compat_ioctl(filp, cmd, arg);
40362
40363 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
40364 - fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40365 -
40366 - if (fn != NULL)
40367 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
40368 + drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40369 ret = (*fn) (filp, cmd, arg);
40370 - else
40371 + } else
40372 ret = drm_ioctl(filp, cmd, arg);
40373
40374 return ret;
40375 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
40376 index c83eb75..d205e5b2 100644
40377 --- a/drivers/gpu/drm/i915/intel_display.c
40378 +++ b/drivers/gpu/drm/i915/intel_display.c
40379 @@ -11179,13 +11179,13 @@ struct intel_quirk {
40380 int subsystem_vendor;
40381 int subsystem_device;
40382 void (*hook)(struct drm_device *dev);
40383 -};
40384 +} __do_const;
40385
40386 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
40387 struct intel_dmi_quirk {
40388 void (*hook)(struct drm_device *dev);
40389 const struct dmi_system_id (*dmi_id_list)[];
40390 -};
40391 +} __do_const;
40392
40393 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40394 {
40395 @@ -11193,18 +11193,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40396 return 1;
40397 }
40398
40399 -static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40400 +static const struct dmi_system_id intel_dmi_quirks_table[] = {
40401 {
40402 - .dmi_id_list = &(const struct dmi_system_id[]) {
40403 - {
40404 - .callback = intel_dmi_reverse_brightness,
40405 - .ident = "NCR Corporation",
40406 - .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40407 - DMI_MATCH(DMI_PRODUCT_NAME, ""),
40408 - },
40409 - },
40410 - { } /* terminating entry */
40411 + .callback = intel_dmi_reverse_brightness,
40412 + .ident = "NCR Corporation",
40413 + .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40414 + DMI_MATCH(DMI_PRODUCT_NAME, ""),
40415 },
40416 + },
40417 + { } /* terminating entry */
40418 +};
40419 +
40420 +static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40421 + {
40422 + .dmi_id_list = &intel_dmi_quirks_table,
40423 .hook = quirk_invert_brightness,
40424 },
40425 };
40426 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
40427 index fe45321..836fdca 100644
40428 --- a/drivers/gpu/drm/mga/mga_drv.h
40429 +++ b/drivers/gpu/drm/mga/mga_drv.h
40430 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
40431 u32 clear_cmd;
40432 u32 maccess;
40433
40434 - atomic_t vbl_received; /**< Number of vblanks received. */
40435 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
40436 wait_queue_head_t fence_queue;
40437 - atomic_t last_fence_retired;
40438 + atomic_unchecked_t last_fence_retired;
40439 u32 next_fence_to_post;
40440
40441 unsigned int fb_cpp;
40442 diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
40443 index 86b4bb8..ae237ad 100644
40444 --- a/drivers/gpu/drm/mga/mga_ioc32.c
40445 +++ b/drivers/gpu/drm/mga/mga_ioc32.c
40446 @@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
40447 return 0;
40448 }
40449
40450 -drm_ioctl_compat_t *mga_compat_ioctls[] = {
40451 +drm_ioctl_compat_t mga_compat_ioctls[] = {
40452 [DRM_MGA_INIT] = compat_mga_init,
40453 [DRM_MGA_GETPARAM] = compat_mga_getparam,
40454 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
40455 @@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
40456 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40457 {
40458 unsigned int nr = DRM_IOCTL_NR(cmd);
40459 - drm_ioctl_compat_t *fn = NULL;
40460 int ret;
40461
40462 if (nr < DRM_COMMAND_BASE)
40463 return drm_compat_ioctl(filp, cmd, arg);
40464
40465 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
40466 - fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40467 -
40468 - if (fn != NULL)
40469 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
40470 + drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40471 ret = (*fn) (filp, cmd, arg);
40472 - else
40473 + } else
40474 ret = drm_ioctl(filp, cmd, arg);
40475
40476 return ret;
40477 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
40478 index 1b071b8..de8601a 100644
40479 --- a/drivers/gpu/drm/mga/mga_irq.c
40480 +++ b/drivers/gpu/drm/mga/mga_irq.c
40481 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
40482 if (crtc != 0)
40483 return 0;
40484
40485 - return atomic_read(&dev_priv->vbl_received);
40486 + return atomic_read_unchecked(&dev_priv->vbl_received);
40487 }
40488
40489
40490 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40491 /* VBLANK interrupt */
40492 if (status & MGA_VLINEPEN) {
40493 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
40494 - atomic_inc(&dev_priv->vbl_received);
40495 + atomic_inc_unchecked(&dev_priv->vbl_received);
40496 drm_handle_vblank(dev, 0);
40497 handled = 1;
40498 }
40499 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40500 if ((prim_start & ~0x03) != (prim_end & ~0x03))
40501 MGA_WRITE(MGA_PRIMEND, prim_end);
40502
40503 - atomic_inc(&dev_priv->last_fence_retired);
40504 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
40505 wake_up(&dev_priv->fence_queue);
40506 handled = 1;
40507 }
40508 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
40509 * using fences.
40510 */
40511 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
40512 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
40513 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
40514 - *sequence) <= (1 << 23)));
40515
40516 *sequence = cur_fence;
40517 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
40518 index 8268a4c..5105708 100644
40519 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
40520 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
40521 @@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
40522 struct bit_table {
40523 const char id;
40524 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
40525 -};
40526 +} __no_const;
40527
40528 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
40529
40530 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
40531 index 7efbafa..19f8087 100644
40532 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
40533 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
40534 @@ -97,7 +97,6 @@ struct nouveau_drm {
40535 struct drm_global_reference mem_global_ref;
40536 struct ttm_bo_global_ref bo_global_ref;
40537 struct ttm_bo_device bdev;
40538 - atomic_t validate_sequence;
40539 int (*move)(struct nouveau_channel *,
40540 struct ttm_buffer_object *,
40541 struct ttm_mem_reg *, struct ttm_mem_reg *);
40542 diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40543 index c1a7e5a..38b8539 100644
40544 --- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40545 +++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40546 @@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
40547 unsigned long arg)
40548 {
40549 unsigned int nr = DRM_IOCTL_NR(cmd);
40550 - drm_ioctl_compat_t *fn = NULL;
40551 + drm_ioctl_compat_t fn = NULL;
40552 int ret;
40553
40554 if (nr < DRM_COMMAND_BASE)
40555 diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40556 index ab0228f..20b756b 100644
40557 --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
40558 +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40559 @@ -130,11 +130,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40560 }
40561
40562 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
40563 - nouveau_vram_manager_init,
40564 - nouveau_vram_manager_fini,
40565 - nouveau_vram_manager_new,
40566 - nouveau_vram_manager_del,
40567 - nouveau_vram_manager_debug
40568 + .init = nouveau_vram_manager_init,
40569 + .takedown = nouveau_vram_manager_fini,
40570 + .get_node = nouveau_vram_manager_new,
40571 + .put_node = nouveau_vram_manager_del,
40572 + .debug = nouveau_vram_manager_debug
40573 };
40574
40575 static int
40576 @@ -199,11 +199,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40577 }
40578
40579 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
40580 - nouveau_gart_manager_init,
40581 - nouveau_gart_manager_fini,
40582 - nouveau_gart_manager_new,
40583 - nouveau_gart_manager_del,
40584 - nouveau_gart_manager_debug
40585 + .init = nouveau_gart_manager_init,
40586 + .takedown = nouveau_gart_manager_fini,
40587 + .get_node = nouveau_gart_manager_new,
40588 + .put_node = nouveau_gart_manager_del,
40589 + .debug = nouveau_gart_manager_debug
40590 };
40591
40592 #include <core/subdev/vm/nv04.h>
40593 @@ -271,11 +271,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40594 }
40595
40596 const struct ttm_mem_type_manager_func nv04_gart_manager = {
40597 - nv04_gart_manager_init,
40598 - nv04_gart_manager_fini,
40599 - nv04_gart_manager_new,
40600 - nv04_gart_manager_del,
40601 - nv04_gart_manager_debug
40602 + .init = nv04_gart_manager_init,
40603 + .takedown = nv04_gart_manager_fini,
40604 + .get_node = nv04_gart_manager_new,
40605 + .put_node = nv04_gart_manager_del,
40606 + .debug = nv04_gart_manager_debug
40607 };
40608
40609 int
40610 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
40611 index fb84da3..d7ee463 100644
40612 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
40613 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
40614 @@ -67,7 +67,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
40615 bool can_switch;
40616
40617 spin_lock(&dev->count_lock);
40618 - can_switch = (dev->open_count == 0);
40619 + can_switch = (local_read(&dev->open_count) == 0);
40620 spin_unlock(&dev->count_lock);
40621 return can_switch;
40622 }
40623 diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
40624 index eb89653..613cf71 100644
40625 --- a/drivers/gpu/drm/qxl/qxl_cmd.c
40626 +++ b/drivers/gpu/drm/qxl/qxl_cmd.c
40627 @@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
40628 int ret;
40629
40630 mutex_lock(&qdev->async_io_mutex);
40631 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
40632 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40633 if (qdev->last_sent_io_cmd > irq_num) {
40634 if (intr)
40635 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40636 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40637 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40638 else
40639 ret = wait_event_timeout(qdev->io_cmd_event,
40640 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40641 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40642 /* 0 is timeout, just bail the "hw" has gone away */
40643 if (ret <= 0)
40644 goto out;
40645 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
40646 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40647 }
40648 outb(val, addr);
40649 qdev->last_sent_io_cmd = irq_num + 1;
40650 if (intr)
40651 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40652 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40653 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40654 else
40655 ret = wait_event_timeout(qdev->io_cmd_event,
40656 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40657 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40658 out:
40659 if (ret > 0)
40660 ret = 0;
40661 diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
40662 index c3c2bbd..bc3c0fb 100644
40663 --- a/drivers/gpu/drm/qxl/qxl_debugfs.c
40664 +++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
40665 @@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
40666 struct drm_info_node *node = (struct drm_info_node *) m->private;
40667 struct qxl_device *qdev = node->minor->dev->dev_private;
40668
40669 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
40670 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
40671 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
40672 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
40673 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
40674 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
40675 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
40676 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
40677 seq_printf(m, "%d\n", qdev->irq_received_error);
40678 return 0;
40679 }
40680 diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
40681 index 36ed40b..0397633 100644
40682 --- a/drivers/gpu/drm/qxl/qxl_drv.h
40683 +++ b/drivers/gpu/drm/qxl/qxl_drv.h
40684 @@ -290,10 +290,10 @@ struct qxl_device {
40685 unsigned int last_sent_io_cmd;
40686
40687 /* interrupt handling */
40688 - atomic_t irq_received;
40689 - atomic_t irq_received_display;
40690 - atomic_t irq_received_cursor;
40691 - atomic_t irq_received_io_cmd;
40692 + atomic_unchecked_t irq_received;
40693 + atomic_unchecked_t irq_received_display;
40694 + atomic_unchecked_t irq_received_cursor;
40695 + atomic_unchecked_t irq_received_io_cmd;
40696 unsigned irq_received_error;
40697 wait_queue_head_t display_event;
40698 wait_queue_head_t cursor_event;
40699 diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
40700 index 0bb86e6..d41416d 100644
40701 --- a/drivers/gpu/drm/qxl/qxl_ioctl.c
40702 +++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
40703 @@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40704
40705 /* TODO copy slow path code from i915 */
40706 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
40707 - 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);
40708 + 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);
40709
40710 {
40711 struct qxl_drawable *draw = fb_cmd;
40712 @@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40713 struct drm_qxl_reloc reloc;
40714
40715 if (copy_from_user(&reloc,
40716 - &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
40717 + &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
40718 sizeof(reloc))) {
40719 ret = -EFAULT;
40720 goto out_free_bos;
40721 @@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
40722
40723 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
40724
40725 - struct drm_qxl_command *commands =
40726 - (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
40727 + struct drm_qxl_command __user *commands =
40728 + (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
40729
40730 - if (copy_from_user(&user_cmd, &commands[cmd_num],
40731 + if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
40732 sizeof(user_cmd)))
40733 return -EFAULT;
40734
40735 diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
40736 index 3485bdc..20d26e3 100644
40737 --- a/drivers/gpu/drm/qxl/qxl_irq.c
40738 +++ b/drivers/gpu/drm/qxl/qxl_irq.c
40739 @@ -36,19 +36,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
40740 if (!pending)
40741 return IRQ_NONE;
40742
40743 - atomic_inc(&qdev->irq_received);
40744 + atomic_inc_unchecked(&qdev->irq_received);
40745
40746 if (pending & QXL_INTERRUPT_DISPLAY) {
40747 - atomic_inc(&qdev->irq_received_display);
40748 + atomic_inc_unchecked(&qdev->irq_received_display);
40749 wake_up_all(&qdev->display_event);
40750 qxl_queue_garbage_collect(qdev, false);
40751 }
40752 if (pending & QXL_INTERRUPT_CURSOR) {
40753 - atomic_inc(&qdev->irq_received_cursor);
40754 + atomic_inc_unchecked(&qdev->irq_received_cursor);
40755 wake_up_all(&qdev->cursor_event);
40756 }
40757 if (pending & QXL_INTERRUPT_IO_CMD) {
40758 - atomic_inc(&qdev->irq_received_io_cmd);
40759 + atomic_inc_unchecked(&qdev->irq_received_io_cmd);
40760 wake_up_all(&qdev->io_cmd_event);
40761 }
40762 if (pending & QXL_INTERRUPT_ERROR) {
40763 @@ -85,10 +85,10 @@ int qxl_irq_init(struct qxl_device *qdev)
40764 init_waitqueue_head(&qdev->io_cmd_event);
40765 INIT_WORK(&qdev->client_monitors_config_work,
40766 qxl_client_monitors_config_work_func);
40767 - atomic_set(&qdev->irq_received, 0);
40768 - atomic_set(&qdev->irq_received_display, 0);
40769 - atomic_set(&qdev->irq_received_cursor, 0);
40770 - atomic_set(&qdev->irq_received_io_cmd, 0);
40771 + atomic_set_unchecked(&qdev->irq_received, 0);
40772 + atomic_set_unchecked(&qdev->irq_received_display, 0);
40773 + atomic_set_unchecked(&qdev->irq_received_cursor, 0);
40774 + atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
40775 qdev->irq_received_error = 0;
40776 ret = drm_irq_install(qdev->ddev);
40777 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
40778 diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
40779 index d52c275..4e6b43d 100644
40780 --- a/drivers/gpu/drm/qxl/qxl_ttm.c
40781 +++ b/drivers/gpu/drm/qxl/qxl_ttm.c
40782 @@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
40783 }
40784 }
40785
40786 -static struct vm_operations_struct qxl_ttm_vm_ops;
40787 +static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
40788 static const struct vm_operations_struct *ttm_vm_ops;
40789
40790 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40791 @@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
40792 return r;
40793 if (unlikely(ttm_vm_ops == NULL)) {
40794 ttm_vm_ops = vma->vm_ops;
40795 + pax_open_kernel();
40796 qxl_ttm_vm_ops = *ttm_vm_ops;
40797 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
40798 + pax_close_kernel();
40799 }
40800 vma->vm_ops = &qxl_ttm_vm_ops;
40801 return 0;
40802 @@ -561,25 +563,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
40803 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
40804 {
40805 #if defined(CONFIG_DEBUG_FS)
40806 - static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
40807 - static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
40808 - unsigned i;
40809 + static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
40810 + {
40811 + .name = "qxl_mem_mm",
40812 + .show = &qxl_mm_dump_table,
40813 + },
40814 + {
40815 + .name = "qxl_surf_mm",
40816 + .show = &qxl_mm_dump_table,
40817 + }
40818 + };
40819
40820 - for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
40821 - if (i == 0)
40822 - sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
40823 - else
40824 - sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
40825 - qxl_mem_types_list[i].name = qxl_mem_types_names[i];
40826 - qxl_mem_types_list[i].show = &qxl_mm_dump_table;
40827 - qxl_mem_types_list[i].driver_features = 0;
40828 - if (i == 0)
40829 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40830 - else
40831 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40832 + pax_open_kernel();
40833 + *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40834 + *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40835 + pax_close_kernel();
40836
40837 - }
40838 - return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
40839 + return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
40840 #else
40841 return 0;
40842 #endif
40843 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
40844 index 59459fe..be26b31 100644
40845 --- a/drivers/gpu/drm/r128/r128_cce.c
40846 +++ b/drivers/gpu/drm/r128/r128_cce.c
40847 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
40848
40849 /* GH: Simple idle check.
40850 */
40851 - atomic_set(&dev_priv->idle_count, 0);
40852 + atomic_set_unchecked(&dev_priv->idle_count, 0);
40853
40854 /* We don't support anything other than bus-mastering ring mode,
40855 * but the ring can be in either AGP or PCI space for the ring
40856 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
40857 index 5bf3f5f..7000661 100644
40858 --- a/drivers/gpu/drm/r128/r128_drv.h
40859 +++ b/drivers/gpu/drm/r128/r128_drv.h
40860 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
40861 int is_pci;
40862 unsigned long cce_buffers_offset;
40863
40864 - atomic_t idle_count;
40865 + atomic_unchecked_t idle_count;
40866
40867 int page_flipping;
40868 int current_page;
40869 u32 crtc_offset;
40870 u32 crtc_offset_cntl;
40871
40872 - atomic_t vbl_received;
40873 + atomic_unchecked_t vbl_received;
40874
40875 u32 color_fmt;
40876 unsigned int front_offset;
40877 diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
40878 index b0d0fd3..a6fbbe4 100644
40879 --- a/drivers/gpu/drm/r128/r128_ioc32.c
40880 +++ b/drivers/gpu/drm/r128/r128_ioc32.c
40881 @@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
40882 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
40883 }
40884
40885 -drm_ioctl_compat_t *r128_compat_ioctls[] = {
40886 +drm_ioctl_compat_t r128_compat_ioctls[] = {
40887 [DRM_R128_INIT] = compat_r128_init,
40888 [DRM_R128_DEPTH] = compat_r128_depth,
40889 [DRM_R128_STIPPLE] = compat_r128_stipple,
40890 @@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
40891 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40892 {
40893 unsigned int nr = DRM_IOCTL_NR(cmd);
40894 - drm_ioctl_compat_t *fn = NULL;
40895 int ret;
40896
40897 if (nr < DRM_COMMAND_BASE)
40898 return drm_compat_ioctl(filp, cmd, arg);
40899
40900 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
40901 - fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40902 -
40903 - if (fn != NULL)
40904 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
40905 + drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40906 ret = (*fn) (filp, cmd, arg);
40907 - else
40908 + } else
40909 ret = drm_ioctl(filp, cmd, arg);
40910
40911 return ret;
40912 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
40913 index c2ae496..30b5993 100644
40914 --- a/drivers/gpu/drm/r128/r128_irq.c
40915 +++ b/drivers/gpu/drm/r128/r128_irq.c
40916 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
40917 if (crtc != 0)
40918 return 0;
40919
40920 - return atomic_read(&dev_priv->vbl_received);
40921 + return atomic_read_unchecked(&dev_priv->vbl_received);
40922 }
40923
40924 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
40925 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
40926 /* VBLANK interrupt */
40927 if (status & R128_CRTC_VBLANK_INT) {
40928 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
40929 - atomic_inc(&dev_priv->vbl_received);
40930 + atomic_inc_unchecked(&dev_priv->vbl_received);
40931 drm_handle_vblank(dev, 0);
40932 return IRQ_HANDLED;
40933 }
40934 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
40935 index e806dac..f81d32f 100644
40936 --- a/drivers/gpu/drm/r128/r128_state.c
40937 +++ b/drivers/gpu/drm/r128/r128_state.c
40938 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
40939
40940 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
40941 {
40942 - if (atomic_read(&dev_priv->idle_count) == 0)
40943 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
40944 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
40945 else
40946 - atomic_set(&dev_priv->idle_count, 0);
40947 + atomic_set_unchecked(&dev_priv->idle_count, 0);
40948 }
40949
40950 #endif
40951 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
40952 index 4a85bb6..aaea819 100644
40953 --- a/drivers/gpu/drm/radeon/mkregtable.c
40954 +++ b/drivers/gpu/drm/radeon/mkregtable.c
40955 @@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
40956 regex_t mask_rex;
40957 regmatch_t match[4];
40958 char buf[1024];
40959 - size_t end;
40960 + long end;
40961 int len;
40962 int done = 0;
40963 int r;
40964 unsigned o;
40965 struct offset *offset;
40966 char last_reg_s[10];
40967 - int last_reg;
40968 + unsigned long last_reg;
40969
40970 if (regcomp
40971 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
40972 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
40973 index 2cd144c..a01c95a 100644
40974 --- a/drivers/gpu/drm/radeon/radeon_device.c
40975 +++ b/drivers/gpu/drm/radeon/radeon_device.c
40976 @@ -1129,7 +1129,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
40977 bool can_switch;
40978
40979 spin_lock(&dev->count_lock);
40980 - can_switch = (dev->open_count == 0);
40981 + can_switch = (local_read(&dev->open_count) == 0);
40982 spin_unlock(&dev->count_lock);
40983 return can_switch;
40984 }
40985 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
40986 index dafd812..1bf20c7 100644
40987 --- a/drivers/gpu/drm/radeon/radeon_drv.h
40988 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
40989 @@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
40990
40991 /* SW interrupt */
40992 wait_queue_head_t swi_queue;
40993 - atomic_t swi_emitted;
40994 + atomic_unchecked_t swi_emitted;
40995 int vblank_crtc;
40996 uint32_t irq_enable_reg;
40997 uint32_t r500_disp_irq_reg;
40998 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
40999 index bdb0f93..5ff558f 100644
41000 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
41001 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
41002 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
41003 request = compat_alloc_user_space(sizeof(*request));
41004 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
41005 || __put_user(req32.param, &request->param)
41006 - || __put_user((void __user *)(unsigned long)req32.value,
41007 + || __put_user((unsigned long)req32.value,
41008 &request->value))
41009 return -EFAULT;
41010
41011 @@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
41012 #define compat_radeon_cp_setparam NULL
41013 #endif /* X86_64 || IA64 */
41014
41015 -static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41016 +static drm_ioctl_compat_t radeon_compat_ioctls[] = {
41017 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
41018 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
41019 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
41020 @@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41021 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41022 {
41023 unsigned int nr = DRM_IOCTL_NR(cmd);
41024 - drm_ioctl_compat_t *fn = NULL;
41025 int ret;
41026
41027 if (nr < DRM_COMMAND_BASE)
41028 return drm_compat_ioctl(filp, cmd, arg);
41029
41030 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
41031 - fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41032 -
41033 - if (fn != NULL)
41034 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
41035 + drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41036 ret = (*fn) (filp, cmd, arg);
41037 - else
41038 + } else
41039 ret = drm_ioctl(filp, cmd, arg);
41040
41041 return ret;
41042 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
41043 index 244b19b..c19226d 100644
41044 --- a/drivers/gpu/drm/radeon/radeon_irq.c
41045 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
41046 @@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
41047 unsigned int ret;
41048 RING_LOCALS;
41049
41050 - atomic_inc(&dev_priv->swi_emitted);
41051 - ret = atomic_read(&dev_priv->swi_emitted);
41052 + atomic_inc_unchecked(&dev_priv->swi_emitted);
41053 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
41054
41055 BEGIN_RING(4);
41056 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
41057 @@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
41058 drm_radeon_private_t *dev_priv =
41059 (drm_radeon_private_t *) dev->dev_private;
41060
41061 - atomic_set(&dev_priv->swi_emitted, 0);
41062 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
41063 init_waitqueue_head(&dev_priv->swi_queue);
41064
41065 dev->max_vblank_count = 0x001fffff;
41066 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
41067 index 956ab7f..fbd36d8 100644
41068 --- a/drivers/gpu/drm/radeon/radeon_state.c
41069 +++ b/drivers/gpu/drm/radeon/radeon_state.c
41070 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
41071 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
41072 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
41073
41074 - if (copy_from_user(&depth_boxes, clear->depth_boxes,
41075 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
41076 sarea_priv->nbox * sizeof(depth_boxes[0])))
41077 return -EFAULT;
41078
41079 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
41080 {
41081 drm_radeon_private_t *dev_priv = dev->dev_private;
41082 drm_radeon_getparam_t *param = data;
41083 - int value;
41084 + int value = 0;
41085
41086 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
41087
41088 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
41089 index c8a8a51..219dacc 100644
41090 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
41091 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
41092 @@ -797,7 +797,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
41093 man->size = size >> PAGE_SHIFT;
41094 }
41095
41096 -static struct vm_operations_struct radeon_ttm_vm_ops;
41097 +static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
41098 static const struct vm_operations_struct *ttm_vm_ops = NULL;
41099
41100 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41101 @@ -838,8 +838,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
41102 }
41103 if (unlikely(ttm_vm_ops == NULL)) {
41104 ttm_vm_ops = vma->vm_ops;
41105 + pax_open_kernel();
41106 radeon_ttm_vm_ops = *ttm_vm_ops;
41107 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
41108 + pax_close_kernel();
41109 }
41110 vma->vm_ops = &radeon_ttm_vm_ops;
41111 return 0;
41112 diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
41113 index edb871d..a275c6ed 100644
41114 --- a/drivers/gpu/drm/tegra/dc.c
41115 +++ b/drivers/gpu/drm/tegra/dc.c
41116 @@ -1057,7 +1057,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
41117 }
41118
41119 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
41120 - dc->debugfs_files[i].data = dc;
41121 + *(void **)&dc->debugfs_files[i].data = dc;
41122
41123 err = drm_debugfs_create_files(dc->debugfs_files,
41124 ARRAY_SIZE(debugfs_files),
41125 diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
41126 index 0e599f0..c9ea7c7 100644
41127 --- a/drivers/gpu/drm/tegra/dsi.c
41128 +++ b/drivers/gpu/drm/tegra/dsi.c
41129 @@ -39,7 +39,7 @@ struct tegra_dsi {
41130 struct clk *clk_lp;
41131 struct clk *clk;
41132
41133 - struct drm_info_list *debugfs_files;
41134 + drm_info_list_no_const *debugfs_files;
41135 struct drm_minor *minor;
41136 struct dentry *debugfs;
41137
41138 diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
41139 index 6928015..c9853e7 100644
41140 --- a/drivers/gpu/drm/tegra/hdmi.c
41141 +++ b/drivers/gpu/drm/tegra/hdmi.c
41142 @@ -59,7 +59,7 @@ struct tegra_hdmi {
41143 bool stereo;
41144 bool dvi;
41145
41146 - struct drm_info_list *debugfs_files;
41147 + drm_info_list_no_const *debugfs_files;
41148 struct drm_minor *minor;
41149 struct dentry *debugfs;
41150 };
41151 diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41152 index bd850c9..d9f3573 100644
41153 --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
41154 +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41155 @@ -146,10 +146,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
41156 }
41157
41158 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
41159 - ttm_bo_man_init,
41160 - ttm_bo_man_takedown,
41161 - ttm_bo_man_get_node,
41162 - ttm_bo_man_put_node,
41163 - ttm_bo_man_debug
41164 + .init = ttm_bo_man_init,
41165 + .takedown = ttm_bo_man_takedown,
41166 + .get_node = ttm_bo_man_get_node,
41167 + .put_node = ttm_bo_man_put_node,
41168 + .debug = ttm_bo_man_debug
41169 };
41170 EXPORT_SYMBOL(ttm_bo_manager_func);
41171 diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
41172 index dbc2def..0a9f710 100644
41173 --- a/drivers/gpu/drm/ttm/ttm_memory.c
41174 +++ b/drivers/gpu/drm/ttm/ttm_memory.c
41175 @@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
41176 zone->glob = glob;
41177 glob->zone_kernel = zone;
41178 ret = kobject_init_and_add(
41179 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41180 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41181 if (unlikely(ret != 0)) {
41182 kobject_put(&zone->kobj);
41183 return ret;
41184 @@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
41185 zone->glob = glob;
41186 glob->zone_dma32 = zone;
41187 ret = kobject_init_and_add(
41188 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41189 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41190 if (unlikely(ret != 0)) {
41191 kobject_put(&zone->kobj);
41192 return ret;
41193 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41194 index 863bef9..cba15cf 100644
41195 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
41196 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41197 @@ -391,9 +391,9 @@ out:
41198 static unsigned long
41199 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41200 {
41201 - static atomic_t start_pool = ATOMIC_INIT(0);
41202 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
41203 unsigned i;
41204 - unsigned pool_offset = atomic_add_return(1, &start_pool);
41205 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
41206 struct ttm_page_pool *pool;
41207 int shrink_pages = sc->nr_to_scan;
41208 unsigned long freed = 0;
41209 diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
41210 index 3771763..883f206 100644
41211 --- a/drivers/gpu/drm/udl/udl_fb.c
41212 +++ b/drivers/gpu/drm/udl/udl_fb.c
41213 @@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
41214 fb_deferred_io_cleanup(info);
41215 kfree(info->fbdefio);
41216 info->fbdefio = NULL;
41217 - info->fbops->fb_mmap = udl_fb_mmap;
41218 }
41219
41220 pr_warn("released /dev/fb%d user=%d count=%d\n",
41221 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
41222 index ad02732..144f5ed 100644
41223 --- a/drivers/gpu/drm/via/via_drv.h
41224 +++ b/drivers/gpu/drm/via/via_drv.h
41225 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
41226 typedef uint32_t maskarray_t[5];
41227
41228 typedef struct drm_via_irq {
41229 - atomic_t irq_received;
41230 + atomic_unchecked_t irq_received;
41231 uint32_t pending_mask;
41232 uint32_t enable_mask;
41233 wait_queue_head_t irq_queue;
41234 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
41235 struct timeval last_vblank;
41236 int last_vblank_valid;
41237 unsigned usec_per_vblank;
41238 - atomic_t vbl_received;
41239 + atomic_unchecked_t vbl_received;
41240 drm_via_state_t hc_state;
41241 char pci_buf[VIA_PCI_BUF_SIZE];
41242 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
41243 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
41244 index 1319433..a993b0c 100644
41245 --- a/drivers/gpu/drm/via/via_irq.c
41246 +++ b/drivers/gpu/drm/via/via_irq.c
41247 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
41248 if (crtc != 0)
41249 return 0;
41250
41251 - return atomic_read(&dev_priv->vbl_received);
41252 + return atomic_read_unchecked(&dev_priv->vbl_received);
41253 }
41254
41255 irqreturn_t via_driver_irq_handler(int irq, void *arg)
41256 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41257
41258 status = VIA_READ(VIA_REG_INTERRUPT);
41259 if (status & VIA_IRQ_VBLANK_PENDING) {
41260 - atomic_inc(&dev_priv->vbl_received);
41261 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
41262 + atomic_inc_unchecked(&dev_priv->vbl_received);
41263 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
41264 do_gettimeofday(&cur_vblank);
41265 if (dev_priv->last_vblank_valid) {
41266 dev_priv->usec_per_vblank =
41267 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41268 dev_priv->last_vblank = cur_vblank;
41269 dev_priv->last_vblank_valid = 1;
41270 }
41271 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
41272 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
41273 DRM_DEBUG("US per vblank is: %u\n",
41274 dev_priv->usec_per_vblank);
41275 }
41276 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41277
41278 for (i = 0; i < dev_priv->num_irqs; ++i) {
41279 if (status & cur_irq->pending_mask) {
41280 - atomic_inc(&cur_irq->irq_received);
41281 + atomic_inc_unchecked(&cur_irq->irq_received);
41282 wake_up(&cur_irq->irq_queue);
41283 handled = 1;
41284 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
41285 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
41286 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41287 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
41288 masks[irq][4]));
41289 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
41290 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
41291 } else {
41292 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41293 (((cur_irq_sequence =
41294 - atomic_read(&cur_irq->irq_received)) -
41295 + atomic_read_unchecked(&cur_irq->irq_received)) -
41296 *sequence) <= (1 << 23)));
41297 }
41298 *sequence = cur_irq_sequence;
41299 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
41300 }
41301
41302 for (i = 0; i < dev_priv->num_irqs; ++i) {
41303 - atomic_set(&cur_irq->irq_received, 0);
41304 + atomic_set_unchecked(&cur_irq->irq_received, 0);
41305 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
41306 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
41307 init_waitqueue_head(&cur_irq->irq_queue);
41308 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
41309 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
41310 case VIA_IRQ_RELATIVE:
41311 irqwait->request.sequence +=
41312 - atomic_read(&cur_irq->irq_received);
41313 + atomic_read_unchecked(&cur_irq->irq_received);
41314 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
41315 case VIA_IRQ_ABSOLUTE:
41316 break;
41317 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41318 index 6b252a8..5975dfe 100644
41319 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41320 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41321 @@ -437,7 +437,7 @@ struct vmw_private {
41322 * Fencing and IRQs.
41323 */
41324
41325 - atomic_t marker_seq;
41326 + atomic_unchecked_t marker_seq;
41327 wait_queue_head_t fence_queue;
41328 wait_queue_head_t fifo_queue;
41329 int fence_queue_waiters; /* Protected by hw_mutex */
41330 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41331 index 6ccd993..618d592 100644
41332 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41333 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41334 @@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
41335 (unsigned int) min,
41336 (unsigned int) fifo->capabilities);
41337
41338 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41339 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41340 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
41341 vmw_marker_queue_init(&fifo->marker_queue);
41342 return vmw_fifo_send_fence(dev_priv, &dummy);
41343 @@ -372,7 +372,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
41344 if (reserveable)
41345 iowrite32(bytes, fifo_mem +
41346 SVGA_FIFO_RESERVED);
41347 - return fifo_mem + (next_cmd >> 2);
41348 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
41349 } else {
41350 need_bounce = true;
41351 }
41352 @@ -492,7 +492,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41353
41354 fm = vmw_fifo_reserve(dev_priv, bytes);
41355 if (unlikely(fm == NULL)) {
41356 - *seqno = atomic_read(&dev_priv->marker_seq);
41357 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41358 ret = -ENOMEM;
41359 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
41360 false, 3*HZ);
41361 @@ -500,7 +500,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41362 }
41363
41364 do {
41365 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
41366 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
41367 } while (*seqno == 0);
41368
41369 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
41370 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41371 index b1273e8..9c274fd 100644
41372 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41373 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41374 @@ -164,9 +164,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
41375 }
41376
41377 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
41378 - vmw_gmrid_man_init,
41379 - vmw_gmrid_man_takedown,
41380 - vmw_gmrid_man_get_node,
41381 - vmw_gmrid_man_put_node,
41382 - vmw_gmrid_man_debug
41383 + .init = vmw_gmrid_man_init,
41384 + .takedown = vmw_gmrid_man_takedown,
41385 + .get_node = vmw_gmrid_man_get_node,
41386 + .put_node = vmw_gmrid_man_put_node,
41387 + .debug = vmw_gmrid_man_debug
41388 };
41389 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41390 index 37881ec..319065d 100644
41391 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41392 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41393 @@ -235,7 +235,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
41394 int ret;
41395
41396 num_clips = arg->num_clips;
41397 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41398 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41399
41400 if (unlikely(num_clips == 0))
41401 return 0;
41402 @@ -318,7 +318,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
41403 int ret;
41404
41405 num_clips = arg->num_clips;
41406 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41407 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41408
41409 if (unlikely(num_clips == 0))
41410 return 0;
41411 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41412 index 0c42376..6febe77 100644
41413 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41414 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41415 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
41416 * emitted. Then the fence is stale and signaled.
41417 */
41418
41419 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
41420 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
41421 > VMW_FENCE_WRAP);
41422
41423 return ret;
41424 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
41425
41426 if (fifo_idle)
41427 down_read(&fifo_state->rwsem);
41428 - signal_seq = atomic_read(&dev_priv->marker_seq);
41429 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
41430 ret = 0;
41431
41432 for (;;) {
41433 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41434 index 8a8725c2..afed796 100644
41435 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41436 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41437 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
41438 while (!vmw_lag_lt(queue, us)) {
41439 spin_lock(&queue->lock);
41440 if (list_empty(&queue->head))
41441 - seqno = atomic_read(&dev_priv->marker_seq);
41442 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41443 else {
41444 marker = list_first_entry(&queue->head,
41445 struct vmw_marker, head);
41446 diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
41447 index 6866448..2ad2b34 100644
41448 --- a/drivers/gpu/vga/vga_switcheroo.c
41449 +++ b/drivers/gpu/vga/vga_switcheroo.c
41450 @@ -644,7 +644,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
41451
41452 /* this version is for the case where the power switch is separate
41453 to the device being powered down. */
41454 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
41455 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
41456 {
41457 /* copy over all the bus versions */
41458 if (dev->bus && dev->bus->pm) {
41459 @@ -689,7 +689,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
41460 return ret;
41461 }
41462
41463 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
41464 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
41465 {
41466 /* copy over all the bus versions */
41467 if (dev->bus && dev->bus->pm) {
41468 diff --git a/drivers/hid/hid-cherry.c b/drivers/hid/hid-cherry.c
41469 index 1bdcccc..f745d2c 100644
41470 --- a/drivers/hid/hid-cherry.c
41471 +++ b/drivers/hid/hid-cherry.c
41472 @@ -28,7 +28,7 @@
41473 static __u8 *ch_report_fixup(struct hid_device *hdev, __u8 *rdesc,
41474 unsigned int *rsize)
41475 {
41476 - if (*rsize >= 17 && rdesc[11] == 0x3c && rdesc[12] == 0x02) {
41477 + if (*rsize >= 18 && rdesc[11] == 0x3c && rdesc[12] == 0x02) {
41478 hid_info(hdev, "fixing up Cherry Cymotion report descriptor\n");
41479 rdesc[11] = rdesc[16] = 0xff;
41480 rdesc[12] = rdesc[17] = 0x03;
41481 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
41482 index a5c7927..025a2b4 100644
41483 --- a/drivers/hid/hid-core.c
41484 +++ b/drivers/hid/hid-core.c
41485 @@ -2476,7 +2476,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
41486
41487 int hid_add_device(struct hid_device *hdev)
41488 {
41489 - static atomic_t id = ATOMIC_INIT(0);
41490 + static atomic_unchecked_t id = ATOMIC_INIT(0);
41491 int ret;
41492
41493 if (WARN_ON(hdev->status & HID_STAT_ADDED))
41494 @@ -2518,7 +2518,7 @@ int hid_add_device(struct hid_device *hdev)
41495 /* XXX hack, any other cleaner solution after the driver core
41496 * is converted to allow more than 20 bytes as the device name? */
41497 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
41498 - hdev->vendor, hdev->product, atomic_inc_return(&id));
41499 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
41500
41501 hid_debug_register(hdev, dev_name(&hdev->dev));
41502 ret = device_add(&hdev->dev);
41503 diff --git a/drivers/hid/hid-kye.c b/drivers/hid/hid-kye.c
41504 index e776963..b92bf01 100644
41505 --- a/drivers/hid/hid-kye.c
41506 +++ b/drivers/hid/hid-kye.c
41507 @@ -300,7 +300,7 @@ static __u8 *kye_report_fixup(struct hid_device *hdev, __u8 *rdesc,
41508 * - change the button usage range to 4-7 for the extra
41509 * buttons
41510 */
41511 - if (*rsize >= 74 &&
41512 + if (*rsize >= 75 &&
41513 rdesc[61] == 0x05 && rdesc[62] == 0x08 &&
41514 rdesc[63] == 0x19 && rdesc[64] == 0x08 &&
41515 rdesc[65] == 0x29 && rdesc[66] == 0x0f &&
41516 diff --git a/drivers/hid/hid-lg.c b/drivers/hid/hid-lg.c
41517 index a976f48..f91ff14 100644
41518 --- a/drivers/hid/hid-lg.c
41519 +++ b/drivers/hid/hid-lg.c
41520 @@ -345,14 +345,14 @@ static __u8 *lg_report_fixup(struct hid_device *hdev, __u8 *rdesc,
41521 struct usb_device_descriptor *udesc;
41522 __u16 bcdDevice, rev_maj, rev_min;
41523
41524 - if ((drv_data->quirks & LG_RDESC) && *rsize >= 90 && rdesc[83] == 0x26 &&
41525 + if ((drv_data->quirks & LG_RDESC) && *rsize >= 91 && rdesc[83] == 0x26 &&
41526 rdesc[84] == 0x8c && rdesc[85] == 0x02) {
41527 hid_info(hdev,
41528 "fixing up Logitech keyboard report descriptor\n");
41529 rdesc[84] = rdesc[89] = 0x4d;
41530 rdesc[85] = rdesc[90] = 0x10;
41531 }
41532 - if ((drv_data->quirks & LG_RDESC_REL_ABS) && *rsize >= 50 &&
41533 + if ((drv_data->quirks & LG_RDESC_REL_ABS) && *rsize >= 51 &&
41534 rdesc[32] == 0x81 && rdesc[33] == 0x06 &&
41535 rdesc[49] == 0x81 && rdesc[50] == 0x06) {
41536 hid_info(hdev,
41537 diff --git a/drivers/hid/hid-logitech-dj.c b/drivers/hid/hid-logitech-dj.c
41538 index 486dbde..b7ba829 100644
41539 --- a/drivers/hid/hid-logitech-dj.c
41540 +++ b/drivers/hid/hid-logitech-dj.c
41541 @@ -238,13 +238,6 @@ static void logi_dj_recv_add_djhid_device(struct dj_receiver_dev *djrcv_dev,
41542 return;
41543 }
41544
41545 - if ((dj_report->device_index < DJ_DEVICE_INDEX_MIN) ||
41546 - (dj_report->device_index > DJ_DEVICE_INDEX_MAX)) {
41547 - dev_err(&djrcv_hdev->dev, "%s: invalid device index:%d\n",
41548 - __func__, dj_report->device_index);
41549 - return;
41550 - }
41551 -
41552 if (djrcv_dev->paired_dj_devices[dj_report->device_index]) {
41553 /* The device is already known. No need to reallocate it. */
41554 dbg_hid("%s: device is already known\n", __func__);
41555 @@ -557,7 +550,7 @@ static int logi_dj_ll_raw_request(struct hid_device *hid,
41556 if (!out_buf)
41557 return -ENOMEM;
41558
41559 - if (count < DJREPORT_SHORT_LENGTH - 2)
41560 + if (count > DJREPORT_SHORT_LENGTH - 2)
41561 count = DJREPORT_SHORT_LENGTH - 2;
41562
41563 out_buf[0] = REPORT_ID_DJ_SHORT;
41564 @@ -690,6 +683,12 @@ static int logi_dj_raw_event(struct hid_device *hdev,
41565 * device (via hid_input_report() ) and return 1 so hid-core does not do
41566 * anything else with it.
41567 */
41568 + if ((dj_report->device_index < DJ_DEVICE_INDEX_MIN) ||
41569 + (dj_report->device_index > DJ_DEVICE_INDEX_MAX)) {
41570 + dev_err(&hdev->dev, "%s: invalid device index:%d\n",
41571 + __func__, dj_report->device_index);
41572 + return false;
41573 + }
41574
41575 spin_lock_irqsave(&djrcv_dev->lock, flags);
41576 if (dj_report->report_id == REPORT_ID_DJ_SHORT) {
41577 diff --git a/drivers/hid/hid-monterey.c b/drivers/hid/hid-monterey.c
41578 index 9e14c00..25daf28 100644
41579 --- a/drivers/hid/hid-monterey.c
41580 +++ b/drivers/hid/hid-monterey.c
41581 @@ -24,7 +24,7 @@
41582 static __u8 *mr_report_fixup(struct hid_device *hdev, __u8 *rdesc,
41583 unsigned int *rsize)
41584 {
41585 - if (*rsize >= 30 && rdesc[29] == 0x05 && rdesc[30] == 0x09) {
41586 + if (*rsize >= 31 && rdesc[29] == 0x05 && rdesc[30] == 0x09) {
41587 hid_info(hdev, "fixing up button/consumer in HID report descriptor\n");
41588 rdesc[30] = 0x0c;
41589 }
41590 diff --git a/drivers/hid/hid-petalynx.c b/drivers/hid/hid-petalynx.c
41591 index 736b250..6aca4f2 100644
41592 --- a/drivers/hid/hid-petalynx.c
41593 +++ b/drivers/hid/hid-petalynx.c
41594 @@ -25,7 +25,7 @@
41595 static __u8 *pl_report_fixup(struct hid_device *hdev, __u8 *rdesc,
41596 unsigned int *rsize)
41597 {
41598 - if (*rsize >= 60 && rdesc[39] == 0x2a && rdesc[40] == 0xf5 &&
41599 + if (*rsize >= 62 && rdesc[39] == 0x2a && rdesc[40] == 0xf5 &&
41600 rdesc[41] == 0x00 && rdesc[59] == 0x26 &&
41601 rdesc[60] == 0xf9 && rdesc[61] == 0x00) {
41602 hid_info(hdev, "fixing up Petalynx Maxter Remote report descriptor\n");
41603 diff --git a/drivers/hid/hid-sunplus.c b/drivers/hid/hid-sunplus.c
41604 index 87fc91e..91072fa 100644
41605 --- a/drivers/hid/hid-sunplus.c
41606 +++ b/drivers/hid/hid-sunplus.c
41607 @@ -24,7 +24,7 @@
41608 static __u8 *sp_report_fixup(struct hid_device *hdev, __u8 *rdesc,
41609 unsigned int *rsize)
41610 {
41611 - if (*rsize >= 107 && rdesc[104] == 0x26 && rdesc[105] == 0x80 &&
41612 + if (*rsize >= 112 && rdesc[104] == 0x26 && rdesc[105] == 0x80 &&
41613 rdesc[106] == 0x03) {
41614 hid_info(hdev, "fixing up Sunplus Wireless Desktop report descriptor\n");
41615 rdesc[105] = rdesc[110] = 0x03;
41616 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
41617 index c13fb5b..55a3802 100644
41618 --- a/drivers/hid/hid-wiimote-debug.c
41619 +++ b/drivers/hid/hid-wiimote-debug.c
41620 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
41621 else if (size == 0)
41622 return -EIO;
41623
41624 - if (copy_to_user(u, buf, size))
41625 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
41626 return -EFAULT;
41627
41628 *off += size;
41629 diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
41630 index 0d078c3..cd0962c 100644
41631 --- a/drivers/hid/uhid.c
41632 +++ b/drivers/hid/uhid.c
41633 @@ -47,7 +47,7 @@ struct uhid_device {
41634 struct mutex report_lock;
41635 wait_queue_head_t report_wait;
41636 atomic_t report_done;
41637 - atomic_t report_id;
41638 + atomic_unchecked_t report_id;
41639 struct uhid_event report_buf;
41640 };
41641
41642 @@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
41643
41644 spin_lock_irqsave(&uhid->qlock, flags);
41645 ev->type = UHID_FEATURE;
41646 - ev->u.feature.id = atomic_inc_return(&uhid->report_id);
41647 + ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
41648 ev->u.feature.rnum = rnum;
41649 ev->u.feature.rtype = report_type;
41650
41651 @@ -539,7 +539,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
41652 spin_lock_irqsave(&uhid->qlock, flags);
41653
41654 /* id for old report; drop it silently */
41655 - if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
41656 + if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
41657 goto unlock;
41658 if (atomic_read(&uhid->report_done))
41659 goto unlock;
41660 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
41661 index 602ca86..10a6573 100644
41662 --- a/drivers/hv/channel.c
41663 +++ b/drivers/hv/channel.c
41664 @@ -365,8 +365,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
41665 int ret = 0;
41666 int t;
41667
41668 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
41669 - atomic_inc(&vmbus_connection.next_gpadl_handle);
41670 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
41671 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
41672
41673 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
41674 if (ret)
41675 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
41676 index bcb4950..61dba6c 100644
41677 --- a/drivers/hv/hv.c
41678 +++ b/drivers/hv/hv.c
41679 @@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
41680 u64 output_address = (output) ? virt_to_phys(output) : 0;
41681 u32 output_address_hi = output_address >> 32;
41682 u32 output_address_lo = output_address & 0xFFFFFFFF;
41683 - void *hypercall_page = hv_context.hypercall_page;
41684 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
41685
41686 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
41687 "=a"(hv_status_lo) : "d" (control_hi),
41688 @@ -154,7 +154,7 @@ int hv_init(void)
41689 /* See if the hypercall page is already set */
41690 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
41691
41692 - virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
41693 + virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
41694
41695 if (!virtaddr)
41696 goto cleanup;
41697 diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
41698 index 5e90c5d..d8fcefb 100644
41699 --- a/drivers/hv/hv_balloon.c
41700 +++ b/drivers/hv/hv_balloon.c
41701 @@ -470,7 +470,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
41702
41703 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
41704 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
41705 -static atomic_t trans_id = ATOMIC_INIT(0);
41706 +static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
41707
41708 static int dm_ring_size = (5 * PAGE_SIZE);
41709
41710 @@ -893,7 +893,7 @@ static void hot_add_req(struct work_struct *dummy)
41711 pr_info("Memory hot add failed\n");
41712
41713 dm->state = DM_INITIALIZED;
41714 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
41715 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41716 vmbus_sendpacket(dm->dev->channel, &resp,
41717 sizeof(struct dm_hot_add_response),
41718 (unsigned long)NULL,
41719 @@ -973,7 +973,7 @@ static void post_status(struct hv_dynmem_device *dm)
41720 memset(&status, 0, sizeof(struct dm_status));
41721 status.hdr.type = DM_STATUS_REPORT;
41722 status.hdr.size = sizeof(struct dm_status);
41723 - status.hdr.trans_id = atomic_inc_return(&trans_id);
41724 + status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41725
41726 /*
41727 * The host expects the guest to report free memory.
41728 @@ -993,7 +993,7 @@ static void post_status(struct hv_dynmem_device *dm)
41729 * send the status. This can happen if we were interrupted
41730 * after we picked our transaction ID.
41731 */
41732 - if (status.hdr.trans_id != atomic_read(&trans_id))
41733 + if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
41734 return;
41735
41736 /*
41737 @@ -1129,7 +1129,7 @@ static void balloon_up(struct work_struct *dummy)
41738 */
41739
41740 do {
41741 - bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
41742 + bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41743 ret = vmbus_sendpacket(dm_device.dev->channel,
41744 bl_resp,
41745 bl_resp->hdr.size,
41746 @@ -1175,7 +1175,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
41747
41748 memset(&resp, 0, sizeof(struct dm_unballoon_response));
41749 resp.hdr.type = DM_UNBALLOON_RESPONSE;
41750 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
41751 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41752 resp.hdr.size = sizeof(struct dm_unballoon_response);
41753
41754 vmbus_sendpacket(dm_device.dev->channel, &resp,
41755 @@ -1239,7 +1239,7 @@ static void version_resp(struct hv_dynmem_device *dm,
41756 memset(&version_req, 0, sizeof(struct dm_version_request));
41757 version_req.hdr.type = DM_VERSION_REQUEST;
41758 version_req.hdr.size = sizeof(struct dm_version_request);
41759 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41760 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41761 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
41762 version_req.is_last_attempt = 1;
41763
41764 @@ -1409,7 +1409,7 @@ static int balloon_probe(struct hv_device *dev,
41765 memset(&version_req, 0, sizeof(struct dm_version_request));
41766 version_req.hdr.type = DM_VERSION_REQUEST;
41767 version_req.hdr.size = sizeof(struct dm_version_request);
41768 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41769 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41770 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
41771 version_req.is_last_attempt = 0;
41772
41773 @@ -1440,7 +1440,7 @@ static int balloon_probe(struct hv_device *dev,
41774 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
41775 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
41776 cap_msg.hdr.size = sizeof(struct dm_capabilities);
41777 - cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
41778 + cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41779
41780 cap_msg.caps.cap_bits.balloon = 1;
41781 cap_msg.caps.cap_bits.hot_add = 1;
41782 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
41783 index 860134d..ea3a79a 100644
41784 --- a/drivers/hv/hyperv_vmbus.h
41785 +++ b/drivers/hv/hyperv_vmbus.h
41786 @@ -602,7 +602,7 @@ enum vmbus_connect_state {
41787 struct vmbus_connection {
41788 enum vmbus_connect_state conn_state;
41789
41790 - atomic_t next_gpadl_handle;
41791 + atomic_unchecked_t next_gpadl_handle;
41792
41793 /*
41794 * Represents channel interrupts. Each bit position represents a
41795 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
41796 index 8e53a3c..7a64e44 100644
41797 --- a/drivers/hv/vmbus_drv.c
41798 +++ b/drivers/hv/vmbus_drv.c
41799 @@ -807,10 +807,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
41800 {
41801 int ret = 0;
41802
41803 - static atomic_t device_num = ATOMIC_INIT(0);
41804 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
41805
41806 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
41807 - atomic_inc_return(&device_num));
41808 + atomic_inc_return_unchecked(&device_num));
41809
41810 child_device_obj->device.bus = &hv_bus;
41811 child_device_obj->device.parent = &hv_acpi_dev->dev;
41812 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
41813 index 579bdf9..75118b5 100644
41814 --- a/drivers/hwmon/acpi_power_meter.c
41815 +++ b/drivers/hwmon/acpi_power_meter.c
41816 @@ -116,7 +116,7 @@ struct sensor_template {
41817 struct device_attribute *devattr,
41818 const char *buf, size_t count);
41819 int index;
41820 -};
41821 +} __do_const;
41822
41823 /* Averaging interval */
41824 static int update_avg_interval(struct acpi_power_meter_resource *resource)
41825 @@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
41826 struct sensor_template *attrs)
41827 {
41828 struct device *dev = &resource->acpi_dev->dev;
41829 - struct sensor_device_attribute *sensors =
41830 + sensor_device_attribute_no_const *sensors =
41831 &resource->sensors[resource->num_sensors];
41832 int res = 0;
41833
41834 diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
41835 index 3288f13..71cfb4e 100644
41836 --- a/drivers/hwmon/applesmc.c
41837 +++ b/drivers/hwmon/applesmc.c
41838 @@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
41839 {
41840 struct applesmc_node_group *grp;
41841 struct applesmc_dev_attr *node;
41842 - struct attribute *attr;
41843 + attribute_no_const *attr;
41844 int ret, i;
41845
41846 for (grp = groups; grp->format; grp++) {
41847 diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
41848 index ae208f6..48b6c5b 100644
41849 --- a/drivers/hwmon/asus_atk0110.c
41850 +++ b/drivers/hwmon/asus_atk0110.c
41851 @@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
41852 struct atk_sensor_data {
41853 struct list_head list;
41854 struct atk_data *data;
41855 - struct device_attribute label_attr;
41856 - struct device_attribute input_attr;
41857 - struct device_attribute limit1_attr;
41858 - struct device_attribute limit2_attr;
41859 + device_attribute_no_const label_attr;
41860 + device_attribute_no_const input_attr;
41861 + device_attribute_no_const limit1_attr;
41862 + device_attribute_no_const limit2_attr;
41863 char label_attr_name[ATTR_NAME_SIZE];
41864 char input_attr_name[ATTR_NAME_SIZE];
41865 char limit1_attr_name[ATTR_NAME_SIZE];
41866 @@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
41867 static struct device_attribute atk_name_attr =
41868 __ATTR(name, 0444, atk_name_show, NULL);
41869
41870 -static void atk_init_attribute(struct device_attribute *attr, char *name,
41871 +static void atk_init_attribute(device_attribute_no_const *attr, char *name,
41872 sysfs_show_func show)
41873 {
41874 sysfs_attr_init(&attr->attr);
41875 diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
41876 index d76f0b7..55ae976 100644
41877 --- a/drivers/hwmon/coretemp.c
41878 +++ b/drivers/hwmon/coretemp.c
41879 @@ -784,7 +784,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
41880 return NOTIFY_OK;
41881 }
41882
41883 -static struct notifier_block coretemp_cpu_notifier __refdata = {
41884 +static struct notifier_block coretemp_cpu_notifier = {
41885 .notifier_call = coretemp_cpu_callback,
41886 };
41887
41888 diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
41889 index 632f1dc..57e6a58 100644
41890 --- a/drivers/hwmon/ibmaem.c
41891 +++ b/drivers/hwmon/ibmaem.c
41892 @@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
41893 struct aem_rw_sensor_template *rw)
41894 {
41895 struct device *dev = &data->pdev->dev;
41896 - struct sensor_device_attribute *sensors = data->sensors;
41897 + sensor_device_attribute_no_const *sensors = data->sensors;
41898 int err;
41899
41900 /* Set up read-only sensors */
41901 diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
41902 index 9fbb1b1..efbaa3e 100644
41903 --- a/drivers/hwmon/iio_hwmon.c
41904 +++ b/drivers/hwmon/iio_hwmon.c
41905 @@ -61,7 +61,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
41906 {
41907 struct device *dev = &pdev->dev;
41908 struct iio_hwmon_state *st;
41909 - struct sensor_device_attribute *a;
41910 + sensor_device_attribute_no_const *a;
41911 int ret, i;
41912 int in_i = 1, temp_i = 1, curr_i = 1;
41913 enum iio_chan_type type;
41914 diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
41915 index 38d5a63..cf2c2ea 100644
41916 --- a/drivers/hwmon/nct6775.c
41917 +++ b/drivers/hwmon/nct6775.c
41918 @@ -944,10 +944,10 @@ static struct attribute_group *
41919 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
41920 int repeat)
41921 {
41922 - struct attribute_group *group;
41923 + attribute_group_no_const *group;
41924 struct sensor_device_attr_u *su;
41925 - struct sensor_device_attribute *a;
41926 - struct sensor_device_attribute_2 *a2;
41927 + sensor_device_attribute_no_const *a;
41928 + sensor_device_attribute_2_no_const *a2;
41929 struct attribute **attrs;
41930 struct sensor_device_template **t;
41931 int i, count;
41932 diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
41933 index 291d11f..3f0dbbd 100644
41934 --- a/drivers/hwmon/pmbus/pmbus_core.c
41935 +++ b/drivers/hwmon/pmbus/pmbus_core.c
41936 @@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
41937 return 0;
41938 }
41939
41940 -static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41941 +static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
41942 const char *name,
41943 umode_t mode,
41944 ssize_t (*show)(struct device *dev,
41945 @@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41946 dev_attr->store = store;
41947 }
41948
41949 -static void pmbus_attr_init(struct sensor_device_attribute *a,
41950 +static void pmbus_attr_init(sensor_device_attribute_no_const *a,
41951 const char *name,
41952 umode_t mode,
41953 ssize_t (*show)(struct device *dev,
41954 @@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
41955 u16 reg, u8 mask)
41956 {
41957 struct pmbus_boolean *boolean;
41958 - struct sensor_device_attribute *a;
41959 + sensor_device_attribute_no_const *a;
41960
41961 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
41962 if (!boolean)
41963 @@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
41964 bool update, bool readonly)
41965 {
41966 struct pmbus_sensor *sensor;
41967 - struct device_attribute *a;
41968 + device_attribute_no_const *a;
41969
41970 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
41971 if (!sensor)
41972 @@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
41973 const char *lstring, int index)
41974 {
41975 struct pmbus_label *label;
41976 - struct device_attribute *a;
41977 + device_attribute_no_const *a;
41978
41979 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
41980 if (!label)
41981 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
41982 index 97cd45a..ac54d8b 100644
41983 --- a/drivers/hwmon/sht15.c
41984 +++ b/drivers/hwmon/sht15.c
41985 @@ -169,7 +169,7 @@ struct sht15_data {
41986 int supply_uv;
41987 bool supply_uv_valid;
41988 struct work_struct update_supply_work;
41989 - atomic_t interrupt_handled;
41990 + atomic_unchecked_t interrupt_handled;
41991 };
41992
41993 /**
41994 @@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
41995 ret = gpio_direction_input(data->pdata->gpio_data);
41996 if (ret)
41997 return ret;
41998 - atomic_set(&data->interrupt_handled, 0);
41999 + atomic_set_unchecked(&data->interrupt_handled, 0);
42000
42001 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42002 if (gpio_get_value(data->pdata->gpio_data) == 0) {
42003 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
42004 /* Only relevant if the interrupt hasn't occurred. */
42005 - if (!atomic_read(&data->interrupt_handled))
42006 + if (!atomic_read_unchecked(&data->interrupt_handled))
42007 schedule_work(&data->read_work);
42008 }
42009 ret = wait_event_timeout(data->wait_queue,
42010 @@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
42011
42012 /* First disable the interrupt */
42013 disable_irq_nosync(irq);
42014 - atomic_inc(&data->interrupt_handled);
42015 + atomic_inc_unchecked(&data->interrupt_handled);
42016 /* Then schedule a reading work struct */
42017 if (data->state != SHT15_READING_NOTHING)
42018 schedule_work(&data->read_work);
42019 @@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
42020 * If not, then start the interrupt again - care here as could
42021 * have gone low in meantime so verify it hasn't!
42022 */
42023 - atomic_set(&data->interrupt_handled, 0);
42024 + atomic_set_unchecked(&data->interrupt_handled, 0);
42025 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42026 /* If still not occurred or another handler was scheduled */
42027 if (gpio_get_value(data->pdata->gpio_data)
42028 - || atomic_read(&data->interrupt_handled))
42029 + || atomic_read_unchecked(&data->interrupt_handled))
42030 return;
42031 }
42032
42033 diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
42034 index 8df43c5..b07b91d 100644
42035 --- a/drivers/hwmon/via-cputemp.c
42036 +++ b/drivers/hwmon/via-cputemp.c
42037 @@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
42038 return NOTIFY_OK;
42039 }
42040
42041 -static struct notifier_block via_cputemp_cpu_notifier __refdata = {
42042 +static struct notifier_block via_cputemp_cpu_notifier = {
42043 .notifier_call = via_cputemp_cpu_callback,
42044 };
42045
42046 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
42047 index 41fc683..a39cfea 100644
42048 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
42049 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
42050 @@ -43,7 +43,7 @@
42051 extern struct i2c_adapter amd756_smbus;
42052
42053 static struct i2c_adapter *s4882_adapter;
42054 -static struct i2c_algorithm *s4882_algo;
42055 +static i2c_algorithm_no_const *s4882_algo;
42056
42057 /* Wrapper access functions for multiplexed SMBus */
42058 static DEFINE_MUTEX(amd756_lock);
42059 diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
42060 index 721f7eb..0fd2a09 100644
42061 --- a/drivers/i2c/busses/i2c-diolan-u2c.c
42062 +++ b/drivers/i2c/busses/i2c-diolan-u2c.c
42063 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
42064 /* usb layer */
42065
42066 /* Send command to device, and get response. */
42067 -static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42068 +static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42069 {
42070 int ret = 0;
42071 int actual;
42072 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
42073 index b170bdf..3c76427 100644
42074 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
42075 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
42076 @@ -41,7 +41,7 @@
42077 extern struct i2c_adapter *nforce2_smbus;
42078
42079 static struct i2c_adapter *s4985_adapter;
42080 -static struct i2c_algorithm *s4985_algo;
42081 +static i2c_algorithm_no_const *s4985_algo;
42082
42083 /* Wrapper access functions for multiplexed SMBus */
42084 static DEFINE_MUTEX(nforce2_lock);
42085 diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
42086 index 80b47e8..1a6040d9 100644
42087 --- a/drivers/i2c/i2c-dev.c
42088 +++ b/drivers/i2c/i2c-dev.c
42089 @@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
42090 break;
42091 }
42092
42093 - data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
42094 + data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
42095 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
42096 if (IS_ERR(rdwr_pa[i].buf)) {
42097 res = PTR_ERR(rdwr_pa[i].buf);
42098 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
42099 index 0b510ba..4fbb5085 100644
42100 --- a/drivers/ide/ide-cd.c
42101 +++ b/drivers/ide/ide-cd.c
42102 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
42103 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
42104 if ((unsigned long)buf & alignment
42105 || blk_rq_bytes(rq) & q->dma_pad_mask
42106 - || object_is_on_stack(buf))
42107 + || object_starts_on_stack(buf))
42108 drive->dma = 0;
42109 }
42110 }
42111 diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
42112 index ede16aec..e423e8a 100644
42113 --- a/drivers/iio/industrialio-core.c
42114 +++ b/drivers/iio/industrialio-core.c
42115 @@ -527,7 +527,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
42116 }
42117
42118 static
42119 -int __iio_device_attr_init(struct device_attribute *dev_attr,
42120 +int __iio_device_attr_init(device_attribute_no_const *dev_attr,
42121 const char *postfix,
42122 struct iio_chan_spec const *chan,
42123 ssize_t (*readfunc)(struct device *dev,
42124 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
42125 index c323917..6ddea8b 100644
42126 --- a/drivers/infiniband/core/cm.c
42127 +++ b/drivers/infiniband/core/cm.c
42128 @@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
42129
42130 struct cm_counter_group {
42131 struct kobject obj;
42132 - atomic_long_t counter[CM_ATTR_COUNT];
42133 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
42134 };
42135
42136 struct cm_counter_attribute {
42137 @@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
42138 struct ib_mad_send_buf *msg = NULL;
42139 int ret;
42140
42141 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42142 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42143 counter[CM_REQ_COUNTER]);
42144
42145 /* Quick state check to discard duplicate REQs. */
42146 @@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
42147 if (!cm_id_priv)
42148 return;
42149
42150 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42151 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42152 counter[CM_REP_COUNTER]);
42153 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
42154 if (ret)
42155 @@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
42156 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
42157 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
42158 spin_unlock_irq(&cm_id_priv->lock);
42159 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42160 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42161 counter[CM_RTU_COUNTER]);
42162 goto out;
42163 }
42164 @@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
42165 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
42166 dreq_msg->local_comm_id);
42167 if (!cm_id_priv) {
42168 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42169 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42170 counter[CM_DREQ_COUNTER]);
42171 cm_issue_drep(work->port, work->mad_recv_wc);
42172 return -EINVAL;
42173 @@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
42174 case IB_CM_MRA_REP_RCVD:
42175 break;
42176 case IB_CM_TIMEWAIT:
42177 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42178 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42179 counter[CM_DREQ_COUNTER]);
42180 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42181 goto unlock;
42182 @@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
42183 cm_free_msg(msg);
42184 goto deref;
42185 case IB_CM_DREQ_RCVD:
42186 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42187 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42188 counter[CM_DREQ_COUNTER]);
42189 goto unlock;
42190 default:
42191 @@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
42192 ib_modify_mad(cm_id_priv->av.port->mad_agent,
42193 cm_id_priv->msg, timeout)) {
42194 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
42195 - atomic_long_inc(&work->port->
42196 + atomic_long_inc_unchecked(&work->port->
42197 counter_group[CM_RECV_DUPLICATES].
42198 counter[CM_MRA_COUNTER]);
42199 goto out;
42200 @@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
42201 break;
42202 case IB_CM_MRA_REQ_RCVD:
42203 case IB_CM_MRA_REP_RCVD:
42204 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42205 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42206 counter[CM_MRA_COUNTER]);
42207 /* fall through */
42208 default:
42209 @@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
42210 case IB_CM_LAP_IDLE:
42211 break;
42212 case IB_CM_MRA_LAP_SENT:
42213 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42214 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42215 counter[CM_LAP_COUNTER]);
42216 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42217 goto unlock;
42218 @@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
42219 cm_free_msg(msg);
42220 goto deref;
42221 case IB_CM_LAP_RCVD:
42222 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42223 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42224 counter[CM_LAP_COUNTER]);
42225 goto unlock;
42226 default:
42227 @@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
42228 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
42229 if (cur_cm_id_priv) {
42230 spin_unlock_irq(&cm.lock);
42231 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42232 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42233 counter[CM_SIDR_REQ_COUNTER]);
42234 goto out; /* Duplicate message. */
42235 }
42236 @@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
42237 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
42238 msg->retries = 1;
42239
42240 - atomic_long_add(1 + msg->retries,
42241 + atomic_long_add_unchecked(1 + msg->retries,
42242 &port->counter_group[CM_XMIT].counter[attr_index]);
42243 if (msg->retries)
42244 - atomic_long_add(msg->retries,
42245 + atomic_long_add_unchecked(msg->retries,
42246 &port->counter_group[CM_XMIT_RETRIES].
42247 counter[attr_index]);
42248
42249 @@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
42250 }
42251
42252 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
42253 - atomic_long_inc(&port->counter_group[CM_RECV].
42254 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
42255 counter[attr_id - CM_ATTR_ID_OFFSET]);
42256
42257 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
42258 @@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
42259 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
42260
42261 return sprintf(buf, "%ld\n",
42262 - atomic_long_read(&group->counter[cm_attr->index]));
42263 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
42264 }
42265
42266 static const struct sysfs_ops cm_counter_ops = {
42267 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
42268 index 9f5ad7c..588cd84 100644
42269 --- a/drivers/infiniband/core/fmr_pool.c
42270 +++ b/drivers/infiniband/core/fmr_pool.c
42271 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
42272
42273 struct task_struct *thread;
42274
42275 - atomic_t req_ser;
42276 - atomic_t flush_ser;
42277 + atomic_unchecked_t req_ser;
42278 + atomic_unchecked_t flush_ser;
42279
42280 wait_queue_head_t force_wait;
42281 };
42282 @@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42283 struct ib_fmr_pool *pool = pool_ptr;
42284
42285 do {
42286 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
42287 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
42288 ib_fmr_batch_release(pool);
42289
42290 - atomic_inc(&pool->flush_ser);
42291 + atomic_inc_unchecked(&pool->flush_ser);
42292 wake_up_interruptible(&pool->force_wait);
42293
42294 if (pool->flush_function)
42295 @@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42296 }
42297
42298 set_current_state(TASK_INTERRUPTIBLE);
42299 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
42300 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
42301 !kthread_should_stop())
42302 schedule();
42303 __set_current_state(TASK_RUNNING);
42304 @@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
42305 pool->dirty_watermark = params->dirty_watermark;
42306 pool->dirty_len = 0;
42307 spin_lock_init(&pool->pool_lock);
42308 - atomic_set(&pool->req_ser, 0);
42309 - atomic_set(&pool->flush_ser, 0);
42310 + atomic_set_unchecked(&pool->req_ser, 0);
42311 + atomic_set_unchecked(&pool->flush_ser, 0);
42312 init_waitqueue_head(&pool->force_wait);
42313
42314 pool->thread = kthread_run(ib_fmr_cleanup_thread,
42315 @@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
42316 }
42317 spin_unlock_irq(&pool->pool_lock);
42318
42319 - serial = atomic_inc_return(&pool->req_ser);
42320 + serial = atomic_inc_return_unchecked(&pool->req_ser);
42321 wake_up_process(pool->thread);
42322
42323 if (wait_event_interruptible(pool->force_wait,
42324 - atomic_read(&pool->flush_ser) - serial >= 0))
42325 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
42326 return -EINTR;
42327
42328 return 0;
42329 @@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
42330 } else {
42331 list_add_tail(&fmr->list, &pool->dirty_list);
42332 if (++pool->dirty_len >= pool->dirty_watermark) {
42333 - atomic_inc(&pool->req_ser);
42334 + atomic_inc_unchecked(&pool->req_ser);
42335 wake_up_process(pool->thread);
42336 }
42337 }
42338 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
42339 index ec7a298..8742e59 100644
42340 --- a/drivers/infiniband/hw/cxgb4/mem.c
42341 +++ b/drivers/infiniband/hw/cxgb4/mem.c
42342 @@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42343 int err;
42344 struct fw_ri_tpte tpt;
42345 u32 stag_idx;
42346 - static atomic_t key;
42347 + static atomic_unchecked_t key;
42348
42349 if (c4iw_fatal_error(rdev))
42350 return -EIO;
42351 @@ -270,7 +270,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42352 if (rdev->stats.stag.cur > rdev->stats.stag.max)
42353 rdev->stats.stag.max = rdev->stats.stag.cur;
42354 mutex_unlock(&rdev->stats.lock);
42355 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
42356 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
42357 }
42358 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
42359 __func__, stag_state, type, pdid, stag_idx);
42360 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
42361 index 79b3dbc..96e5fcc 100644
42362 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
42363 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
42364 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42365 struct ib_atomic_eth *ateth;
42366 struct ipath_ack_entry *e;
42367 u64 vaddr;
42368 - atomic64_t *maddr;
42369 + atomic64_unchecked_t *maddr;
42370 u64 sdata;
42371 u32 rkey;
42372 u8 next;
42373 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42374 IB_ACCESS_REMOTE_ATOMIC)))
42375 goto nack_acc_unlck;
42376 /* Perform atomic OP and save result. */
42377 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42378 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42379 sdata = be64_to_cpu(ateth->swap_data);
42380 e = &qp->s_ack_queue[qp->r_head_ack_queue];
42381 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
42382 - (u64) atomic64_add_return(sdata, maddr) - sdata :
42383 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42384 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42385 be64_to_cpu(ateth->compare_data),
42386 sdata);
42387 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
42388 index 1f95bba..9530f87 100644
42389 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
42390 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
42391 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
42392 unsigned long flags;
42393 struct ib_wc wc;
42394 u64 sdata;
42395 - atomic64_t *maddr;
42396 + atomic64_unchecked_t *maddr;
42397 enum ib_wc_status send_status;
42398
42399 /*
42400 @@ -382,11 +382,11 @@ again:
42401 IB_ACCESS_REMOTE_ATOMIC)))
42402 goto acc_err;
42403 /* Perform atomic OP and save result. */
42404 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42405 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42406 sdata = wqe->wr.wr.atomic.compare_add;
42407 *(u64 *) sqp->s_sge.sge.vaddr =
42408 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
42409 - (u64) atomic64_add_return(sdata, maddr) - sdata :
42410 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42411 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42412 sdata, wqe->wr.wr.atomic.swap);
42413 goto send_comp;
42414 diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
42415 index fd36ec6..a6a082f 100644
42416 --- a/drivers/infiniband/hw/mlx4/mad.c
42417 +++ b/drivers/infiniband/hw/mlx4/mad.c
42418 @@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
42419
42420 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
42421 {
42422 - return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
42423 + return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
42424 cpu_to_be64(0xff00000000000000LL);
42425 }
42426
42427 diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
42428 index ed327e6..ca1739e0 100644
42429 --- a/drivers/infiniband/hw/mlx4/mcg.c
42430 +++ b/drivers/infiniband/hw/mlx4/mcg.c
42431 @@ -1041,7 +1041,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
42432 {
42433 char name[20];
42434
42435 - atomic_set(&ctx->tid, 0);
42436 + atomic_set_unchecked(&ctx->tid, 0);
42437 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
42438 ctx->mcg_wq = create_singlethread_workqueue(name);
42439 if (!ctx->mcg_wq)
42440 diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42441 index 66b0b7d..f14836a 100644
42442 --- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
42443 +++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42444 @@ -425,7 +425,7 @@ struct mlx4_ib_demux_ctx {
42445 struct list_head mcg_mgid0_list;
42446 struct workqueue_struct *mcg_wq;
42447 struct mlx4_ib_demux_pv_ctx **tun;
42448 - atomic_t tid;
42449 + atomic_unchecked_t tid;
42450 int flushing; /* flushing the work queue */
42451 };
42452
42453 diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
42454 index 9d3e5c1..6f166df 100644
42455 --- a/drivers/infiniband/hw/mthca/mthca_cmd.c
42456 +++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
42457 @@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
42458 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
42459 }
42460
42461 -int mthca_QUERY_FW(struct mthca_dev *dev)
42462 +int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
42463 {
42464 struct mthca_mailbox *mailbox;
42465 u32 *outbox;
42466 @@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42467 CMD_TIME_CLASS_B);
42468 }
42469
42470 -int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42471 +int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42472 int num_mtt)
42473 {
42474 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
42475 @@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
42476 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
42477 }
42478
42479 -int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42480 +int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42481 int eq_num)
42482 {
42483 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
42484 @@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
42485 CMD_TIME_CLASS_B);
42486 }
42487
42488 -int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42489 +int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42490 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
42491 void *in_mad, void *response_mad)
42492 {
42493 diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
42494 index ded76c1..0cf0a08 100644
42495 --- a/drivers/infiniband/hw/mthca/mthca_main.c
42496 +++ b/drivers/infiniband/hw/mthca/mthca_main.c
42497 @@ -692,7 +692,7 @@ err_close:
42498 return err;
42499 }
42500
42501 -static int mthca_setup_hca(struct mthca_dev *dev)
42502 +static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
42503 {
42504 int err;
42505
42506 diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
42507 index ed9a989..6aa5dc2 100644
42508 --- a/drivers/infiniband/hw/mthca/mthca_mr.c
42509 +++ b/drivers/infiniband/hw/mthca/mthca_mr.c
42510 @@ -81,7 +81,7 @@ struct mthca_mpt_entry {
42511 * through the bitmaps)
42512 */
42513
42514 -static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42515 +static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42516 {
42517 int o;
42518 int m;
42519 @@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
42520 return key;
42521 }
42522
42523 -int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42524 +int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42525 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
42526 {
42527 struct mthca_mailbox *mailbox;
42528 @@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
42529 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
42530 }
42531
42532 -int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42533 +int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42534 u64 *buffer_list, int buffer_size_shift,
42535 int list_len, u64 iova, u64 total_size,
42536 u32 access, struct mthca_mr *mr)
42537 diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
42538 index 415f8e1..e34214e 100644
42539 --- a/drivers/infiniband/hw/mthca/mthca_provider.c
42540 +++ b/drivers/infiniband/hw/mthca/mthca_provider.c
42541 @@ -764,7 +764,7 @@ unlock:
42542 return 0;
42543 }
42544
42545 -static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42546 +static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42547 {
42548 struct mthca_dev *dev = to_mdev(ibcq->device);
42549 struct mthca_cq *cq = to_mcq(ibcq);
42550 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
42551 index 353c7b0..c6ce921 100644
42552 --- a/drivers/infiniband/hw/nes/nes.c
42553 +++ b/drivers/infiniband/hw/nes/nes.c
42554 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
42555 LIST_HEAD(nes_adapter_list);
42556 static LIST_HEAD(nes_dev_list);
42557
42558 -atomic_t qps_destroyed;
42559 +atomic_unchecked_t qps_destroyed;
42560
42561 static unsigned int ee_flsh_adapter;
42562 static unsigned int sysfs_nonidx_addr;
42563 @@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
42564 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
42565 struct nes_adapter *nesadapter = nesdev->nesadapter;
42566
42567 - atomic_inc(&qps_destroyed);
42568 + atomic_inc_unchecked(&qps_destroyed);
42569
42570 /* Free the control structures */
42571
42572 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
42573 index 33cc589..3bd6538 100644
42574 --- a/drivers/infiniband/hw/nes/nes.h
42575 +++ b/drivers/infiniband/hw/nes/nes.h
42576 @@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
42577 extern unsigned int wqm_quanta;
42578 extern struct list_head nes_adapter_list;
42579
42580 -extern atomic_t cm_connects;
42581 -extern atomic_t cm_accepts;
42582 -extern atomic_t cm_disconnects;
42583 -extern atomic_t cm_closes;
42584 -extern atomic_t cm_connecteds;
42585 -extern atomic_t cm_connect_reqs;
42586 -extern atomic_t cm_rejects;
42587 -extern atomic_t mod_qp_timouts;
42588 -extern atomic_t qps_created;
42589 -extern atomic_t qps_destroyed;
42590 -extern atomic_t sw_qps_destroyed;
42591 +extern atomic_unchecked_t cm_connects;
42592 +extern atomic_unchecked_t cm_accepts;
42593 +extern atomic_unchecked_t cm_disconnects;
42594 +extern atomic_unchecked_t cm_closes;
42595 +extern atomic_unchecked_t cm_connecteds;
42596 +extern atomic_unchecked_t cm_connect_reqs;
42597 +extern atomic_unchecked_t cm_rejects;
42598 +extern atomic_unchecked_t mod_qp_timouts;
42599 +extern atomic_unchecked_t qps_created;
42600 +extern atomic_unchecked_t qps_destroyed;
42601 +extern atomic_unchecked_t sw_qps_destroyed;
42602 extern u32 mh_detected;
42603 extern u32 mh_pauses_sent;
42604 extern u32 cm_packets_sent;
42605 @@ -196,16 +196,16 @@ extern u32 cm_packets_created;
42606 extern u32 cm_packets_received;
42607 extern u32 cm_packets_dropped;
42608 extern u32 cm_packets_retrans;
42609 -extern atomic_t cm_listens_created;
42610 -extern atomic_t cm_listens_destroyed;
42611 +extern atomic_unchecked_t cm_listens_created;
42612 +extern atomic_unchecked_t cm_listens_destroyed;
42613 extern u32 cm_backlog_drops;
42614 -extern atomic_t cm_loopbacks;
42615 -extern atomic_t cm_nodes_created;
42616 -extern atomic_t cm_nodes_destroyed;
42617 -extern atomic_t cm_accel_dropped_pkts;
42618 -extern atomic_t cm_resets_recvd;
42619 -extern atomic_t pau_qps_created;
42620 -extern atomic_t pau_qps_destroyed;
42621 +extern atomic_unchecked_t cm_loopbacks;
42622 +extern atomic_unchecked_t cm_nodes_created;
42623 +extern atomic_unchecked_t cm_nodes_destroyed;
42624 +extern atomic_unchecked_t cm_accel_dropped_pkts;
42625 +extern atomic_unchecked_t cm_resets_recvd;
42626 +extern atomic_unchecked_t pau_qps_created;
42627 +extern atomic_unchecked_t pau_qps_destroyed;
42628
42629 extern u32 int_mod_timer_init;
42630 extern u32 int_mod_cq_depth_256;
42631 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
42632 index dfa9df4..6bf7221 100644
42633 --- a/drivers/infiniband/hw/nes/nes_cm.c
42634 +++ b/drivers/infiniband/hw/nes/nes_cm.c
42635 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
42636 u32 cm_packets_retrans;
42637 u32 cm_packets_created;
42638 u32 cm_packets_received;
42639 -atomic_t cm_listens_created;
42640 -atomic_t cm_listens_destroyed;
42641 +atomic_unchecked_t cm_listens_created;
42642 +atomic_unchecked_t cm_listens_destroyed;
42643 u32 cm_backlog_drops;
42644 -atomic_t cm_loopbacks;
42645 -atomic_t cm_nodes_created;
42646 -atomic_t cm_nodes_destroyed;
42647 -atomic_t cm_accel_dropped_pkts;
42648 -atomic_t cm_resets_recvd;
42649 +atomic_unchecked_t cm_loopbacks;
42650 +atomic_unchecked_t cm_nodes_created;
42651 +atomic_unchecked_t cm_nodes_destroyed;
42652 +atomic_unchecked_t cm_accel_dropped_pkts;
42653 +atomic_unchecked_t cm_resets_recvd;
42654
42655 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
42656 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
42657 @@ -134,28 +134,28 @@ static void record_ird_ord(struct nes_cm_node *, u16, u16);
42658 /* instance of function pointers for client API */
42659 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
42660 static struct nes_cm_ops nes_cm_api = {
42661 - mini_cm_accelerated,
42662 - mini_cm_listen,
42663 - mini_cm_del_listen,
42664 - mini_cm_connect,
42665 - mini_cm_close,
42666 - mini_cm_accept,
42667 - mini_cm_reject,
42668 - mini_cm_recv_pkt,
42669 - mini_cm_dealloc_core,
42670 - mini_cm_get,
42671 - mini_cm_set
42672 + .accelerated = mini_cm_accelerated,
42673 + .listen = mini_cm_listen,
42674 + .stop_listener = mini_cm_del_listen,
42675 + .connect = mini_cm_connect,
42676 + .close = mini_cm_close,
42677 + .accept = mini_cm_accept,
42678 + .reject = mini_cm_reject,
42679 + .recv_pkt = mini_cm_recv_pkt,
42680 + .destroy_cm_core = mini_cm_dealloc_core,
42681 + .get = mini_cm_get,
42682 + .set = mini_cm_set
42683 };
42684
42685 static struct nes_cm_core *g_cm_core;
42686
42687 -atomic_t cm_connects;
42688 -atomic_t cm_accepts;
42689 -atomic_t cm_disconnects;
42690 -atomic_t cm_closes;
42691 -atomic_t cm_connecteds;
42692 -atomic_t cm_connect_reqs;
42693 -atomic_t cm_rejects;
42694 +atomic_unchecked_t cm_connects;
42695 +atomic_unchecked_t cm_accepts;
42696 +atomic_unchecked_t cm_disconnects;
42697 +atomic_unchecked_t cm_closes;
42698 +atomic_unchecked_t cm_connecteds;
42699 +atomic_unchecked_t cm_connect_reqs;
42700 +atomic_unchecked_t cm_rejects;
42701
42702 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
42703 {
42704 @@ -1319,7 +1319,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
42705 kfree(listener);
42706 listener = NULL;
42707 ret = 0;
42708 - atomic_inc(&cm_listens_destroyed);
42709 + atomic_inc_unchecked(&cm_listens_destroyed);
42710 } else {
42711 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
42712 }
42713 @@ -1513,7 +1513,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
42714 cm_node->rem_mac);
42715
42716 add_hte_node(cm_core, cm_node);
42717 - atomic_inc(&cm_nodes_created);
42718 + atomic_inc_unchecked(&cm_nodes_created);
42719
42720 return cm_node;
42721 }
42722 @@ -1571,7 +1571,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
42723 }
42724
42725 atomic_dec(&cm_core->node_cnt);
42726 - atomic_inc(&cm_nodes_destroyed);
42727 + atomic_inc_unchecked(&cm_nodes_destroyed);
42728 nesqp = cm_node->nesqp;
42729 if (nesqp) {
42730 nesqp->cm_node = NULL;
42731 @@ -1635,7 +1635,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
42732
42733 static void drop_packet(struct sk_buff *skb)
42734 {
42735 - atomic_inc(&cm_accel_dropped_pkts);
42736 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
42737 dev_kfree_skb_any(skb);
42738 }
42739
42740 @@ -1698,7 +1698,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
42741 {
42742
42743 int reset = 0; /* whether to send reset in case of err.. */
42744 - atomic_inc(&cm_resets_recvd);
42745 + atomic_inc_unchecked(&cm_resets_recvd);
42746 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
42747 " refcnt=%d\n", cm_node, cm_node->state,
42748 atomic_read(&cm_node->ref_count));
42749 @@ -2339,7 +2339,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
42750 rem_ref_cm_node(cm_node->cm_core, cm_node);
42751 return NULL;
42752 }
42753 - atomic_inc(&cm_loopbacks);
42754 + atomic_inc_unchecked(&cm_loopbacks);
42755 loopbackremotenode->loopbackpartner = cm_node;
42756 loopbackremotenode->tcp_cntxt.rcv_wscale =
42757 NES_CM_DEFAULT_RCV_WND_SCALE;
42758 @@ -2614,7 +2614,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
42759 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
42760 else {
42761 rem_ref_cm_node(cm_core, cm_node);
42762 - atomic_inc(&cm_accel_dropped_pkts);
42763 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
42764 dev_kfree_skb_any(skb);
42765 }
42766 break;
42767 @@ -2922,7 +2922,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42768
42769 if ((cm_id) && (cm_id->event_handler)) {
42770 if (issue_disconn) {
42771 - atomic_inc(&cm_disconnects);
42772 + atomic_inc_unchecked(&cm_disconnects);
42773 cm_event.event = IW_CM_EVENT_DISCONNECT;
42774 cm_event.status = disconn_status;
42775 cm_event.local_addr = cm_id->local_addr;
42776 @@ -2944,7 +2944,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42777 }
42778
42779 if (issue_close) {
42780 - atomic_inc(&cm_closes);
42781 + atomic_inc_unchecked(&cm_closes);
42782 nes_disconnect(nesqp, 1);
42783
42784 cm_id->provider_data = nesqp;
42785 @@ -3082,7 +3082,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42786
42787 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
42788 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
42789 - atomic_inc(&cm_accepts);
42790 + atomic_inc_unchecked(&cm_accepts);
42791
42792 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
42793 netdev_refcnt_read(nesvnic->netdev));
42794 @@ -3278,7 +3278,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
42795 struct nes_cm_core *cm_core;
42796 u8 *start_buff;
42797
42798 - atomic_inc(&cm_rejects);
42799 + atomic_inc_unchecked(&cm_rejects);
42800 cm_node = (struct nes_cm_node *)cm_id->provider_data;
42801 loopback = cm_node->loopbackpartner;
42802 cm_core = cm_node->cm_core;
42803 @@ -3340,7 +3340,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42804 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
42805 ntohs(laddr->sin_port));
42806
42807 - atomic_inc(&cm_connects);
42808 + atomic_inc_unchecked(&cm_connects);
42809 nesqp->active_conn = 1;
42810
42811 /* cache the cm_id in the qp */
42812 @@ -3451,7 +3451,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
42813 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
42814 return err;
42815 }
42816 - atomic_inc(&cm_listens_created);
42817 + atomic_inc_unchecked(&cm_listens_created);
42818 }
42819
42820 cm_id->add_ref(cm_id);
42821 @@ -3558,7 +3558,7 @@ static void cm_event_connected(struct nes_cm_event *event)
42822
42823 if (nesqp->destroyed)
42824 return;
42825 - atomic_inc(&cm_connecteds);
42826 + atomic_inc_unchecked(&cm_connecteds);
42827 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
42828 " local port 0x%04X. jiffies = %lu.\n",
42829 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
42830 @@ -3741,7 +3741,7 @@ static void cm_event_reset(struct nes_cm_event *event)
42831
42832 cm_id->add_ref(cm_id);
42833 ret = cm_id->event_handler(cm_id, &cm_event);
42834 - atomic_inc(&cm_closes);
42835 + atomic_inc_unchecked(&cm_closes);
42836 cm_event.event = IW_CM_EVENT_CLOSE;
42837 cm_event.status = 0;
42838 cm_event.provider_data = cm_id->provider_data;
42839 @@ -3781,7 +3781,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
42840 return;
42841 cm_id = cm_node->cm_id;
42842
42843 - atomic_inc(&cm_connect_reqs);
42844 + atomic_inc_unchecked(&cm_connect_reqs);
42845 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42846 cm_node, cm_id, jiffies);
42847
42848 @@ -3830,7 +3830,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
42849 return;
42850 cm_id = cm_node->cm_id;
42851
42852 - atomic_inc(&cm_connect_reqs);
42853 + atomic_inc_unchecked(&cm_connect_reqs);
42854 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42855 cm_node, cm_id, jiffies);
42856
42857 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
42858 index 4166452..fc952c3 100644
42859 --- a/drivers/infiniband/hw/nes/nes_mgt.c
42860 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
42861 @@ -40,8 +40,8 @@
42862 #include "nes.h"
42863 #include "nes_mgt.h"
42864
42865 -atomic_t pau_qps_created;
42866 -atomic_t pau_qps_destroyed;
42867 +atomic_unchecked_t pau_qps_created;
42868 +atomic_unchecked_t pau_qps_destroyed;
42869
42870 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
42871 {
42872 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
42873 {
42874 struct sk_buff *skb;
42875 unsigned long flags;
42876 - atomic_inc(&pau_qps_destroyed);
42877 + atomic_inc_unchecked(&pau_qps_destroyed);
42878
42879 /* Free packets that have not yet been forwarded */
42880 /* Lock is acquired by skb_dequeue when removing the skb */
42881 @@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
42882 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
42883 skb_queue_head_init(&nesqp->pau_list);
42884 spin_lock_init(&nesqp->pau_lock);
42885 - atomic_inc(&pau_qps_created);
42886 + atomic_inc_unchecked(&pau_qps_created);
42887 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
42888 }
42889
42890 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
42891 index 49eb511..a774366 100644
42892 --- a/drivers/infiniband/hw/nes/nes_nic.c
42893 +++ b/drivers/infiniband/hw/nes/nes_nic.c
42894 @@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
42895 target_stat_values[++index] = mh_detected;
42896 target_stat_values[++index] = mh_pauses_sent;
42897 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
42898 - target_stat_values[++index] = atomic_read(&cm_connects);
42899 - target_stat_values[++index] = atomic_read(&cm_accepts);
42900 - target_stat_values[++index] = atomic_read(&cm_disconnects);
42901 - target_stat_values[++index] = atomic_read(&cm_connecteds);
42902 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
42903 - target_stat_values[++index] = atomic_read(&cm_rejects);
42904 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
42905 - target_stat_values[++index] = atomic_read(&qps_created);
42906 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
42907 - target_stat_values[++index] = atomic_read(&qps_destroyed);
42908 - target_stat_values[++index] = atomic_read(&cm_closes);
42909 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
42910 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
42911 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
42912 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
42913 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
42914 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
42915 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
42916 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
42917 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
42918 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
42919 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
42920 target_stat_values[++index] = cm_packets_sent;
42921 target_stat_values[++index] = cm_packets_bounced;
42922 target_stat_values[++index] = cm_packets_created;
42923 target_stat_values[++index] = cm_packets_received;
42924 target_stat_values[++index] = cm_packets_dropped;
42925 target_stat_values[++index] = cm_packets_retrans;
42926 - target_stat_values[++index] = atomic_read(&cm_listens_created);
42927 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
42928 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
42929 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
42930 target_stat_values[++index] = cm_backlog_drops;
42931 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
42932 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
42933 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
42934 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
42935 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
42936 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
42937 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
42938 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
42939 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
42940 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
42941 target_stat_values[++index] = nesadapter->free_4kpbl;
42942 target_stat_values[++index] = nesadapter->free_256pbl;
42943 target_stat_values[++index] = int_mod_timer_init;
42944 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
42945 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
42946 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
42947 - target_stat_values[++index] = atomic_read(&pau_qps_created);
42948 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
42949 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
42950 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
42951 }
42952
42953 /**
42954 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
42955 index 218dd35..97ce31d 100644
42956 --- a/drivers/infiniband/hw/nes/nes_verbs.c
42957 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
42958 @@ -46,9 +46,9 @@
42959
42960 #include <rdma/ib_umem.h>
42961
42962 -atomic_t mod_qp_timouts;
42963 -atomic_t qps_created;
42964 -atomic_t sw_qps_destroyed;
42965 +atomic_unchecked_t mod_qp_timouts;
42966 +atomic_unchecked_t qps_created;
42967 +atomic_unchecked_t sw_qps_destroyed;
42968
42969 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
42970
42971 @@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
42972 if (init_attr->create_flags)
42973 return ERR_PTR(-EINVAL);
42974
42975 - atomic_inc(&qps_created);
42976 + atomic_inc_unchecked(&qps_created);
42977 switch (init_attr->qp_type) {
42978 case IB_QPT_RC:
42979 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
42980 @@ -1468,7 +1468,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
42981 struct iw_cm_event cm_event;
42982 int ret = 0;
42983
42984 - atomic_inc(&sw_qps_destroyed);
42985 + atomic_inc_unchecked(&sw_qps_destroyed);
42986 nesqp->destroyed = 1;
42987
42988 /* Blow away the connection if it exists. */
42989 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
42990 index c00ae09..04e91be 100644
42991 --- a/drivers/infiniband/hw/qib/qib.h
42992 +++ b/drivers/infiniband/hw/qib/qib.h
42993 @@ -52,6 +52,7 @@
42994 #include <linux/kref.h>
42995 #include <linux/sched.h>
42996 #include <linux/kthread.h>
42997 +#include <linux/slab.h>
42998
42999 #include "qib_common.h"
43000 #include "qib_verbs.h"
43001 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
43002 index 24c41ba..102d71f 100644
43003 --- a/drivers/input/gameport/gameport.c
43004 +++ b/drivers/input/gameport/gameport.c
43005 @@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
43006 */
43007 static void gameport_init_port(struct gameport *gameport)
43008 {
43009 - static atomic_t gameport_no = ATOMIC_INIT(0);
43010 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
43011
43012 __module_get(THIS_MODULE);
43013
43014 mutex_init(&gameport->drv_mutex);
43015 device_initialize(&gameport->dev);
43016 dev_set_name(&gameport->dev, "gameport%lu",
43017 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
43018 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
43019 gameport->dev.bus = &gameport_bus;
43020 gameport->dev.release = gameport_release_port;
43021 if (gameport->parent)
43022 diff --git a/drivers/input/input.c b/drivers/input/input.c
43023 index 29ca0bb..f4bc2e3 100644
43024 --- a/drivers/input/input.c
43025 +++ b/drivers/input/input.c
43026 @@ -1774,7 +1774,7 @@ EXPORT_SYMBOL_GPL(input_class);
43027 */
43028 struct input_dev *input_allocate_device(void)
43029 {
43030 - static atomic_t input_no = ATOMIC_INIT(0);
43031 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
43032 struct input_dev *dev;
43033
43034 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
43035 @@ -1789,7 +1789,7 @@ struct input_dev *input_allocate_device(void)
43036 INIT_LIST_HEAD(&dev->node);
43037
43038 dev_set_name(&dev->dev, "input%ld",
43039 - (unsigned long) atomic_inc_return(&input_no) - 1);
43040 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
43041
43042 __module_get(THIS_MODULE);
43043 }
43044 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
43045 index 4a95b22..874c182 100644
43046 --- a/drivers/input/joystick/sidewinder.c
43047 +++ b/drivers/input/joystick/sidewinder.c
43048 @@ -30,6 +30,7 @@
43049 #include <linux/kernel.h>
43050 #include <linux/module.h>
43051 #include <linux/slab.h>
43052 +#include <linux/sched.h>
43053 #include <linux/input.h>
43054 #include <linux/gameport.h>
43055 #include <linux/jiffies.h>
43056 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
43057 index 603fe0d..f63decc 100644
43058 --- a/drivers/input/joystick/xpad.c
43059 +++ b/drivers/input/joystick/xpad.c
43060 @@ -737,7 +737,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
43061
43062 static int xpad_led_probe(struct usb_xpad *xpad)
43063 {
43064 - static atomic_t led_seq = ATOMIC_INIT(0);
43065 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
43066 long led_no;
43067 struct xpad_led *led;
43068 struct led_classdev *led_cdev;
43069 @@ -750,7 +750,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
43070 if (!led)
43071 return -ENOMEM;
43072
43073 - led_no = (long)atomic_inc_return(&led_seq) - 1;
43074 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
43075
43076 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
43077 led->xpad = xpad;
43078 diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
43079 index 5a73639..d586683 100644
43080 --- a/drivers/input/misc/ims-pcu.c
43081 +++ b/drivers/input/misc/ims-pcu.c
43082 @@ -1850,7 +1850,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
43083
43084 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
43085 {
43086 - static atomic_t device_no = ATOMIC_INIT(0);
43087 + static atomic_unchecked_t device_no = ATOMIC_INIT(0);
43088
43089 const struct ims_pcu_device_info *info;
43090 int error;
43091 @@ -1881,7 +1881,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
43092 }
43093
43094 /* Device appears to be operable, complete initialization */
43095 - pcu->device_no = atomic_inc_return(&device_no) - 1;
43096 + pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
43097
43098 /*
43099 * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor
43100 diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
43101 index 2f0b39d..7370f13 100644
43102 --- a/drivers/input/mouse/psmouse.h
43103 +++ b/drivers/input/mouse/psmouse.h
43104 @@ -116,7 +116,7 @@ struct psmouse_attribute {
43105 ssize_t (*set)(struct psmouse *psmouse, void *data,
43106 const char *buf, size_t count);
43107 bool protect;
43108 -};
43109 +} __do_const;
43110 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
43111
43112 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
43113 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
43114 index b604564..3f14ae4 100644
43115 --- a/drivers/input/mousedev.c
43116 +++ b/drivers/input/mousedev.c
43117 @@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
43118
43119 spin_unlock_irq(&client->packet_lock);
43120
43121 - if (copy_to_user(buffer, data, count))
43122 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
43123 return -EFAULT;
43124
43125 return count;
43126 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
43127 index b29134d..394deb0 100644
43128 --- a/drivers/input/serio/serio.c
43129 +++ b/drivers/input/serio/serio.c
43130 @@ -514,7 +514,7 @@ static void serio_release_port(struct device *dev)
43131 */
43132 static void serio_init_port(struct serio *serio)
43133 {
43134 - static atomic_t serio_no = ATOMIC_INIT(0);
43135 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
43136
43137 __module_get(THIS_MODULE);
43138
43139 @@ -525,7 +525,7 @@ static void serio_init_port(struct serio *serio)
43140 mutex_init(&serio->drv_mutex);
43141 device_initialize(&serio->dev);
43142 dev_set_name(&serio->dev, "serio%ld",
43143 - (long)atomic_inc_return(&serio_no) - 1);
43144 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
43145 serio->dev.bus = &serio_bus;
43146 serio->dev.release = serio_release_port;
43147 serio->dev.groups = serio_device_attr_groups;
43148 diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
43149 index c9a02fe..0debc75 100644
43150 --- a/drivers/input/serio/serio_raw.c
43151 +++ b/drivers/input/serio/serio_raw.c
43152 @@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
43153
43154 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43155 {
43156 - static atomic_t serio_raw_no = ATOMIC_INIT(0);
43157 + static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
43158 struct serio_raw *serio_raw;
43159 int err;
43160
43161 @@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43162 }
43163
43164 snprintf(serio_raw->name, sizeof(serio_raw->name),
43165 - "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
43166 + "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
43167 kref_init(&serio_raw->kref);
43168 INIT_LIST_HEAD(&serio_raw->client_list);
43169 init_waitqueue_head(&serio_raw->wait);
43170 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
43171 index e5555fc..937986d 100644
43172 --- a/drivers/iommu/iommu.c
43173 +++ b/drivers/iommu/iommu.c
43174 @@ -588,7 +588,7 @@ static struct notifier_block iommu_bus_nb = {
43175 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
43176 {
43177 bus_register_notifier(bus, &iommu_bus_nb);
43178 - bus_for_each_dev(bus, NULL, ops, add_iommu_group);
43179 + bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
43180 }
43181
43182 /**
43183 diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
43184 index 228632c9..edfe331 100644
43185 --- a/drivers/iommu/irq_remapping.c
43186 +++ b/drivers/iommu/irq_remapping.c
43187 @@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
43188 void panic_if_irq_remap(const char *msg)
43189 {
43190 if (irq_remapping_enabled)
43191 - panic(msg);
43192 + panic("%s", msg);
43193 }
43194
43195 static void ir_ack_apic_edge(struct irq_data *data)
43196 @@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
43197
43198 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
43199 {
43200 - chip->irq_print_chip = ir_print_prefix;
43201 - chip->irq_ack = ir_ack_apic_edge;
43202 - chip->irq_eoi = ir_ack_apic_level;
43203 - chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43204 + pax_open_kernel();
43205 + *(void **)&chip->irq_print_chip = ir_print_prefix;
43206 + *(void **)&chip->irq_ack = ir_ack_apic_edge;
43207 + *(void **)&chip->irq_eoi = ir_ack_apic_level;
43208 + *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43209 + pax_close_kernel();
43210 }
43211
43212 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
43213 diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
43214 index 739ca67..42ee3f1 100644
43215 --- a/drivers/irqchip/irq-gic.c
43216 +++ b/drivers/irqchip/irq-gic.c
43217 @@ -85,7 +85,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
43218 * Supported arch specific GIC irq extension.
43219 * Default make them NULL.
43220 */
43221 -struct irq_chip gic_arch_extn = {
43222 +irq_chip_no_const gic_arch_extn = {
43223 .irq_eoi = NULL,
43224 .irq_mask = NULL,
43225 .irq_unmask = NULL,
43226 @@ -337,7 +337,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
43227 chained_irq_exit(chip, desc);
43228 }
43229
43230 -static struct irq_chip gic_chip = {
43231 +static irq_chip_no_const gic_chip __read_only = {
43232 .name = "GIC",
43233 .irq_mask = gic_mask_irq,
43234 .irq_unmask = gic_unmask_irq,
43235 diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
43236 index 8777065..a4a9967 100644
43237 --- a/drivers/irqchip/irq-renesas-irqc.c
43238 +++ b/drivers/irqchip/irq-renesas-irqc.c
43239 @@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
43240 struct irqc_priv *p;
43241 struct resource *io;
43242 struct resource *irq;
43243 - struct irq_chip *irq_chip;
43244 + irq_chip_no_const *irq_chip;
43245 const char *name = dev_name(&pdev->dev);
43246 int ret;
43247 int k;
43248 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
43249 index ac6f72b..81150f2 100644
43250 --- a/drivers/isdn/capi/capi.c
43251 +++ b/drivers/isdn/capi/capi.c
43252 @@ -81,8 +81,8 @@ struct capiminor {
43253
43254 struct capi20_appl *ap;
43255 u32 ncci;
43256 - atomic_t datahandle;
43257 - atomic_t msgid;
43258 + atomic_unchecked_t datahandle;
43259 + atomic_unchecked_t msgid;
43260
43261 struct tty_port port;
43262 int ttyinstop;
43263 @@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
43264 capimsg_setu16(s, 2, mp->ap->applid);
43265 capimsg_setu8 (s, 4, CAPI_DATA_B3);
43266 capimsg_setu8 (s, 5, CAPI_RESP);
43267 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
43268 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
43269 capimsg_setu32(s, 8, mp->ncci);
43270 capimsg_setu16(s, 12, datahandle);
43271 }
43272 @@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
43273 mp->outbytes -= len;
43274 spin_unlock_bh(&mp->outlock);
43275
43276 - datahandle = atomic_inc_return(&mp->datahandle);
43277 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
43278 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
43279 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43280 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43281 capimsg_setu16(skb->data, 2, mp->ap->applid);
43282 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
43283 capimsg_setu8 (skb->data, 5, CAPI_REQ);
43284 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
43285 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
43286 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
43287 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
43288 capimsg_setu16(skb->data, 16, len); /* Data length */
43289 diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
43290 index c44950d..10ac276 100644
43291 --- a/drivers/isdn/gigaset/bas-gigaset.c
43292 +++ b/drivers/isdn/gigaset/bas-gigaset.c
43293 @@ -2564,22 +2564,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
43294
43295
43296 static const struct gigaset_ops gigops = {
43297 - gigaset_write_cmd,
43298 - gigaset_write_room,
43299 - gigaset_chars_in_buffer,
43300 - gigaset_brkchars,
43301 - gigaset_init_bchannel,
43302 - gigaset_close_bchannel,
43303 - gigaset_initbcshw,
43304 - gigaset_freebcshw,
43305 - gigaset_reinitbcshw,
43306 - gigaset_initcshw,
43307 - gigaset_freecshw,
43308 - gigaset_set_modem_ctrl,
43309 - gigaset_baud_rate,
43310 - gigaset_set_line_ctrl,
43311 - gigaset_isoc_send_skb,
43312 - gigaset_isoc_input,
43313 + .write_cmd = gigaset_write_cmd,
43314 + .write_room = gigaset_write_room,
43315 + .chars_in_buffer = gigaset_chars_in_buffer,
43316 + .brkchars = gigaset_brkchars,
43317 + .init_bchannel = gigaset_init_bchannel,
43318 + .close_bchannel = gigaset_close_bchannel,
43319 + .initbcshw = gigaset_initbcshw,
43320 + .freebcshw = gigaset_freebcshw,
43321 + .reinitbcshw = gigaset_reinitbcshw,
43322 + .initcshw = gigaset_initcshw,
43323 + .freecshw = gigaset_freecshw,
43324 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43325 + .baud_rate = gigaset_baud_rate,
43326 + .set_line_ctrl = gigaset_set_line_ctrl,
43327 + .send_skb = gigaset_isoc_send_skb,
43328 + .handle_input = gigaset_isoc_input,
43329 };
43330
43331 /* bas_gigaset_init
43332 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
43333 index 600c79b..3752bab 100644
43334 --- a/drivers/isdn/gigaset/interface.c
43335 +++ b/drivers/isdn/gigaset/interface.c
43336 @@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
43337 }
43338 tty->driver_data = cs;
43339
43340 - ++cs->port.count;
43341 + atomic_inc(&cs->port.count);
43342
43343 - if (cs->port.count == 1) {
43344 + if (atomic_read(&cs->port.count) == 1) {
43345 tty_port_tty_set(&cs->port, tty);
43346 cs->port.low_latency = 1;
43347 }
43348 @@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
43349
43350 if (!cs->connected)
43351 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
43352 - else if (!cs->port.count)
43353 + else if (!atomic_read(&cs->port.count))
43354 dev_warn(cs->dev, "%s: device not opened\n", __func__);
43355 - else if (!--cs->port.count)
43356 + else if (!atomic_dec_return(&cs->port.count))
43357 tty_port_tty_set(&cs->port, NULL);
43358
43359 mutex_unlock(&cs->mutex);
43360 diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
43361 index 8c91fd5..14f13ce 100644
43362 --- a/drivers/isdn/gigaset/ser-gigaset.c
43363 +++ b/drivers/isdn/gigaset/ser-gigaset.c
43364 @@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
43365 }
43366
43367 static const struct gigaset_ops ops = {
43368 - gigaset_write_cmd,
43369 - gigaset_write_room,
43370 - gigaset_chars_in_buffer,
43371 - gigaset_brkchars,
43372 - gigaset_init_bchannel,
43373 - gigaset_close_bchannel,
43374 - gigaset_initbcshw,
43375 - gigaset_freebcshw,
43376 - gigaset_reinitbcshw,
43377 - gigaset_initcshw,
43378 - gigaset_freecshw,
43379 - gigaset_set_modem_ctrl,
43380 - gigaset_baud_rate,
43381 - gigaset_set_line_ctrl,
43382 - gigaset_m10x_send_skb, /* asyncdata.c */
43383 - gigaset_m10x_input, /* asyncdata.c */
43384 + .write_cmd = gigaset_write_cmd,
43385 + .write_room = gigaset_write_room,
43386 + .chars_in_buffer = gigaset_chars_in_buffer,
43387 + .brkchars = gigaset_brkchars,
43388 + .init_bchannel = gigaset_init_bchannel,
43389 + .close_bchannel = gigaset_close_bchannel,
43390 + .initbcshw = gigaset_initbcshw,
43391 + .freebcshw = gigaset_freebcshw,
43392 + .reinitbcshw = gigaset_reinitbcshw,
43393 + .initcshw = gigaset_initcshw,
43394 + .freecshw = gigaset_freecshw,
43395 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43396 + .baud_rate = gigaset_baud_rate,
43397 + .set_line_ctrl = gigaset_set_line_ctrl,
43398 + .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
43399 + .handle_input = gigaset_m10x_input, /* asyncdata.c */
43400 };
43401
43402
43403 diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
43404 index d0a41cb..b953e50 100644
43405 --- a/drivers/isdn/gigaset/usb-gigaset.c
43406 +++ b/drivers/isdn/gigaset/usb-gigaset.c
43407 @@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
43408 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
43409 memcpy(cs->hw.usb->bchars, buf, 6);
43410 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
43411 - 0, 0, &buf, 6, 2000);
43412 + 0, 0, buf, 6, 2000);
43413 }
43414
43415 static void gigaset_freebcshw(struct bc_state *bcs)
43416 @@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
43417 }
43418
43419 static const struct gigaset_ops ops = {
43420 - gigaset_write_cmd,
43421 - gigaset_write_room,
43422 - gigaset_chars_in_buffer,
43423 - gigaset_brkchars,
43424 - gigaset_init_bchannel,
43425 - gigaset_close_bchannel,
43426 - gigaset_initbcshw,
43427 - gigaset_freebcshw,
43428 - gigaset_reinitbcshw,
43429 - gigaset_initcshw,
43430 - gigaset_freecshw,
43431 - gigaset_set_modem_ctrl,
43432 - gigaset_baud_rate,
43433 - gigaset_set_line_ctrl,
43434 - gigaset_m10x_send_skb,
43435 - gigaset_m10x_input,
43436 + .write_cmd = gigaset_write_cmd,
43437 + .write_room = gigaset_write_room,
43438 + .chars_in_buffer = gigaset_chars_in_buffer,
43439 + .brkchars = gigaset_brkchars,
43440 + .init_bchannel = gigaset_init_bchannel,
43441 + .close_bchannel = gigaset_close_bchannel,
43442 + .initbcshw = gigaset_initbcshw,
43443 + .freebcshw = gigaset_freebcshw,
43444 + .reinitbcshw = gigaset_reinitbcshw,
43445 + .initcshw = gigaset_initcshw,
43446 + .freecshw = gigaset_freecshw,
43447 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43448 + .baud_rate = gigaset_baud_rate,
43449 + .set_line_ctrl = gigaset_set_line_ctrl,
43450 + .send_skb = gigaset_m10x_send_skb,
43451 + .handle_input = gigaset_m10x_input,
43452 };
43453
43454 /*
43455 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
43456 index 4d9b195..455075c 100644
43457 --- a/drivers/isdn/hardware/avm/b1.c
43458 +++ b/drivers/isdn/hardware/avm/b1.c
43459 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
43460 }
43461 if (left) {
43462 if (t4file->user) {
43463 - if (copy_from_user(buf, dp, left))
43464 + if (left > sizeof buf || copy_from_user(buf, dp, left))
43465 return -EFAULT;
43466 } else {
43467 memcpy(buf, dp, left);
43468 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
43469 }
43470 if (left) {
43471 if (config->user) {
43472 - if (copy_from_user(buf, dp, left))
43473 + if (left > sizeof buf || copy_from_user(buf, dp, left))
43474 return -EFAULT;
43475 } else {
43476 memcpy(buf, dp, left);
43477 diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
43478 index 9b856e1..fa03c92 100644
43479 --- a/drivers/isdn/i4l/isdn_common.c
43480 +++ b/drivers/isdn/i4l/isdn_common.c
43481 @@ -1654,6 +1654,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
43482 } else
43483 return -EINVAL;
43484 case IIOCDBGVAR:
43485 + if (!capable(CAP_SYS_RAWIO))
43486 + return -EPERM;
43487 if (arg) {
43488 if (copy_to_user(argp, &dev, sizeof(ulong)))
43489 return -EFAULT;
43490 diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
43491 index 91d5730..336523e 100644
43492 --- a/drivers/isdn/i4l/isdn_concap.c
43493 +++ b/drivers/isdn/i4l/isdn_concap.c
43494 @@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
43495 }
43496
43497 struct concap_device_ops isdn_concap_reliable_dl_dops = {
43498 - &isdn_concap_dl_data_req,
43499 - &isdn_concap_dl_connect_req,
43500 - &isdn_concap_dl_disconn_req
43501 + .data_req = &isdn_concap_dl_data_req,
43502 + .connect_req = &isdn_concap_dl_connect_req,
43503 + .disconn_req = &isdn_concap_dl_disconn_req
43504 };
43505
43506 /* The following should better go into a dedicated source file such that
43507 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
43508 index 3c5f249..5fac4d0 100644
43509 --- a/drivers/isdn/i4l/isdn_tty.c
43510 +++ b/drivers/isdn/i4l/isdn_tty.c
43511 @@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
43512
43513 #ifdef ISDN_DEBUG_MODEM_OPEN
43514 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
43515 - port->count);
43516 + atomic_read(&port->count));
43517 #endif
43518 - port->count++;
43519 + atomic_inc(&port->count);
43520 port->tty = tty;
43521 /*
43522 * Start up serial port
43523 @@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43524 #endif
43525 return;
43526 }
43527 - if ((tty->count == 1) && (port->count != 1)) {
43528 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
43529 /*
43530 * Uh, oh. tty->count is 1, which means that the tty
43531 * structure will be freed. Info->count should always
43532 @@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43533 * serial port won't be shutdown.
43534 */
43535 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
43536 - "info->count is %d\n", port->count);
43537 - port->count = 1;
43538 + "info->count is %d\n", atomic_read(&port->count));
43539 + atomic_set(&port->count, 1);
43540 }
43541 - if (--port->count < 0) {
43542 + if (atomic_dec_return(&port->count) < 0) {
43543 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
43544 - info->line, port->count);
43545 - port->count = 0;
43546 + info->line, atomic_read(&port->count));
43547 + atomic_set(&port->count, 0);
43548 }
43549 - if (port->count) {
43550 + if (atomic_read(&port->count)) {
43551 #ifdef ISDN_DEBUG_MODEM_OPEN
43552 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
43553 #endif
43554 @@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
43555 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
43556 return;
43557 isdn_tty_shutdown(info);
43558 - port->count = 0;
43559 + atomic_set(&port->count, 0);
43560 port->flags &= ~ASYNC_NORMAL_ACTIVE;
43561 port->tty = NULL;
43562 wake_up_interruptible(&port->open_wait);
43563 @@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
43564 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
43565 modem_info *info = &dev->mdm.info[i];
43566
43567 - if (info->port.count == 0)
43568 + if (atomic_read(&info->port.count) == 0)
43569 continue;
43570 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
43571 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
43572 diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
43573 index e2d4e58..40cd045 100644
43574 --- a/drivers/isdn/i4l/isdn_x25iface.c
43575 +++ b/drivers/isdn/i4l/isdn_x25iface.c
43576 @@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
43577
43578
43579 static struct concap_proto_ops ix25_pops = {
43580 - &isdn_x25iface_proto_new,
43581 - &isdn_x25iface_proto_del,
43582 - &isdn_x25iface_proto_restart,
43583 - &isdn_x25iface_proto_close,
43584 - &isdn_x25iface_xmit,
43585 - &isdn_x25iface_receive,
43586 - &isdn_x25iface_connect_ind,
43587 - &isdn_x25iface_disconn_ind
43588 + .proto_new = &isdn_x25iface_proto_new,
43589 + .proto_del = &isdn_x25iface_proto_del,
43590 + .restart = &isdn_x25iface_proto_restart,
43591 + .close = &isdn_x25iface_proto_close,
43592 + .encap_and_xmit = &isdn_x25iface_xmit,
43593 + .data_ind = &isdn_x25iface_receive,
43594 + .connect_ind = &isdn_x25iface_connect_ind,
43595 + .disconn_ind = &isdn_x25iface_disconn_ind
43596 };
43597
43598 /* error message helper function */
43599 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
43600 index 6a7447c..cae33fe 100644
43601 --- a/drivers/isdn/icn/icn.c
43602 +++ b/drivers/isdn/icn/icn.c
43603 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
43604 if (count > len)
43605 count = len;
43606 if (user) {
43607 - if (copy_from_user(msg, buf, count))
43608 + if (count > sizeof msg || copy_from_user(msg, buf, count))
43609 return -EFAULT;
43610 } else
43611 memcpy(msg, buf, count);
43612 diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
43613 index a4f05c5..1433bc5 100644
43614 --- a/drivers/isdn/mISDN/dsp_cmx.c
43615 +++ b/drivers/isdn/mISDN/dsp_cmx.c
43616 @@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
43617 static u16 dsp_count; /* last sample count */
43618 static int dsp_count_valid; /* if we have last sample count */
43619
43620 -void
43621 +void __intentional_overflow(-1)
43622 dsp_cmx_send(void *arg)
43623 {
43624 struct dsp_conf *conf;
43625 diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
43626 index f58a354..fbae176 100644
43627 --- a/drivers/leds/leds-clevo-mail.c
43628 +++ b/drivers/leds/leds-clevo-mail.c
43629 @@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
43630 * detected as working, but in reality it is not) as low as
43631 * possible.
43632 */
43633 -static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
43634 +static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
43635 {
43636 .callback = clevo_mail_led_dmi_callback,
43637 .ident = "Clevo D410J",
43638 diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
43639 index 2eb3ef6..295891f 100644
43640 --- a/drivers/leds/leds-ss4200.c
43641 +++ b/drivers/leds/leds-ss4200.c
43642 @@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
43643 * detected as working, but in reality it is not) as low as
43644 * possible.
43645 */
43646 -static struct dmi_system_id nas_led_whitelist[] __initdata = {
43647 +static struct dmi_system_id nas_led_whitelist[] __initconst = {
43648 {
43649 .callback = ss4200_led_dmi_callback,
43650 .ident = "Intel SS4200-E",
43651 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
43652 index 0bf1e4e..b4bf44e 100644
43653 --- a/drivers/lguest/core.c
43654 +++ b/drivers/lguest/core.c
43655 @@ -97,9 +97,17 @@ static __init int map_switcher(void)
43656 * The end address needs +1 because __get_vm_area allocates an
43657 * extra guard page, so we need space for that.
43658 */
43659 +
43660 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
43661 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43662 + VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
43663 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43664 +#else
43665 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43666 VM_ALLOC, switcher_addr, switcher_addr
43667 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43668 +#endif
43669 +
43670 if (!switcher_vma) {
43671 err = -ENOMEM;
43672 printk("lguest: could not map switcher pages high\n");
43673 @@ -124,7 +132,7 @@ static __init int map_switcher(void)
43674 * Now the Switcher is mapped at the right address, we can't fail!
43675 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
43676 */
43677 - memcpy(switcher_vma->addr, start_switcher_text,
43678 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
43679 end_switcher_text - start_switcher_text);
43680
43681 printk(KERN_INFO "lguest: mapped switcher at %p\n",
43682 diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
43683 index e8b55c3..3514c37 100644
43684 --- a/drivers/lguest/page_tables.c
43685 +++ b/drivers/lguest/page_tables.c
43686 @@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
43687 /*:*/
43688
43689 #ifdef CONFIG_X86_PAE
43690 -static void release_pmd(pmd_t *spmd)
43691 +static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
43692 {
43693 /* If the entry's not present, there's nothing to release. */
43694 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
43695 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
43696 index 922a1ac..9dd0c2a 100644
43697 --- a/drivers/lguest/x86/core.c
43698 +++ b/drivers/lguest/x86/core.c
43699 @@ -59,7 +59,7 @@ static struct {
43700 /* Offset from where switcher.S was compiled to where we've copied it */
43701 static unsigned long switcher_offset(void)
43702 {
43703 - return switcher_addr - (unsigned long)start_switcher_text;
43704 + return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
43705 }
43706
43707 /* This cpu's struct lguest_pages (after the Switcher text page) */
43708 @@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
43709 * These copies are pretty cheap, so we do them unconditionally: */
43710 /* Save the current Host top-level page directory.
43711 */
43712 +
43713 +#ifdef CONFIG_PAX_PER_CPU_PGD
43714 + pages->state.host_cr3 = read_cr3();
43715 +#else
43716 pages->state.host_cr3 = __pa(current->mm->pgd);
43717 +#endif
43718 +
43719 /*
43720 * Set up the Guest's page tables to see this CPU's pages (and no
43721 * other CPU's pages).
43722 @@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
43723 * compiled-in switcher code and the high-mapped copy we just made.
43724 */
43725 for (i = 0; i < IDT_ENTRIES; i++)
43726 - default_idt_entries[i] += switcher_offset();
43727 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
43728
43729 /*
43730 * Set up the Switcher's per-cpu areas.
43731 @@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
43732 * it will be undisturbed when we switch. To change %cs and jump we
43733 * need this structure to feed to Intel's "lcall" instruction.
43734 */
43735 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
43736 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
43737 lguest_entry.segment = LGUEST_CS;
43738
43739 /*
43740 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
43741 index 40634b0..4f5855e 100644
43742 --- a/drivers/lguest/x86/switcher_32.S
43743 +++ b/drivers/lguest/x86/switcher_32.S
43744 @@ -87,6 +87,7 @@
43745 #include <asm/page.h>
43746 #include <asm/segment.h>
43747 #include <asm/lguest.h>
43748 +#include <asm/processor-flags.h>
43749
43750 // We mark the start of the code to copy
43751 // It's placed in .text tho it's never run here
43752 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
43753 // Changes type when we load it: damn Intel!
43754 // For after we switch over our page tables
43755 // That entry will be read-only: we'd crash.
43756 +
43757 +#ifdef CONFIG_PAX_KERNEXEC
43758 + mov %cr0, %edx
43759 + xor $X86_CR0_WP, %edx
43760 + mov %edx, %cr0
43761 +#endif
43762 +
43763 movl $(GDT_ENTRY_TSS*8), %edx
43764 ltr %dx
43765
43766 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
43767 // Let's clear it again for our return.
43768 // The GDT descriptor of the Host
43769 // Points to the table after two "size" bytes
43770 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
43771 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
43772 // Clear "used" from type field (byte 5, bit 2)
43773 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
43774 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
43775 +
43776 +#ifdef CONFIG_PAX_KERNEXEC
43777 + mov %cr0, %eax
43778 + xor $X86_CR0_WP, %eax
43779 + mov %eax, %cr0
43780 +#endif
43781
43782 // Once our page table's switched, the Guest is live!
43783 // The Host fades as we run this final step.
43784 @@ -295,13 +309,12 @@ deliver_to_host:
43785 // I consulted gcc, and it gave
43786 // These instructions, which I gladly credit:
43787 leal (%edx,%ebx,8), %eax
43788 - movzwl (%eax),%edx
43789 - movl 4(%eax), %eax
43790 - xorw %ax, %ax
43791 - orl %eax, %edx
43792 + movl 4(%eax), %edx
43793 + movw (%eax), %dx
43794 // Now the address of the handler's in %edx
43795 // We call it now: its "iret" drops us home.
43796 - jmp *%edx
43797 + ljmp $__KERNEL_CS, $1f
43798 +1: jmp *%edx
43799
43800 // Every interrupt can come to us here
43801 // But we must truly tell each apart.
43802 diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
43803 index 7ef7461..5a09dac 100644
43804 --- a/drivers/md/bcache/closure.h
43805 +++ b/drivers/md/bcache/closure.h
43806 @@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
43807 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
43808 struct workqueue_struct *wq)
43809 {
43810 - BUG_ON(object_is_on_stack(cl));
43811 + BUG_ON(object_starts_on_stack(cl));
43812 closure_set_ip(cl);
43813 cl->fn = fn;
43814 cl->wq = wq;
43815 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
43816 index 9a8e66a..10cc762 100644
43817 --- a/drivers/md/bitmap.c
43818 +++ b/drivers/md/bitmap.c
43819 @@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
43820 chunk_kb ? "KB" : "B");
43821 if (bitmap->storage.file) {
43822 seq_printf(seq, ", file: ");
43823 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
43824 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
43825 }
43826
43827 seq_printf(seq, "\n");
43828 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
43829 index 5152142..623d141 100644
43830 --- a/drivers/md/dm-ioctl.c
43831 +++ b/drivers/md/dm-ioctl.c
43832 @@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
43833 cmd == DM_LIST_VERSIONS_CMD)
43834 return 0;
43835
43836 - if ((cmd == DM_DEV_CREATE_CMD)) {
43837 + if (cmd == DM_DEV_CREATE_CMD) {
43838 if (!*param->name) {
43839 DMWARN("name not supplied when creating device");
43840 return -EINVAL;
43841 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
43842 index 7dfdb5c..4caada6 100644
43843 --- a/drivers/md/dm-raid1.c
43844 +++ b/drivers/md/dm-raid1.c
43845 @@ -40,7 +40,7 @@ enum dm_raid1_error {
43846
43847 struct mirror {
43848 struct mirror_set *ms;
43849 - atomic_t error_count;
43850 + atomic_unchecked_t error_count;
43851 unsigned long error_type;
43852 struct dm_dev *dev;
43853 sector_t offset;
43854 @@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
43855 struct mirror *m;
43856
43857 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
43858 - if (!atomic_read(&m->error_count))
43859 + if (!atomic_read_unchecked(&m->error_count))
43860 return m;
43861
43862 return NULL;
43863 @@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
43864 * simple way to tell if a device has encountered
43865 * errors.
43866 */
43867 - atomic_inc(&m->error_count);
43868 + atomic_inc_unchecked(&m->error_count);
43869
43870 if (test_and_set_bit(error_type, &m->error_type))
43871 return;
43872 @@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
43873 struct mirror *m = get_default_mirror(ms);
43874
43875 do {
43876 - if (likely(!atomic_read(&m->error_count)))
43877 + if (likely(!atomic_read_unchecked(&m->error_count)))
43878 return m;
43879
43880 if (m-- == ms->mirror)
43881 @@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
43882 {
43883 struct mirror *default_mirror = get_default_mirror(m->ms);
43884
43885 - return !atomic_read(&default_mirror->error_count);
43886 + return !atomic_read_unchecked(&default_mirror->error_count);
43887 }
43888
43889 static int mirror_available(struct mirror_set *ms, struct bio *bio)
43890 @@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
43891 */
43892 if (likely(region_in_sync(ms, region, 1)))
43893 m = choose_mirror(ms, bio->bi_iter.bi_sector);
43894 - else if (m && atomic_read(&m->error_count))
43895 + else if (m && atomic_read_unchecked(&m->error_count))
43896 m = NULL;
43897
43898 if (likely(m))
43899 @@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
43900 }
43901
43902 ms->mirror[mirror].ms = ms;
43903 - atomic_set(&(ms->mirror[mirror].error_count), 0);
43904 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
43905 ms->mirror[mirror].error_type = 0;
43906 ms->mirror[mirror].offset = offset;
43907
43908 @@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
43909 */
43910 static char device_status_char(struct mirror *m)
43911 {
43912 - if (!atomic_read(&(m->error_count)))
43913 + if (!atomic_read_unchecked(&(m->error_count)))
43914 return 'A';
43915
43916 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
43917 diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
43918 index 28a9012..9c0f6a5 100644
43919 --- a/drivers/md/dm-stats.c
43920 +++ b/drivers/md/dm-stats.c
43921 @@ -382,7 +382,7 @@ do_sync_free:
43922 synchronize_rcu_expedited();
43923 dm_stat_free(&s->rcu_head);
43924 } else {
43925 - ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
43926 + ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
43927 call_rcu(&s->rcu_head, dm_stat_free);
43928 }
43929 return 0;
43930 @@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
43931 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
43932 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
43933 ));
43934 - ACCESS_ONCE(last->last_sector) = end_sector;
43935 - ACCESS_ONCE(last->last_rw) = bi_rw;
43936 + ACCESS_ONCE_RW(last->last_sector) = end_sector;
43937 + ACCESS_ONCE_RW(last->last_rw) = bi_rw;
43938 }
43939
43940 rcu_read_lock();
43941 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
43942 index d1600d2..4c3af3a 100644
43943 --- a/drivers/md/dm-stripe.c
43944 +++ b/drivers/md/dm-stripe.c
43945 @@ -21,7 +21,7 @@ struct stripe {
43946 struct dm_dev *dev;
43947 sector_t physical_start;
43948
43949 - atomic_t error_count;
43950 + atomic_unchecked_t error_count;
43951 };
43952
43953 struct stripe_c {
43954 @@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
43955 kfree(sc);
43956 return r;
43957 }
43958 - atomic_set(&(sc->stripe[i].error_count), 0);
43959 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
43960 }
43961
43962 ti->private = sc;
43963 @@ -330,7 +330,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
43964 DMEMIT("%d ", sc->stripes);
43965 for (i = 0; i < sc->stripes; i++) {
43966 DMEMIT("%s ", sc->stripe[i].dev->name);
43967 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
43968 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
43969 'D' : 'A';
43970 }
43971 buffer[i] = '\0';
43972 @@ -375,8 +375,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
43973 */
43974 for (i = 0; i < sc->stripes; i++)
43975 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
43976 - atomic_inc(&(sc->stripe[i].error_count));
43977 - if (atomic_read(&(sc->stripe[i].error_count)) <
43978 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
43979 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
43980 DM_IO_ERROR_THRESHOLD)
43981 schedule_work(&sc->trigger_event);
43982 }
43983 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
43984 index 50601ec..6d3b9dc 100644
43985 --- a/drivers/md/dm-table.c
43986 +++ b/drivers/md/dm-table.c
43987 @@ -274,7 +274,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
43988 static int open_dev(struct dm_dev_internal *d, dev_t dev,
43989 struct mapped_device *md)
43990 {
43991 - static char *_claim_ptr = "I belong to device-mapper";
43992 + static char _claim_ptr[] = "I belong to device-mapper";
43993 struct block_device *bdev;
43994
43995 int r;
43996 @@ -342,7 +342,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
43997 if (!dev_size)
43998 return 0;
43999
44000 - if ((start >= dev_size) || (start + len > dev_size)) {
44001 + if ((start >= dev_size) || (len > dev_size - start)) {
44002 DMWARN("%s: %s too small for target: "
44003 "start=%llu, len=%llu, dev_size=%llu",
44004 dm_device_name(ti->table->md), bdevname(bdev, b),
44005 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
44006 index e9d33ad..dae9880d 100644
44007 --- a/drivers/md/dm-thin-metadata.c
44008 +++ b/drivers/md/dm-thin-metadata.c
44009 @@ -404,7 +404,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44010 {
44011 pmd->info.tm = pmd->tm;
44012 pmd->info.levels = 2;
44013 - pmd->info.value_type.context = pmd->data_sm;
44014 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44015 pmd->info.value_type.size = sizeof(__le64);
44016 pmd->info.value_type.inc = data_block_inc;
44017 pmd->info.value_type.dec = data_block_dec;
44018 @@ -423,7 +423,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44019
44020 pmd->bl_info.tm = pmd->tm;
44021 pmd->bl_info.levels = 1;
44022 - pmd->bl_info.value_type.context = pmd->data_sm;
44023 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44024 pmd->bl_info.value_type.size = sizeof(__le64);
44025 pmd->bl_info.value_type.inc = data_block_inc;
44026 pmd->bl_info.value_type.dec = data_block_dec;
44027 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
44028 index 490ac23..b9790cd 100644
44029 --- a/drivers/md/dm.c
44030 +++ b/drivers/md/dm.c
44031 @@ -180,9 +180,9 @@ struct mapped_device {
44032 /*
44033 * Event handling.
44034 */
44035 - atomic_t event_nr;
44036 + atomic_unchecked_t event_nr;
44037 wait_queue_head_t eventq;
44038 - atomic_t uevent_seq;
44039 + atomic_unchecked_t uevent_seq;
44040 struct list_head uevent_list;
44041 spinlock_t uevent_lock; /* Protect access to uevent_list */
44042
44043 @@ -1895,8 +1895,8 @@ static struct mapped_device *alloc_dev(int minor)
44044 spin_lock_init(&md->deferred_lock);
44045 atomic_set(&md->holders, 1);
44046 atomic_set(&md->open_count, 0);
44047 - atomic_set(&md->event_nr, 0);
44048 - atomic_set(&md->uevent_seq, 0);
44049 + atomic_set_unchecked(&md->event_nr, 0);
44050 + atomic_set_unchecked(&md->uevent_seq, 0);
44051 INIT_LIST_HEAD(&md->uevent_list);
44052 spin_lock_init(&md->uevent_lock);
44053
44054 @@ -2050,7 +2050,7 @@ static void event_callback(void *context)
44055
44056 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
44057
44058 - atomic_inc(&md->event_nr);
44059 + atomic_inc_unchecked(&md->event_nr);
44060 wake_up(&md->eventq);
44061 }
44062
44063 @@ -2743,18 +2743,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
44064
44065 uint32_t dm_next_uevent_seq(struct mapped_device *md)
44066 {
44067 - return atomic_add_return(1, &md->uevent_seq);
44068 + return atomic_add_return_unchecked(1, &md->uevent_seq);
44069 }
44070
44071 uint32_t dm_get_event_nr(struct mapped_device *md)
44072 {
44073 - return atomic_read(&md->event_nr);
44074 + return atomic_read_unchecked(&md->event_nr);
44075 }
44076
44077 int dm_wait_event(struct mapped_device *md, int event_nr)
44078 {
44079 return wait_event_interruptible(md->eventq,
44080 - (event_nr != atomic_read(&md->event_nr)));
44081 + (event_nr != atomic_read_unchecked(&md->event_nr)));
44082 }
44083
44084 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
44085 diff --git a/drivers/md/md.c b/drivers/md/md.c
44086 index 9a18209..ec4d3ec 100644
44087 --- a/drivers/md/md.c
44088 +++ b/drivers/md/md.c
44089 @@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
44090 * start build, activate spare
44091 */
44092 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
44093 -static atomic_t md_event_count;
44094 +static atomic_unchecked_t md_event_count;
44095 void md_new_event(struct mddev *mddev)
44096 {
44097 - atomic_inc(&md_event_count);
44098 + atomic_inc_unchecked(&md_event_count);
44099 wake_up(&md_event_waiters);
44100 }
44101 EXPORT_SYMBOL_GPL(md_new_event);
44102 @@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
44103 */
44104 static void md_new_event_inintr(struct mddev *mddev)
44105 {
44106 - atomic_inc(&md_event_count);
44107 + atomic_inc_unchecked(&md_event_count);
44108 wake_up(&md_event_waiters);
44109 }
44110
44111 @@ -1462,7 +1462,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
44112 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
44113 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
44114 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
44115 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44116 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44117
44118 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
44119 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
44120 @@ -1713,7 +1713,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
44121 else
44122 sb->resync_offset = cpu_to_le64(0);
44123
44124 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
44125 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
44126
44127 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
44128 sb->size = cpu_to_le64(mddev->dev_sectors);
44129 @@ -2725,7 +2725,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
44130 static ssize_t
44131 errors_show(struct md_rdev *rdev, char *page)
44132 {
44133 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
44134 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
44135 }
44136
44137 static ssize_t
44138 @@ -2734,7 +2734,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
44139 char *e;
44140 unsigned long n = simple_strtoul(buf, &e, 10);
44141 if (*buf && (*e == 0 || *e == '\n')) {
44142 - atomic_set(&rdev->corrected_errors, n);
44143 + atomic_set_unchecked(&rdev->corrected_errors, n);
44144 return len;
44145 }
44146 return -EINVAL;
44147 @@ -3183,8 +3183,8 @@ int md_rdev_init(struct md_rdev *rdev)
44148 rdev->sb_loaded = 0;
44149 rdev->bb_page = NULL;
44150 atomic_set(&rdev->nr_pending, 0);
44151 - atomic_set(&rdev->read_errors, 0);
44152 - atomic_set(&rdev->corrected_errors, 0);
44153 + atomic_set_unchecked(&rdev->read_errors, 0);
44154 + atomic_set_unchecked(&rdev->corrected_errors, 0);
44155
44156 INIT_LIST_HEAD(&rdev->same_set);
44157 init_waitqueue_head(&rdev->blocked_wait);
44158 @@ -7058,7 +7058,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
44159
44160 spin_unlock(&pers_lock);
44161 seq_printf(seq, "\n");
44162 - seq->poll_event = atomic_read(&md_event_count);
44163 + seq->poll_event = atomic_read_unchecked(&md_event_count);
44164 return 0;
44165 }
44166 if (v == (void*)2) {
44167 @@ -7161,7 +7161,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
44168 return error;
44169
44170 seq = file->private_data;
44171 - seq->poll_event = atomic_read(&md_event_count);
44172 + seq->poll_event = atomic_read_unchecked(&md_event_count);
44173 return error;
44174 }
44175
44176 @@ -7178,7 +7178,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
44177 /* always allow read */
44178 mask = POLLIN | POLLRDNORM;
44179
44180 - if (seq->poll_event != atomic_read(&md_event_count))
44181 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
44182 mask |= POLLERR | POLLPRI;
44183 return mask;
44184 }
44185 @@ -7222,7 +7222,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
44186 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
44187 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
44188 (int)part_stat_read(&disk->part0, sectors[1]) -
44189 - atomic_read(&disk->sync_io);
44190 + atomic_read_unchecked(&disk->sync_io);
44191 /* sync IO will cause sync_io to increase before the disk_stats
44192 * as sync_io is counted when a request starts, and
44193 * disk_stats is counted when it completes.
44194 diff --git a/drivers/md/md.h b/drivers/md/md.h
44195 index a49d991..3582bb7 100644
44196 --- a/drivers/md/md.h
44197 +++ b/drivers/md/md.h
44198 @@ -94,13 +94,13 @@ struct md_rdev {
44199 * only maintained for arrays that
44200 * support hot removal
44201 */
44202 - atomic_t read_errors; /* number of consecutive read errors that
44203 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
44204 * we have tried to ignore.
44205 */
44206 struct timespec last_read_error; /* monotonic time since our
44207 * last read error
44208 */
44209 - atomic_t corrected_errors; /* number of corrected read errors,
44210 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
44211 * for reporting to userspace and storing
44212 * in superblock.
44213 */
44214 @@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
44215
44216 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
44217 {
44218 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44219 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44220 }
44221
44222 struct md_personality
44223 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
44224 index 786b689..ea8c956 100644
44225 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
44226 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
44227 @@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
44228 * Flick into a mode where all blocks get allocated in the new area.
44229 */
44230 smm->begin = old_len;
44231 - memcpy(sm, &bootstrap_ops, sizeof(*sm));
44232 + memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
44233
44234 /*
44235 * Extend.
44236 @@ -710,7 +710,7 @@ out:
44237 /*
44238 * Switch back to normal behaviour.
44239 */
44240 - memcpy(sm, &ops, sizeof(*sm));
44241 + memcpy((void *)sm, &ops, sizeof(*sm));
44242 return r;
44243 }
44244
44245 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
44246 index 3e6d115..ffecdeb 100644
44247 --- a/drivers/md/persistent-data/dm-space-map.h
44248 +++ b/drivers/md/persistent-data/dm-space-map.h
44249 @@ -71,6 +71,7 @@ struct dm_space_map {
44250 dm_sm_threshold_fn fn,
44251 void *context);
44252 };
44253 +typedef struct dm_space_map __no_const dm_space_map_no_const;
44254
44255 /*----------------------------------------------------------------*/
44256
44257 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
44258 index 56e24c0..e1c8e1f 100644
44259 --- a/drivers/md/raid1.c
44260 +++ b/drivers/md/raid1.c
44261 @@ -1931,7 +1931,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
44262 if (r1_sync_page_io(rdev, sect, s,
44263 bio->bi_io_vec[idx].bv_page,
44264 READ) != 0)
44265 - atomic_add(s, &rdev->corrected_errors);
44266 + atomic_add_unchecked(s, &rdev->corrected_errors);
44267 }
44268 sectors -= s;
44269 sect += s;
44270 @@ -2165,7 +2165,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
44271 test_bit(In_sync, &rdev->flags)) {
44272 if (r1_sync_page_io(rdev, sect, s,
44273 conf->tmppage, READ)) {
44274 - atomic_add(s, &rdev->corrected_errors);
44275 + atomic_add_unchecked(s, &rdev->corrected_errors);
44276 printk(KERN_INFO
44277 "md/raid1:%s: read error corrected "
44278 "(%d sectors at %llu on %s)\n",
44279 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
44280 index cb882aa..cb8aeca 100644
44281 --- a/drivers/md/raid10.c
44282 +++ b/drivers/md/raid10.c
44283 @@ -1949,7 +1949,7 @@ static void end_sync_read(struct bio *bio, int error)
44284 /* The write handler will notice the lack of
44285 * R10BIO_Uptodate and record any errors etc
44286 */
44287 - atomic_add(r10_bio->sectors,
44288 + atomic_add_unchecked(r10_bio->sectors,
44289 &conf->mirrors[d].rdev->corrected_errors);
44290
44291 /* for reconstruct, we always reschedule after a read.
44292 @@ -2307,7 +2307,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44293 {
44294 struct timespec cur_time_mon;
44295 unsigned long hours_since_last;
44296 - unsigned int read_errors = atomic_read(&rdev->read_errors);
44297 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
44298
44299 ktime_get_ts(&cur_time_mon);
44300
44301 @@ -2329,9 +2329,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44302 * overflowing the shift of read_errors by hours_since_last.
44303 */
44304 if (hours_since_last >= 8 * sizeof(read_errors))
44305 - atomic_set(&rdev->read_errors, 0);
44306 + atomic_set_unchecked(&rdev->read_errors, 0);
44307 else
44308 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
44309 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
44310 }
44311
44312 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
44313 @@ -2385,8 +2385,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44314 return;
44315
44316 check_decay_read_errors(mddev, rdev);
44317 - atomic_inc(&rdev->read_errors);
44318 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
44319 + atomic_inc_unchecked(&rdev->read_errors);
44320 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
44321 char b[BDEVNAME_SIZE];
44322 bdevname(rdev->bdev, b);
44323
44324 @@ -2394,7 +2394,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44325 "md/raid10:%s: %s: Raid device exceeded "
44326 "read_error threshold [cur %d:max %d]\n",
44327 mdname(mddev), b,
44328 - atomic_read(&rdev->read_errors), max_read_errors);
44329 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
44330 printk(KERN_NOTICE
44331 "md/raid10:%s: %s: Failing raid device\n",
44332 mdname(mddev), b);
44333 @@ -2549,7 +2549,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44334 sect +
44335 choose_data_offset(r10_bio, rdev)),
44336 bdevname(rdev->bdev, b));
44337 - atomic_add(s, &rdev->corrected_errors);
44338 + atomic_add_unchecked(s, &rdev->corrected_errors);
44339 }
44340
44341 rdev_dec_pending(rdev, mddev);
44342 @@ -2954,6 +2954,7 @@ static sector_t sync_request(struct mddev *mddev, sector_t sector_nr,
44343 */
44344 if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) {
44345 end_reshape(conf);
44346 + close_sync(conf);
44347 return 0;
44348 }
44349
44350 @@ -4411,7 +4412,7 @@ read_more:
44351 read_bio->bi_private = r10_bio;
44352 read_bio->bi_end_io = end_sync_read;
44353 read_bio->bi_rw = READ;
44354 - read_bio->bi_flags &= ~(BIO_POOL_MASK - 1);
44355 + read_bio->bi_flags &= (~0UL << BIO_RESET_BITS);
44356 read_bio->bi_flags |= 1 << BIO_UPTODATE;
44357 read_bio->bi_vcnt = 0;
44358 read_bio->bi_iter.bi_size = 0;
44359 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
44360 index ad1b9be..c6316b5 100644
44361 --- a/drivers/md/raid5.c
44362 +++ b/drivers/md/raid5.c
44363 @@ -1702,6 +1702,10 @@ static int grow_one_stripe(struct r5conf *conf, int hash)
44364 return 1;
44365 }
44366
44367 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44368 +static atomic_unchecked_t raid5_cache_id = ATOMIC_INIT(0);
44369 +#endif
44370 +
44371 static int grow_stripes(struct r5conf *conf, int num)
44372 {
44373 struct kmem_cache *sc;
44374 @@ -1713,7 +1717,11 @@ static int grow_stripes(struct r5conf *conf, int num)
44375 "raid%d-%s", conf->level, mdname(conf->mddev));
44376 else
44377 sprintf(conf->cache_name[0],
44378 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44379 + "raid%d-%08lx", conf->level, atomic_inc_return_unchecked(&raid5_cache_id));
44380 +#else
44381 "raid%d-%p", conf->level, conf->mddev);
44382 +#endif
44383 sprintf(conf->cache_name[1], "%s-alt", conf->cache_name[0]);
44384
44385 conf->active_name = 0;
44386 @@ -1986,21 +1994,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
44387 mdname(conf->mddev), STRIPE_SECTORS,
44388 (unsigned long long)s,
44389 bdevname(rdev->bdev, b));
44390 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
44391 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
44392 clear_bit(R5_ReadError, &sh->dev[i].flags);
44393 clear_bit(R5_ReWrite, &sh->dev[i].flags);
44394 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
44395 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
44396
44397 - if (atomic_read(&rdev->read_errors))
44398 - atomic_set(&rdev->read_errors, 0);
44399 + if (atomic_read_unchecked(&rdev->read_errors))
44400 + atomic_set_unchecked(&rdev->read_errors, 0);
44401 } else {
44402 const char *bdn = bdevname(rdev->bdev, b);
44403 int retry = 0;
44404 int set_bad = 0;
44405
44406 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
44407 - atomic_inc(&rdev->read_errors);
44408 + atomic_inc_unchecked(&rdev->read_errors);
44409 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
44410 printk_ratelimited(
44411 KERN_WARNING
44412 @@ -2028,7 +2036,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
44413 mdname(conf->mddev),
44414 (unsigned long long)s,
44415 bdn);
44416 - } else if (atomic_read(&rdev->read_errors)
44417 + } else if (atomic_read_unchecked(&rdev->read_errors)
44418 > conf->max_nr_stripes)
44419 printk(KERN_WARNING
44420 "md/raid:%s: Too many read errors, failing device %s.\n",
44421 @@ -3774,6 +3782,8 @@ static void handle_stripe(struct stripe_head *sh)
44422 set_bit(R5_Wantwrite, &dev->flags);
44423 if (prexor)
44424 continue;
44425 + if (s.failed > 1)
44426 + continue;
44427 if (!test_bit(R5_Insync, &dev->flags) ||
44428 ((i == sh->pd_idx || i == sh->qd_idx) &&
44429 s.failed == 0))
44430 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
44431 index 983db75..ef9248c 100644
44432 --- a/drivers/media/dvb-core/dvbdev.c
44433 +++ b/drivers/media/dvb-core/dvbdev.c
44434 @@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
44435 const struct dvb_device *template, void *priv, int type)
44436 {
44437 struct dvb_device *dvbdev;
44438 - struct file_operations *dvbdevfops;
44439 + file_operations_no_const *dvbdevfops;
44440 struct device *clsdev;
44441 int minor;
44442 int id;
44443 diff --git a/drivers/media/dvb-frontends/af9033.h b/drivers/media/dvb-frontends/af9033.h
44444 index 539f4db..cdd403b 100644
44445 --- a/drivers/media/dvb-frontends/af9033.h
44446 +++ b/drivers/media/dvb-frontends/af9033.h
44447 @@ -82,7 +82,7 @@ struct af9033_ops {
44448 int (*pid_filter_ctrl)(struct dvb_frontend *fe, int onoff);
44449 int (*pid_filter)(struct dvb_frontend *fe, int index, u16 pid,
44450 int onoff);
44451 -};
44452 +} __no_const;
44453
44454
44455 #if IS_ENABLED(CONFIG_DVB_AF9033)
44456 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
44457 index 9b6c3bb..baeb5c7 100644
44458 --- a/drivers/media/dvb-frontends/dib3000.h
44459 +++ b/drivers/media/dvb-frontends/dib3000.h
44460 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
44461 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
44462 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
44463 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
44464 -};
44465 +} __no_const;
44466
44467 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
44468 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
44469 diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
44470 index ed8cb90..5ef7f79 100644
44471 --- a/drivers/media/pci/cx88/cx88-video.c
44472 +++ b/drivers/media/pci/cx88/cx88-video.c
44473 @@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
44474
44475 /* ------------------------------------------------------------------ */
44476
44477 -static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44478 -static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44479 -static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44480 +static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44481 +static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44482 +static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44483
44484 module_param_array(video_nr, int, NULL, 0444);
44485 module_param_array(vbi_nr, int, NULL, 0444);
44486 diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
44487 index 802642d..5534900 100644
44488 --- a/drivers/media/pci/ivtv/ivtv-driver.c
44489 +++ b/drivers/media/pci/ivtv/ivtv-driver.c
44490 @@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
44491 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
44492
44493 /* ivtv instance counter */
44494 -static atomic_t ivtv_instance = ATOMIC_INIT(0);
44495 +static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
44496
44497 /* Parameter declarations */
44498 static int cardtype[IVTV_MAX_CARDS];
44499 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
44500 index 9a726ea..f5e9b52 100644
44501 --- a/drivers/media/platform/omap/omap_vout.c
44502 +++ b/drivers/media/platform/omap/omap_vout.c
44503 @@ -63,7 +63,6 @@ enum omap_vout_channels {
44504 OMAP_VIDEO2,
44505 };
44506
44507 -static struct videobuf_queue_ops video_vbq_ops;
44508 /* Variables configurable through module params*/
44509 static u32 video1_numbuffers = 3;
44510 static u32 video2_numbuffers = 3;
44511 @@ -1015,6 +1014,12 @@ static int omap_vout_open(struct file *file)
44512 {
44513 struct videobuf_queue *q;
44514 struct omap_vout_device *vout = NULL;
44515 + static struct videobuf_queue_ops video_vbq_ops = {
44516 + .buf_setup = omap_vout_buffer_setup,
44517 + .buf_prepare = omap_vout_buffer_prepare,
44518 + .buf_release = omap_vout_buffer_release,
44519 + .buf_queue = omap_vout_buffer_queue,
44520 + };
44521
44522 vout = video_drvdata(file);
44523 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
44524 @@ -1032,10 +1037,6 @@ static int omap_vout_open(struct file *file)
44525 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
44526
44527 q = &vout->vbq;
44528 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
44529 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
44530 - video_vbq_ops.buf_release = omap_vout_buffer_release;
44531 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
44532 spin_lock_init(&vout->vbq_lock);
44533
44534 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
44535 diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
44536 index fb2acc5..a2fcbdc4 100644
44537 --- a/drivers/media/platform/s5p-tv/mixer.h
44538 +++ b/drivers/media/platform/s5p-tv/mixer.h
44539 @@ -156,7 +156,7 @@ struct mxr_layer {
44540 /** layer index (unique identifier) */
44541 int idx;
44542 /** callbacks for layer methods */
44543 - struct mxr_layer_ops ops;
44544 + struct mxr_layer_ops *ops;
44545 /** format array */
44546 const struct mxr_format **fmt_array;
44547 /** size of format array */
44548 diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44549 index 74344c7..a39e70e 100644
44550 --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44551 +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44552 @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
44553 {
44554 struct mxr_layer *layer;
44555 int ret;
44556 - struct mxr_layer_ops ops = {
44557 + static struct mxr_layer_ops ops = {
44558 .release = mxr_graph_layer_release,
44559 .buffer_set = mxr_graph_buffer_set,
44560 .stream_set = mxr_graph_stream_set,
44561 diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
44562 index b713403..53cb5ad 100644
44563 --- a/drivers/media/platform/s5p-tv/mixer_reg.c
44564 +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
44565 @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
44566 layer->update_buf = next;
44567 }
44568
44569 - layer->ops.buffer_set(layer, layer->update_buf);
44570 + layer->ops->buffer_set(layer, layer->update_buf);
44571
44572 if (done && done != layer->shadow_buf)
44573 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
44574 diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
44575 index a1ce55f..4a3c4d9 100644
44576 --- a/drivers/media/platform/s5p-tv/mixer_video.c
44577 +++ b/drivers/media/platform/s5p-tv/mixer_video.c
44578 @@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
44579 layer->geo.src.height = layer->geo.src.full_height;
44580
44581 mxr_geometry_dump(mdev, &layer->geo);
44582 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44583 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44584 mxr_geometry_dump(mdev, &layer->geo);
44585 }
44586
44587 @@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
44588 layer->geo.dst.full_width = mbus_fmt.width;
44589 layer->geo.dst.full_height = mbus_fmt.height;
44590 layer->geo.dst.field = mbus_fmt.field;
44591 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44592 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44593
44594 mxr_geometry_dump(mdev, &layer->geo);
44595 }
44596 @@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
44597 /* set source size to highest accepted value */
44598 geo->src.full_width = max(geo->dst.full_width, pix->width);
44599 geo->src.full_height = max(geo->dst.full_height, pix->height);
44600 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44601 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44602 mxr_geometry_dump(mdev, &layer->geo);
44603 /* set cropping to total visible screen */
44604 geo->src.width = pix->width;
44605 @@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
44606 geo->src.x_offset = 0;
44607 geo->src.y_offset = 0;
44608 /* assure consistency of geometry */
44609 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44610 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44611 mxr_geometry_dump(mdev, &layer->geo);
44612 /* set full size to lowest possible value */
44613 geo->src.full_width = 0;
44614 geo->src.full_height = 0;
44615 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44616 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44617 mxr_geometry_dump(mdev, &layer->geo);
44618
44619 /* returning results */
44620 @@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
44621 target->width = s->r.width;
44622 target->height = s->r.height;
44623
44624 - layer->ops.fix_geometry(layer, stage, s->flags);
44625 + layer->ops->fix_geometry(layer, stage, s->flags);
44626
44627 /* retrieve update selection rectangle */
44628 res.left = target->x_offset;
44629 @@ -950,13 +950,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
44630 mxr_output_get(mdev);
44631
44632 mxr_layer_update_output(layer);
44633 - layer->ops.format_set(layer);
44634 + layer->ops->format_set(layer);
44635 /* enabling layer in hardware */
44636 spin_lock_irqsave(&layer->enq_slock, flags);
44637 layer->state = MXR_LAYER_STREAMING;
44638 spin_unlock_irqrestore(&layer->enq_slock, flags);
44639
44640 - layer->ops.stream_set(layer, MXR_ENABLE);
44641 + layer->ops->stream_set(layer, MXR_ENABLE);
44642 mxr_streamer_get(mdev);
44643
44644 return 0;
44645 @@ -1026,7 +1026,7 @@ static int stop_streaming(struct vb2_queue *vq)
44646 spin_unlock_irqrestore(&layer->enq_slock, flags);
44647
44648 /* disabling layer in hardware */
44649 - layer->ops.stream_set(layer, MXR_DISABLE);
44650 + layer->ops->stream_set(layer, MXR_DISABLE);
44651 /* remove one streamer */
44652 mxr_streamer_put(mdev);
44653 /* allow changes in output configuration */
44654 @@ -1065,8 +1065,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
44655
44656 void mxr_layer_release(struct mxr_layer *layer)
44657 {
44658 - if (layer->ops.release)
44659 - layer->ops.release(layer);
44660 + if (layer->ops->release)
44661 + layer->ops->release(layer);
44662 }
44663
44664 void mxr_base_layer_release(struct mxr_layer *layer)
44665 @@ -1092,7 +1092,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
44666
44667 layer->mdev = mdev;
44668 layer->idx = idx;
44669 - layer->ops = *ops;
44670 + layer->ops = ops;
44671
44672 spin_lock_init(&layer->enq_slock);
44673 INIT_LIST_HEAD(&layer->enq_list);
44674 diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44675 index c9388c4..ce71ece 100644
44676 --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44677 +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44678 @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
44679 {
44680 struct mxr_layer *layer;
44681 int ret;
44682 - struct mxr_layer_ops ops = {
44683 + static struct mxr_layer_ops ops = {
44684 .release = mxr_vp_layer_release,
44685 .buffer_set = mxr_vp_buffer_set,
44686 .stream_set = mxr_vp_stream_set,
44687 diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
44688 index 3890f4f..b5c7511 100644
44689 --- a/drivers/media/platform/vivi.c
44690 +++ b/drivers/media/platform/vivi.c
44691 @@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
44692 MODULE_LICENSE("Dual BSD/GPL");
44693 MODULE_VERSION(VIVI_VERSION);
44694
44695 -static unsigned video_nr = -1;
44696 -module_param(video_nr, uint, 0644);
44697 +static int video_nr = -1;
44698 +module_param(video_nr, int, 0644);
44699 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
44700
44701 static unsigned n_devs = 1;
44702 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
44703 index d719e59..63f3470 100644
44704 --- a/drivers/media/radio/radio-cadet.c
44705 +++ b/drivers/media/radio/radio-cadet.c
44706 @@ -333,6 +333,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44707 unsigned char readbuf[RDS_BUFFER];
44708 int i = 0;
44709
44710 + if (count > RDS_BUFFER)
44711 + return -EFAULT;
44712 mutex_lock(&dev->lock);
44713 if (dev->rdsstat == 0)
44714 cadet_start_rds(dev);
44715 @@ -349,8 +351,9 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44716 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
44717 mutex_unlock(&dev->lock);
44718
44719 - if (i && copy_to_user(data, readbuf, i))
44720 - return -EFAULT;
44721 + if (i > sizeof(readbuf) || (i && copy_to_user(data, readbuf, i)))
44722 + i = -EFAULT;
44723 +
44724 return i;
44725 }
44726
44727 diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
44728 index 5236035..c622c74 100644
44729 --- a/drivers/media/radio/radio-maxiradio.c
44730 +++ b/drivers/media/radio/radio-maxiradio.c
44731 @@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
44732 /* TEA5757 pin mappings */
44733 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
44734
44735 -static atomic_t maxiradio_instance = ATOMIC_INIT(0);
44736 +static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
44737
44738 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
44739 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
44740 diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
44741 index 050b3bb..79f62b9 100644
44742 --- a/drivers/media/radio/radio-shark.c
44743 +++ b/drivers/media/radio/radio-shark.c
44744 @@ -79,7 +79,7 @@ struct shark_device {
44745 u32 last_val;
44746 };
44747
44748 -static atomic_t shark_instance = ATOMIC_INIT(0);
44749 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44750
44751 static void shark_write_val(struct snd_tea575x *tea, u32 val)
44752 {
44753 diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
44754 index 8654e0d..0608a64 100644
44755 --- a/drivers/media/radio/radio-shark2.c
44756 +++ b/drivers/media/radio/radio-shark2.c
44757 @@ -74,7 +74,7 @@ struct shark_device {
44758 u8 *transfer_buffer;
44759 };
44760
44761 -static atomic_t shark_instance = ATOMIC_INIT(0);
44762 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44763
44764 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
44765 {
44766 diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
44767 index 2fd9009..278cc1e 100644
44768 --- a/drivers/media/radio/radio-si476x.c
44769 +++ b/drivers/media/radio/radio-si476x.c
44770 @@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
44771 struct si476x_radio *radio;
44772 struct v4l2_ctrl *ctrl;
44773
44774 - static atomic_t instance = ATOMIC_INIT(0);
44775 + static atomic_unchecked_t instance = ATOMIC_INIT(0);
44776
44777 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
44778 if (!radio)
44779 diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
44780 index a1c641e..3007da9 100644
44781 --- a/drivers/media/usb/dvb-usb/cxusb.c
44782 +++ b/drivers/media/usb/dvb-usb/cxusb.c
44783 @@ -1112,7 +1112,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
44784
44785 struct dib0700_adapter_state {
44786 int (*set_param_save) (struct dvb_frontend *);
44787 -};
44788 +} __no_const;
44789
44790 static int dib7070_set_param_override(struct dvb_frontend *fe)
44791 {
44792 diff --git a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
44793 index 733a7ff..f8b52e3 100644
44794 --- a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
44795 +++ b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
44796 @@ -35,42 +35,57 @@ static int usb_cypress_writemem(struct usb_device *udev,u16 addr,u8 *data, u8 le
44797
44798 int usb_cypress_load_firmware(struct usb_device *udev, const struct firmware *fw, int type)
44799 {
44800 - struct hexline hx;
44801 - u8 reset;
44802 + struct hexline *hx;
44803 + u8 *reset;
44804 int ret,pos=0;
44805
44806 + reset = kmalloc(1, GFP_KERNEL);
44807 + if (reset == NULL)
44808 + return -ENOMEM;
44809 +
44810 + hx = kmalloc(sizeof(struct hexline), GFP_KERNEL);
44811 + if (hx == NULL) {
44812 + kfree(reset);
44813 + return -ENOMEM;
44814 + }
44815 +
44816 /* stop the CPU */
44817 - reset = 1;
44818 - if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1)) != 1)
44819 + reset[0] = 1;
44820 + if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1)) != 1)
44821 err("could not stop the USB controller CPU.");
44822
44823 - while ((ret = dvb_usb_get_hexline(fw,&hx,&pos)) > 0) {
44824 - deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx.addr,hx.len,hx.chk);
44825 - ret = usb_cypress_writemem(udev,hx.addr,hx.data,hx.len);
44826 + while ((ret = dvb_usb_get_hexline(fw,hx,&pos)) > 0) {
44827 + deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx->addr,hx->len,hx->chk);
44828 + ret = usb_cypress_writemem(udev,hx->addr,hx->data,hx->len);
44829
44830 - if (ret != hx.len) {
44831 + if (ret != hx->len) {
44832 err("error while transferring firmware "
44833 "(transferred size: %d, block size: %d)",
44834 - ret,hx.len);
44835 + ret,hx->len);
44836 ret = -EINVAL;
44837 break;
44838 }
44839 }
44840 if (ret < 0) {
44841 err("firmware download failed at %d with %d",pos,ret);
44842 + kfree(reset);
44843 + kfree(hx);
44844 return ret;
44845 }
44846
44847 if (ret == 0) {
44848 /* restart the CPU */
44849 - reset = 0;
44850 - if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1) != 1) {
44851 + reset[0] = 0;
44852 + if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1) != 1) {
44853 err("could not restart the USB controller CPU.");
44854 ret = -EINVAL;
44855 }
44856 } else
44857 ret = -EIO;
44858
44859 + kfree(reset);
44860 + kfree(hx);
44861 +
44862 return ret;
44863 }
44864 EXPORT_SYMBOL(usb_cypress_load_firmware);
44865 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
44866 index ae0f56a..ec71784 100644
44867 --- a/drivers/media/usb/dvb-usb/dw2102.c
44868 +++ b/drivers/media/usb/dvb-usb/dw2102.c
44869 @@ -118,7 +118,7 @@ struct su3000_state {
44870
44871 struct s6x0_state {
44872 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
44873 -};
44874 +} __no_const;
44875
44876 /* debug */
44877 static int dvb_usb_dw2102_debug;
44878 diff --git a/drivers/media/usb/dvb-usb/technisat-usb2.c b/drivers/media/usb/dvb-usb/technisat-usb2.c
44879 index 98d24ae..bc22415 100644
44880 --- a/drivers/media/usb/dvb-usb/technisat-usb2.c
44881 +++ b/drivers/media/usb/dvb-usb/technisat-usb2.c
44882 @@ -87,8 +87,11 @@ struct technisat_usb2_state {
44883 static int technisat_usb2_i2c_access(struct usb_device *udev,
44884 u8 device_addr, u8 *tx, u8 txlen, u8 *rx, u8 rxlen)
44885 {
44886 - u8 b[64];
44887 - int ret, actual_length;
44888 + u8 *b = kmalloc(64, GFP_KERNEL);
44889 + int ret, actual_length, error = 0;
44890 +
44891 + if (b == NULL)
44892 + return -ENOMEM;
44893
44894 deb_i2c("i2c-access: %02x, tx: ", device_addr);
44895 debug_dump(tx, txlen, deb_i2c);
44896 @@ -121,7 +124,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
44897
44898 if (ret < 0) {
44899 err("i2c-error: out failed %02x = %d", device_addr, ret);
44900 - return -ENODEV;
44901 + error = -ENODEV;
44902 + goto out;
44903 }
44904
44905 ret = usb_bulk_msg(udev,
44906 @@ -129,7 +133,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
44907 b, 64, &actual_length, 1000);
44908 if (ret < 0) {
44909 err("i2c-error: in failed %02x = %d", device_addr, ret);
44910 - return -ENODEV;
44911 + error = -ENODEV;
44912 + goto out;
44913 }
44914
44915 if (b[0] != I2C_STATUS_OK) {
44916 @@ -137,8 +142,10 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
44917 /* handle tuner-i2c-nak */
44918 if (!(b[0] == I2C_STATUS_NAK &&
44919 device_addr == 0x60
44920 - /* && device_is_technisat_usb2 */))
44921 - return -ENODEV;
44922 + /* && device_is_technisat_usb2 */)) {
44923 + error = -ENODEV;
44924 + goto out;
44925 + }
44926 }
44927
44928 deb_i2c("status: %d, ", b[0]);
44929 @@ -152,7 +159,9 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
44930
44931 deb_i2c("\n");
44932
44933 - return 0;
44934 +out:
44935 + kfree(b);
44936 + return error;
44937 }
44938
44939 static int technisat_usb2_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
44940 @@ -224,14 +233,16 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
44941 {
44942 int ret;
44943
44944 - u8 led[8] = {
44945 - red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
44946 - 0
44947 - };
44948 + u8 *led = kzalloc(8, GFP_KERNEL);
44949 +
44950 + if (led == NULL)
44951 + return -ENOMEM;
44952
44953 if (disable_led_control && state != LED_OFF)
44954 return 0;
44955
44956 + led[0] = red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST;
44957 +
44958 switch (state) {
44959 case LED_ON:
44960 led[1] = 0x82;
44961 @@ -263,16 +274,22 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
44962 red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
44963 USB_TYPE_VENDOR | USB_DIR_OUT,
44964 0, 0,
44965 - led, sizeof(led), 500);
44966 + led, 8, 500);
44967
44968 mutex_unlock(&d->i2c_mutex);
44969 +
44970 + kfree(led);
44971 +
44972 return ret;
44973 }
44974
44975 static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 green)
44976 {
44977 int ret;
44978 - u8 b = 0;
44979 + u8 *b = kzalloc(1, GFP_KERNEL);
44980 +
44981 + if (b == NULL)
44982 + return -ENOMEM;
44983
44984 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
44985 return -EAGAIN;
44986 @@ -281,10 +298,12 @@ static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 gre
44987 SET_LED_TIMER_DIVIDER_VENDOR_REQUEST,
44988 USB_TYPE_VENDOR | USB_DIR_OUT,
44989 (red << 8) | green, 0,
44990 - &b, 1, 500);
44991 + b, 1, 500);
44992
44993 mutex_unlock(&d->i2c_mutex);
44994
44995 + kfree(b);
44996 +
44997 return ret;
44998 }
44999
45000 @@ -328,7 +347,7 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
45001 struct dvb_usb_device_description **desc, int *cold)
45002 {
45003 int ret;
45004 - u8 version[3];
45005 + u8 *version = kmalloc(3, GFP_KERNEL);
45006
45007 /* first select the interface */
45008 if (usb_set_interface(udev, 0, 1) != 0)
45009 @@ -338,11 +357,14 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
45010
45011 *cold = 0; /* by default do not download a firmware - just in case something is wrong */
45012
45013 + if (version == NULL)
45014 + return 0;
45015 +
45016 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
45017 GET_VERSION_INFO_VENDOR_REQUEST,
45018 USB_TYPE_VENDOR | USB_DIR_IN,
45019 0, 0,
45020 - version, sizeof(version), 500);
45021 + version, 3, 500);
45022
45023 if (ret < 0)
45024 *cold = 1;
45025 @@ -351,6 +373,8 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
45026 *cold = 0;
45027 }
45028
45029 + kfree(version);
45030 +
45031 return 0;
45032 }
45033
45034 @@ -591,10 +615,15 @@ static int technisat_usb2_frontend_attach(struct dvb_usb_adapter *a)
45035
45036 static int technisat_usb2_get_ir(struct dvb_usb_device *d)
45037 {
45038 - u8 buf[62], *b;
45039 + u8 *buf, *b;
45040 int ret;
45041 struct ir_raw_event ev;
45042
45043 + buf = kmalloc(62, GFP_KERNEL);
45044 +
45045 + if (buf == NULL)
45046 + return -ENOMEM;
45047 +
45048 buf[0] = GET_IR_DATA_VENDOR_REQUEST;
45049 buf[1] = 0x08;
45050 buf[2] = 0x8f;
45051 @@ -617,16 +646,20 @@ static int technisat_usb2_get_ir(struct dvb_usb_device *d)
45052 GET_IR_DATA_VENDOR_REQUEST,
45053 USB_TYPE_VENDOR | USB_DIR_IN,
45054 0x8080, 0,
45055 - buf, sizeof(buf), 500);
45056 + buf, 62, 500);
45057
45058 unlock:
45059 mutex_unlock(&d->i2c_mutex);
45060
45061 - if (ret < 0)
45062 + if (ret < 0) {
45063 + kfree(buf);
45064 return ret;
45065 + }
45066
45067 - if (ret == 1)
45068 + if (ret == 1) {
45069 + kfree(buf);
45070 return 0; /* no key pressed */
45071 + }
45072
45073 /* decoding */
45074 b = buf+1;
45075 @@ -653,6 +686,8 @@ unlock:
45076
45077 ir_raw_event_handle(d->rc_dev);
45078
45079 + kfree(buf);
45080 +
45081 return 1;
45082 }
45083
45084 diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
45085 index 7e2411c..cef73ca 100644
45086 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
45087 +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
45088 @@ -328,7 +328,7 @@ struct v4l2_buffer32 {
45089 __u32 reserved;
45090 };
45091
45092 -static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
45093 +static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
45094 enum v4l2_memory memory)
45095 {
45096 void __user *up_pln;
45097 @@ -357,7 +357,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
45098 return 0;
45099 }
45100
45101 -static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
45102 +static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
45103 enum v4l2_memory memory)
45104 {
45105 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
45106 @@ -427,7 +427,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
45107 * by passing a very big num_planes value */
45108 uplane = compat_alloc_user_space(num_planes *
45109 sizeof(struct v4l2_plane));
45110 - kp->m.planes = uplane;
45111 + kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
45112
45113 while (--num_planes >= 0) {
45114 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
45115 @@ -498,7 +498,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
45116 if (num_planes == 0)
45117 return 0;
45118
45119 - uplane = kp->m.planes;
45120 + uplane = (struct v4l2_plane __force_user *)kp->m.planes;
45121 if (get_user(p, &up->m.planes))
45122 return -EFAULT;
45123 uplane32 = compat_ptr(p);
45124 @@ -552,7 +552,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
45125 get_user(kp->capability, &up->capability) ||
45126 get_user(kp->flags, &up->flags))
45127 return -EFAULT;
45128 - kp->base = compat_ptr(tmp);
45129 + kp->base = (void __force_kernel *)compat_ptr(tmp);
45130 get_v4l2_pix_format(&kp->fmt, &up->fmt);
45131 return 0;
45132 }
45133 @@ -658,7 +658,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
45134 n * sizeof(struct v4l2_ext_control32)))
45135 return -EFAULT;
45136 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
45137 - kp->controls = kcontrols;
45138 + kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
45139 while (--n >= 0) {
45140 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
45141 return -EFAULT;
45142 @@ -680,7 +680,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
45143 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
45144 {
45145 struct v4l2_ext_control32 __user *ucontrols;
45146 - struct v4l2_ext_control __user *kcontrols = kp->controls;
45147 + struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
45148 int n = kp->count;
45149 compat_caddr_t p;
45150
45151 @@ -774,7 +774,7 @@ static int put_v4l2_edid32(struct v4l2_edid *kp, struct v4l2_edid32 __user *up)
45152 put_user(kp->start_block, &up->start_block) ||
45153 put_user(kp->blocks, &up->blocks) ||
45154 put_user(tmp, &up->edid) ||
45155 - copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
45156 + copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
45157 return -EFAULT;
45158 return 0;
45159 }
45160 diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
45161 index 55c6832..a91c7a6 100644
45162 --- a/drivers/media/v4l2-core/v4l2-ctrls.c
45163 +++ b/drivers/media/v4l2-core/v4l2-ctrls.c
45164 @@ -1431,8 +1431,8 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
45165 return 0;
45166
45167 case V4L2_CTRL_TYPE_STRING:
45168 - len = strlen(c->string);
45169 - if (len < ctrl->minimum)
45170 + len = strlen_user(c->string);
45171 + if (!len || len < ctrl->minimum)
45172 return -ERANGE;
45173 if ((len - ctrl->minimum) % ctrl->step)
45174 return -ERANGE;
45175 diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
45176 index 02d1b63..5fd6b16 100644
45177 --- a/drivers/media/v4l2-core/v4l2-device.c
45178 +++ b/drivers/media/v4l2-core/v4l2-device.c
45179 @@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
45180 EXPORT_SYMBOL_GPL(v4l2_device_put);
45181
45182 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
45183 - atomic_t *instance)
45184 + atomic_unchecked_t *instance)
45185 {
45186 - int num = atomic_inc_return(instance) - 1;
45187 + int num = atomic_inc_return_unchecked(instance) - 1;
45188 int len = strlen(basename);
45189
45190 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
45191 diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
45192 index d9113cc..7de6ccc 100644
45193 --- a/drivers/media/v4l2-core/v4l2-ioctl.c
45194 +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
45195 @@ -2003,7 +2003,8 @@ struct v4l2_ioctl_info {
45196 struct file *file, void *fh, void *p);
45197 } u;
45198 void (*debug)(const void *arg, bool write_only);
45199 -};
45200 +} __do_const;
45201 +typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
45202
45203 /* This control needs a priority check */
45204 #define INFO_FL_PRIO (1 << 0)
45205 @@ -2186,7 +2187,7 @@ static long __video_do_ioctl(struct file *file,
45206 struct video_device *vfd = video_devdata(file);
45207 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
45208 bool write_only = false;
45209 - struct v4l2_ioctl_info default_info;
45210 + v4l2_ioctl_info_no_const default_info;
45211 const struct v4l2_ioctl_info *info;
45212 void *fh = file->private_data;
45213 struct v4l2_fh *vfh = NULL;
45214 @@ -2260,7 +2261,7 @@ done:
45215 }
45216
45217 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
45218 - void * __user *user_ptr, void ***kernel_ptr)
45219 + void __user **user_ptr, void ***kernel_ptr)
45220 {
45221 int ret = 0;
45222
45223 @@ -2276,7 +2277,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
45224 ret = -EINVAL;
45225 break;
45226 }
45227 - *user_ptr = (void __user *)buf->m.planes;
45228 + *user_ptr = (void __force_user *)buf->m.planes;
45229 *kernel_ptr = (void *)&buf->m.planes;
45230 *array_size = sizeof(struct v4l2_plane) * buf->length;
45231 ret = 1;
45232 @@ -2311,7 +2312,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
45233 ret = -EINVAL;
45234 break;
45235 }
45236 - *user_ptr = (void __user *)ctrls->controls;
45237 + *user_ptr = (void __force_user *)ctrls->controls;
45238 *kernel_ptr = (void *)&ctrls->controls;
45239 *array_size = sizeof(struct v4l2_ext_control)
45240 * ctrls->count;
45241 @@ -2412,7 +2413,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
45242 }
45243
45244 if (has_array_args) {
45245 - *kernel_ptr = user_ptr;
45246 + *kernel_ptr = (void __force_kernel *)user_ptr;
45247 if (copy_to_user(user_ptr, mbuf, array_size))
45248 err = -EFAULT;
45249 goto out_array_args;
45250 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
45251 index 570b18a..f880314 100644
45252 --- a/drivers/message/fusion/mptbase.c
45253 +++ b/drivers/message/fusion/mptbase.c
45254 @@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
45255 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
45256 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
45257
45258 +#ifdef CONFIG_GRKERNSEC_HIDESYM
45259 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
45260 +#else
45261 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
45262 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
45263 +#endif
45264 +
45265 /*
45266 * Rounding UP to nearest 4-kB boundary here...
45267 */
45268 @@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
45269 ioc->facts.GlobalCredits);
45270
45271 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
45272 +#ifdef CONFIG_GRKERNSEC_HIDESYM
45273 + NULL, NULL);
45274 +#else
45275 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
45276 +#endif
45277 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
45278 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
45279 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
45280 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
45281 index 00d339c..2ea899d 100644
45282 --- a/drivers/message/fusion/mptsas.c
45283 +++ b/drivers/message/fusion/mptsas.c
45284 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
45285 return 0;
45286 }
45287
45288 +static inline void
45289 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
45290 +{
45291 + if (phy_info->port_details) {
45292 + phy_info->port_details->rphy = rphy;
45293 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
45294 + ioc->name, rphy));
45295 + }
45296 +
45297 + if (rphy) {
45298 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
45299 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
45300 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
45301 + ioc->name, rphy, rphy->dev.release));
45302 + }
45303 +}
45304 +
45305 /* no mutex */
45306 static void
45307 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
45308 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
45309 return NULL;
45310 }
45311
45312 -static inline void
45313 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
45314 -{
45315 - if (phy_info->port_details) {
45316 - phy_info->port_details->rphy = rphy;
45317 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
45318 - ioc->name, rphy));
45319 - }
45320 -
45321 - if (rphy) {
45322 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
45323 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
45324 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
45325 - ioc->name, rphy, rphy->dev.release));
45326 - }
45327 -}
45328 -
45329 static inline struct sas_port *
45330 mptsas_get_port(struct mptsas_phyinfo *phy_info)
45331 {
45332 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
45333 index 727819c..ad74694 100644
45334 --- a/drivers/message/fusion/mptscsih.c
45335 +++ b/drivers/message/fusion/mptscsih.c
45336 @@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
45337
45338 h = shost_priv(SChost);
45339
45340 - if (h) {
45341 - if (h->info_kbuf == NULL)
45342 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
45343 - return h->info_kbuf;
45344 - h->info_kbuf[0] = '\0';
45345 + if (!h)
45346 + return NULL;
45347
45348 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
45349 - h->info_kbuf[size-1] = '\0';
45350 - }
45351 + if (h->info_kbuf == NULL)
45352 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
45353 + return h->info_kbuf;
45354 + h->info_kbuf[0] = '\0';
45355 +
45356 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
45357 + h->info_kbuf[size-1] = '\0';
45358
45359 return h->info_kbuf;
45360 }
45361 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
45362 index b7d87cd..3fb36da 100644
45363 --- a/drivers/message/i2o/i2o_proc.c
45364 +++ b/drivers/message/i2o/i2o_proc.c
45365 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
45366 "Array Controller Device"
45367 };
45368
45369 -static char *chtostr(char *tmp, u8 *chars, int n)
45370 -{
45371 - tmp[0] = 0;
45372 - return strncat(tmp, (char *)chars, n);
45373 -}
45374 -
45375 static int i2o_report_query_status(struct seq_file *seq, int block_status,
45376 char *group)
45377 {
45378 @@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
45379 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
45380 {
45381 struct i2o_controller *c = (struct i2o_controller *)seq->private;
45382 - static u32 work32[5];
45383 - static u8 *work8 = (u8 *) work32;
45384 - static u16 *work16 = (u16 *) work32;
45385 + u32 work32[5];
45386 + u8 *work8 = (u8 *) work32;
45387 + u16 *work16 = (u16 *) work32;
45388 int token;
45389 u32 hwcap;
45390
45391 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
45392 } *result;
45393
45394 i2o_exec_execute_ddm_table ddm_table;
45395 - char tmp[28 + 1];
45396
45397 result = kmalloc(sizeof(*result), GFP_KERNEL);
45398 if (!result)
45399 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
45400
45401 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
45402 seq_printf(seq, "%-#8x", ddm_table.module_id);
45403 - seq_printf(seq, "%-29s",
45404 - chtostr(tmp, ddm_table.module_name_version, 28));
45405 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
45406 seq_printf(seq, "%9d ", ddm_table.data_size);
45407 seq_printf(seq, "%8d", ddm_table.code_size);
45408
45409 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
45410
45411 i2o_driver_result_table *result;
45412 i2o_driver_store_table *dst;
45413 - char tmp[28 + 1];
45414
45415 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
45416 if (result == NULL)
45417 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
45418
45419 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
45420 seq_printf(seq, "%-#8x", dst->module_id);
45421 - seq_printf(seq, "%-29s",
45422 - chtostr(tmp, dst->module_name_version, 28));
45423 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
45424 + seq_printf(seq, "%-.28s", dst->module_name_version);
45425 + seq_printf(seq, "%-.8s", dst->date);
45426 seq_printf(seq, "%8d ", dst->module_size);
45427 seq_printf(seq, "%8d ", dst->mpb_size);
45428 seq_printf(seq, "0x%04x", dst->module_flags);
45429 @@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
45430 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
45431 {
45432 struct i2o_device *d = (struct i2o_device *)seq->private;
45433 - static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
45434 + u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
45435 // == (allow) 512d bytes (max)
45436 - static u16 *work16 = (u16 *) work32;
45437 + u16 *work16 = (u16 *) work32;
45438 int token;
45439 - char tmp[16 + 1];
45440
45441 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
45442
45443 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
45444 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
45445 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
45446 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
45447 - seq_printf(seq, "Vendor info : %s\n",
45448 - chtostr(tmp, (u8 *) (work32 + 2), 16));
45449 - seq_printf(seq, "Product info : %s\n",
45450 - chtostr(tmp, (u8 *) (work32 + 6), 16));
45451 - seq_printf(seq, "Description : %s\n",
45452 - chtostr(tmp, (u8 *) (work32 + 10), 16));
45453 - seq_printf(seq, "Product rev. : %s\n",
45454 - chtostr(tmp, (u8 *) (work32 + 14), 8));
45455 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
45456 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
45457 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
45458 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
45459
45460 seq_printf(seq, "Serial number : ");
45461 print_serial_number(seq, (u8 *) (work32 + 16),
45462 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
45463 u8 pad[256]; // allow up to 256 byte (max) serial number
45464 } result;
45465
45466 - char tmp[24 + 1];
45467 -
45468 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
45469
45470 if (token < 0) {
45471 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
45472 }
45473
45474 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
45475 - seq_printf(seq, "Module name : %s\n",
45476 - chtostr(tmp, result.module_name, 24));
45477 - seq_printf(seq, "Module revision : %s\n",
45478 - chtostr(tmp, result.module_rev, 8));
45479 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
45480 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
45481
45482 seq_printf(seq, "Serial number : ");
45483 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
45484 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45485 u8 instance_number[4];
45486 } result;
45487
45488 - char tmp[64 + 1];
45489 -
45490 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
45491
45492 if (token < 0) {
45493 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45494 return 0;
45495 }
45496
45497 - seq_printf(seq, "Device name : %s\n",
45498 - chtostr(tmp, result.device_name, 64));
45499 - seq_printf(seq, "Service name : %s\n",
45500 - chtostr(tmp, result.service_name, 64));
45501 - seq_printf(seq, "Physical name : %s\n",
45502 - chtostr(tmp, result.physical_location, 64));
45503 - seq_printf(seq, "Instance number : %s\n",
45504 - chtostr(tmp, result.instance_number, 4));
45505 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
45506 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
45507 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
45508 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
45509
45510 return 0;
45511 }
45512 @@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45513 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
45514 {
45515 struct i2o_device *d = (struct i2o_device *)seq->private;
45516 - static u32 work32[12];
45517 - static u16 *work16 = (u16 *) work32;
45518 - static u8 *work8 = (u8 *) work32;
45519 + u32 work32[12];
45520 + u16 *work16 = (u16 *) work32;
45521 + u8 *work8 = (u8 *) work32;
45522 int token;
45523
45524 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
45525 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
45526 index 92752fb..a7494f6 100644
45527 --- a/drivers/message/i2o/iop.c
45528 +++ b/drivers/message/i2o/iop.c
45529 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
45530
45531 spin_lock_irqsave(&c->context_list_lock, flags);
45532
45533 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
45534 - atomic_inc(&c->context_list_counter);
45535 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
45536 + atomic_inc_unchecked(&c->context_list_counter);
45537
45538 - entry->context = atomic_read(&c->context_list_counter);
45539 + entry->context = atomic_read_unchecked(&c->context_list_counter);
45540
45541 list_add(&entry->list, &c->context_list);
45542
45543 @@ -1076,7 +1076,7 @@ struct i2o_controller *i2o_iop_alloc(void)
45544
45545 #if BITS_PER_LONG == 64
45546 spin_lock_init(&c->context_list_lock);
45547 - atomic_set(&c->context_list_counter, 0);
45548 + atomic_set_unchecked(&c->context_list_counter, 0);
45549 INIT_LIST_HEAD(&c->context_list);
45550 #endif
45551
45552 diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
45553 index d1a22aa..d0f7bf7 100644
45554 --- a/drivers/mfd/ab8500-debugfs.c
45555 +++ b/drivers/mfd/ab8500-debugfs.c
45556 @@ -100,7 +100,7 @@ static int irq_last;
45557 static u32 *irq_count;
45558 static int num_irqs;
45559
45560 -static struct device_attribute **dev_attr;
45561 +static device_attribute_no_const **dev_attr;
45562 static char **event_name;
45563
45564 static u8 avg_sample = SAMPLE_16;
45565 diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
45566 index a83eed5..62a58a9 100644
45567 --- a/drivers/mfd/max8925-i2c.c
45568 +++ b/drivers/mfd/max8925-i2c.c
45569 @@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
45570 const struct i2c_device_id *id)
45571 {
45572 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
45573 - static struct max8925_chip *chip;
45574 + struct max8925_chip *chip;
45575 struct device_node *node = client->dev.of_node;
45576
45577 if (node && !pdata) {
45578 diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
45579 index 460a014..21d3061 100644
45580 --- a/drivers/mfd/tps65910.c
45581 +++ b/drivers/mfd/tps65910.c
45582 @@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
45583 struct tps65910_platform_data *pdata)
45584 {
45585 int ret = 0;
45586 - static struct regmap_irq_chip *tps6591x_irqs_chip;
45587 + struct regmap_irq_chip *tps6591x_irqs_chip;
45588
45589 if (!irq) {
45590 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
45591 diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
45592 index 596b1f6..5b6ab74 100644
45593 --- a/drivers/mfd/twl4030-irq.c
45594 +++ b/drivers/mfd/twl4030-irq.c
45595 @@ -34,6 +34,7 @@
45596 #include <linux/of.h>
45597 #include <linux/irqdomain.h>
45598 #include <linux/i2c/twl.h>
45599 +#include <asm/pgtable.h>
45600
45601 #include "twl-core.h"
45602
45603 @@ -725,10 +726,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
45604 * Install an irq handler for each of the SIH modules;
45605 * clone dummy irq_chip since PIH can't *do* anything
45606 */
45607 - twl4030_irq_chip = dummy_irq_chip;
45608 - twl4030_irq_chip.name = "twl4030";
45609 + pax_open_kernel();
45610 + memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
45611 + *(const char **)&twl4030_irq_chip.name = "twl4030";
45612
45613 - twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45614 + *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45615 + pax_close_kernel();
45616
45617 for (i = irq_base; i < irq_end; i++) {
45618 irq_set_chip_and_handler(i, &twl4030_irq_chip,
45619 diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
45620 index 464419b..64bae8d 100644
45621 --- a/drivers/misc/c2port/core.c
45622 +++ b/drivers/misc/c2port/core.c
45623 @@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
45624 goto error_idr_alloc;
45625 c2dev->id = ret;
45626
45627 - bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45628 + pax_open_kernel();
45629 + *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45630 + pax_close_kernel();
45631
45632 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
45633 "c2port%d", c2dev->id);
45634 diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
45635 index 3f2b625..945e179 100644
45636 --- a/drivers/misc/eeprom/sunxi_sid.c
45637 +++ b/drivers/misc/eeprom/sunxi_sid.c
45638 @@ -126,7 +126,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
45639
45640 platform_set_drvdata(pdev, sid_data);
45641
45642 - sid_bin_attr.size = sid_data->keysize;
45643 + pax_open_kernel();
45644 + *(size_t *)&sid_bin_attr.size = sid_data->keysize;
45645 + pax_close_kernel();
45646 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
45647 return -ENODEV;
45648
45649 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
45650 index 36f5d52..32311c3 100644
45651 --- a/drivers/misc/kgdbts.c
45652 +++ b/drivers/misc/kgdbts.c
45653 @@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
45654 char before[BREAK_INSTR_SIZE];
45655 char after[BREAK_INSTR_SIZE];
45656
45657 - probe_kernel_read(before, (char *)kgdbts_break_test,
45658 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
45659 BREAK_INSTR_SIZE);
45660 init_simple_test();
45661 ts.tst = plant_and_detach_test;
45662 @@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
45663 /* Activate test with initial breakpoint */
45664 if (!is_early)
45665 kgdb_breakpoint();
45666 - probe_kernel_read(after, (char *)kgdbts_break_test,
45667 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
45668 BREAK_INSTR_SIZE);
45669 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
45670 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
45671 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
45672 index 3ef4627..8d00486 100644
45673 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
45674 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
45675 @@ -497,7 +497,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
45676 * the lid is closed. This leads to interrupts as soon as a little move
45677 * is done.
45678 */
45679 - atomic_inc(&lis3->count);
45680 + atomic_inc_unchecked(&lis3->count);
45681
45682 wake_up_interruptible(&lis3->misc_wait);
45683 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
45684 @@ -583,7 +583,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
45685 if (lis3->pm_dev)
45686 pm_runtime_get_sync(lis3->pm_dev);
45687
45688 - atomic_set(&lis3->count, 0);
45689 + atomic_set_unchecked(&lis3->count, 0);
45690 return 0;
45691 }
45692
45693 @@ -615,7 +615,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
45694 add_wait_queue(&lis3->misc_wait, &wait);
45695 while (true) {
45696 set_current_state(TASK_INTERRUPTIBLE);
45697 - data = atomic_xchg(&lis3->count, 0);
45698 + data = atomic_xchg_unchecked(&lis3->count, 0);
45699 if (data)
45700 break;
45701
45702 @@ -656,7 +656,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
45703 struct lis3lv02d, miscdev);
45704
45705 poll_wait(file, &lis3->misc_wait, wait);
45706 - if (atomic_read(&lis3->count))
45707 + if (atomic_read_unchecked(&lis3->count))
45708 return POLLIN | POLLRDNORM;
45709 return 0;
45710 }
45711 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
45712 index c439c82..1f20f57 100644
45713 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
45714 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
45715 @@ -297,7 +297,7 @@ struct lis3lv02d {
45716 struct input_polled_dev *idev; /* input device */
45717 struct platform_device *pdev; /* platform device */
45718 struct regulator_bulk_data regulators[2];
45719 - atomic_t count; /* interrupt count after last read */
45720 + atomic_unchecked_t count; /* interrupt count after last read */
45721 union axis_conversion ac; /* hw -> logical axis */
45722 int mapped_btns[3];
45723
45724 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
45725 index 2f30bad..c4c13d0 100644
45726 --- a/drivers/misc/sgi-gru/gruhandles.c
45727 +++ b/drivers/misc/sgi-gru/gruhandles.c
45728 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
45729 unsigned long nsec;
45730
45731 nsec = CLKS2NSEC(clks);
45732 - atomic_long_inc(&mcs_op_statistics[op].count);
45733 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
45734 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
45735 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
45736 if (mcs_op_statistics[op].max < nsec)
45737 mcs_op_statistics[op].max = nsec;
45738 }
45739 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
45740 index 4f76359..cdfcb2e 100644
45741 --- a/drivers/misc/sgi-gru/gruprocfs.c
45742 +++ b/drivers/misc/sgi-gru/gruprocfs.c
45743 @@ -32,9 +32,9 @@
45744
45745 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
45746
45747 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
45748 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
45749 {
45750 - unsigned long val = atomic_long_read(v);
45751 + unsigned long val = atomic_long_read_unchecked(v);
45752
45753 seq_printf(s, "%16lu %s\n", val, id);
45754 }
45755 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
45756
45757 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
45758 for (op = 0; op < mcsop_last; op++) {
45759 - count = atomic_long_read(&mcs_op_statistics[op].count);
45760 - total = atomic_long_read(&mcs_op_statistics[op].total);
45761 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
45762 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
45763 max = mcs_op_statistics[op].max;
45764 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
45765 count ? total / count : 0, max);
45766 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
45767 index 5c3ce24..4915ccb 100644
45768 --- a/drivers/misc/sgi-gru/grutables.h
45769 +++ b/drivers/misc/sgi-gru/grutables.h
45770 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
45771 * GRU statistics.
45772 */
45773 struct gru_stats_s {
45774 - atomic_long_t vdata_alloc;
45775 - atomic_long_t vdata_free;
45776 - atomic_long_t gts_alloc;
45777 - atomic_long_t gts_free;
45778 - atomic_long_t gms_alloc;
45779 - atomic_long_t gms_free;
45780 - atomic_long_t gts_double_allocate;
45781 - atomic_long_t assign_context;
45782 - atomic_long_t assign_context_failed;
45783 - atomic_long_t free_context;
45784 - atomic_long_t load_user_context;
45785 - atomic_long_t load_kernel_context;
45786 - atomic_long_t lock_kernel_context;
45787 - atomic_long_t unlock_kernel_context;
45788 - atomic_long_t steal_user_context;
45789 - atomic_long_t steal_kernel_context;
45790 - atomic_long_t steal_context_failed;
45791 - atomic_long_t nopfn;
45792 - atomic_long_t asid_new;
45793 - atomic_long_t asid_next;
45794 - atomic_long_t asid_wrap;
45795 - atomic_long_t asid_reuse;
45796 - atomic_long_t intr;
45797 - atomic_long_t intr_cbr;
45798 - atomic_long_t intr_tfh;
45799 - atomic_long_t intr_spurious;
45800 - atomic_long_t intr_mm_lock_failed;
45801 - atomic_long_t call_os;
45802 - atomic_long_t call_os_wait_queue;
45803 - atomic_long_t user_flush_tlb;
45804 - atomic_long_t user_unload_context;
45805 - atomic_long_t user_exception;
45806 - atomic_long_t set_context_option;
45807 - atomic_long_t check_context_retarget_intr;
45808 - atomic_long_t check_context_unload;
45809 - atomic_long_t tlb_dropin;
45810 - atomic_long_t tlb_preload_page;
45811 - atomic_long_t tlb_dropin_fail_no_asid;
45812 - atomic_long_t tlb_dropin_fail_upm;
45813 - atomic_long_t tlb_dropin_fail_invalid;
45814 - atomic_long_t tlb_dropin_fail_range_active;
45815 - atomic_long_t tlb_dropin_fail_idle;
45816 - atomic_long_t tlb_dropin_fail_fmm;
45817 - atomic_long_t tlb_dropin_fail_no_exception;
45818 - atomic_long_t tfh_stale_on_fault;
45819 - atomic_long_t mmu_invalidate_range;
45820 - atomic_long_t mmu_invalidate_page;
45821 - atomic_long_t flush_tlb;
45822 - atomic_long_t flush_tlb_gru;
45823 - atomic_long_t flush_tlb_gru_tgh;
45824 - atomic_long_t flush_tlb_gru_zero_asid;
45825 + atomic_long_unchecked_t vdata_alloc;
45826 + atomic_long_unchecked_t vdata_free;
45827 + atomic_long_unchecked_t gts_alloc;
45828 + atomic_long_unchecked_t gts_free;
45829 + atomic_long_unchecked_t gms_alloc;
45830 + atomic_long_unchecked_t gms_free;
45831 + atomic_long_unchecked_t gts_double_allocate;
45832 + atomic_long_unchecked_t assign_context;
45833 + atomic_long_unchecked_t assign_context_failed;
45834 + atomic_long_unchecked_t free_context;
45835 + atomic_long_unchecked_t load_user_context;
45836 + atomic_long_unchecked_t load_kernel_context;
45837 + atomic_long_unchecked_t lock_kernel_context;
45838 + atomic_long_unchecked_t unlock_kernel_context;
45839 + atomic_long_unchecked_t steal_user_context;
45840 + atomic_long_unchecked_t steal_kernel_context;
45841 + atomic_long_unchecked_t steal_context_failed;
45842 + atomic_long_unchecked_t nopfn;
45843 + atomic_long_unchecked_t asid_new;
45844 + atomic_long_unchecked_t asid_next;
45845 + atomic_long_unchecked_t asid_wrap;
45846 + atomic_long_unchecked_t asid_reuse;
45847 + atomic_long_unchecked_t intr;
45848 + atomic_long_unchecked_t intr_cbr;
45849 + atomic_long_unchecked_t intr_tfh;
45850 + atomic_long_unchecked_t intr_spurious;
45851 + atomic_long_unchecked_t intr_mm_lock_failed;
45852 + atomic_long_unchecked_t call_os;
45853 + atomic_long_unchecked_t call_os_wait_queue;
45854 + atomic_long_unchecked_t user_flush_tlb;
45855 + atomic_long_unchecked_t user_unload_context;
45856 + atomic_long_unchecked_t user_exception;
45857 + atomic_long_unchecked_t set_context_option;
45858 + atomic_long_unchecked_t check_context_retarget_intr;
45859 + atomic_long_unchecked_t check_context_unload;
45860 + atomic_long_unchecked_t tlb_dropin;
45861 + atomic_long_unchecked_t tlb_preload_page;
45862 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
45863 + atomic_long_unchecked_t tlb_dropin_fail_upm;
45864 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
45865 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
45866 + atomic_long_unchecked_t tlb_dropin_fail_idle;
45867 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
45868 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
45869 + atomic_long_unchecked_t tfh_stale_on_fault;
45870 + atomic_long_unchecked_t mmu_invalidate_range;
45871 + atomic_long_unchecked_t mmu_invalidate_page;
45872 + atomic_long_unchecked_t flush_tlb;
45873 + atomic_long_unchecked_t flush_tlb_gru;
45874 + atomic_long_unchecked_t flush_tlb_gru_tgh;
45875 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
45876
45877 - atomic_long_t copy_gpa;
45878 - atomic_long_t read_gpa;
45879 + atomic_long_unchecked_t copy_gpa;
45880 + atomic_long_unchecked_t read_gpa;
45881
45882 - atomic_long_t mesq_receive;
45883 - atomic_long_t mesq_receive_none;
45884 - atomic_long_t mesq_send;
45885 - atomic_long_t mesq_send_failed;
45886 - atomic_long_t mesq_noop;
45887 - atomic_long_t mesq_send_unexpected_error;
45888 - atomic_long_t mesq_send_lb_overflow;
45889 - atomic_long_t mesq_send_qlimit_reached;
45890 - atomic_long_t mesq_send_amo_nacked;
45891 - atomic_long_t mesq_send_put_nacked;
45892 - atomic_long_t mesq_page_overflow;
45893 - atomic_long_t mesq_qf_locked;
45894 - atomic_long_t mesq_qf_noop_not_full;
45895 - atomic_long_t mesq_qf_switch_head_failed;
45896 - atomic_long_t mesq_qf_unexpected_error;
45897 - atomic_long_t mesq_noop_unexpected_error;
45898 - atomic_long_t mesq_noop_lb_overflow;
45899 - atomic_long_t mesq_noop_qlimit_reached;
45900 - atomic_long_t mesq_noop_amo_nacked;
45901 - atomic_long_t mesq_noop_put_nacked;
45902 - atomic_long_t mesq_noop_page_overflow;
45903 + atomic_long_unchecked_t mesq_receive;
45904 + atomic_long_unchecked_t mesq_receive_none;
45905 + atomic_long_unchecked_t mesq_send;
45906 + atomic_long_unchecked_t mesq_send_failed;
45907 + atomic_long_unchecked_t mesq_noop;
45908 + atomic_long_unchecked_t mesq_send_unexpected_error;
45909 + atomic_long_unchecked_t mesq_send_lb_overflow;
45910 + atomic_long_unchecked_t mesq_send_qlimit_reached;
45911 + atomic_long_unchecked_t mesq_send_amo_nacked;
45912 + atomic_long_unchecked_t mesq_send_put_nacked;
45913 + atomic_long_unchecked_t mesq_page_overflow;
45914 + atomic_long_unchecked_t mesq_qf_locked;
45915 + atomic_long_unchecked_t mesq_qf_noop_not_full;
45916 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
45917 + atomic_long_unchecked_t mesq_qf_unexpected_error;
45918 + atomic_long_unchecked_t mesq_noop_unexpected_error;
45919 + atomic_long_unchecked_t mesq_noop_lb_overflow;
45920 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
45921 + atomic_long_unchecked_t mesq_noop_amo_nacked;
45922 + atomic_long_unchecked_t mesq_noop_put_nacked;
45923 + atomic_long_unchecked_t mesq_noop_page_overflow;
45924
45925 };
45926
45927 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
45928 tghop_invalidate, mcsop_last};
45929
45930 struct mcs_op_statistic {
45931 - atomic_long_t count;
45932 - atomic_long_t total;
45933 + atomic_long_unchecked_t count;
45934 + atomic_long_unchecked_t total;
45935 unsigned long max;
45936 };
45937
45938 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
45939
45940 #define STAT(id) do { \
45941 if (gru_options & OPT_STATS) \
45942 - atomic_long_inc(&gru_stats.id); \
45943 + atomic_long_inc_unchecked(&gru_stats.id); \
45944 } while (0)
45945
45946 #ifdef CONFIG_SGI_GRU_DEBUG
45947 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
45948 index c862cd4..0d176fe 100644
45949 --- a/drivers/misc/sgi-xp/xp.h
45950 +++ b/drivers/misc/sgi-xp/xp.h
45951 @@ -288,7 +288,7 @@ struct xpc_interface {
45952 xpc_notify_func, void *);
45953 void (*received) (short, int, void *);
45954 enum xp_retval (*partid_to_nasids) (short, void *);
45955 -};
45956 +} __no_const;
45957
45958 extern struct xpc_interface xpc_interface;
45959
45960 diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
45961 index 01be66d..e3a0c7e 100644
45962 --- a/drivers/misc/sgi-xp/xp_main.c
45963 +++ b/drivers/misc/sgi-xp/xp_main.c
45964 @@ -78,13 +78,13 @@ xpc_notloaded(void)
45965 }
45966
45967 struct xpc_interface xpc_interface = {
45968 - (void (*)(int))xpc_notloaded,
45969 - (void (*)(int))xpc_notloaded,
45970 - (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45971 - (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45972 + .connect = (void (*)(int))xpc_notloaded,
45973 + .disconnect = (void (*)(int))xpc_notloaded,
45974 + .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45975 + .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45976 void *))xpc_notloaded,
45977 - (void (*)(short, int, void *))xpc_notloaded,
45978 - (enum xp_retval(*)(short, void *))xpc_notloaded
45979 + .received = (void (*)(short, int, void *))xpc_notloaded,
45980 + .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
45981 };
45982 EXPORT_SYMBOL_GPL(xpc_interface);
45983
45984 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
45985 index b94d5f7..7f494c5 100644
45986 --- a/drivers/misc/sgi-xp/xpc.h
45987 +++ b/drivers/misc/sgi-xp/xpc.h
45988 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
45989 void (*received_payload) (struct xpc_channel *, void *);
45990 void (*notify_senders_of_disconnect) (struct xpc_channel *);
45991 };
45992 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
45993
45994 /* struct xpc_partition act_state values (for XPC HB) */
45995
45996 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
45997 /* found in xpc_main.c */
45998 extern struct device *xpc_part;
45999 extern struct device *xpc_chan;
46000 -extern struct xpc_arch_operations xpc_arch_ops;
46001 +extern xpc_arch_operations_no_const xpc_arch_ops;
46002 extern int xpc_disengage_timelimit;
46003 extern int xpc_disengage_timedout;
46004 extern int xpc_activate_IRQ_rcvd;
46005 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
46006 index 82dc574..8539ab2 100644
46007 --- a/drivers/misc/sgi-xp/xpc_main.c
46008 +++ b/drivers/misc/sgi-xp/xpc_main.c
46009 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
46010 .notifier_call = xpc_system_die,
46011 };
46012
46013 -struct xpc_arch_operations xpc_arch_ops;
46014 +xpc_arch_operations_no_const xpc_arch_ops;
46015
46016 /*
46017 * Timer function to enforce the timelimit on the partition disengage.
46018 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
46019
46020 if (((die_args->trapnr == X86_TRAP_MF) ||
46021 (die_args->trapnr == X86_TRAP_XF)) &&
46022 - !user_mode_vm(die_args->regs))
46023 + !user_mode(die_args->regs))
46024 xpc_die_deactivate();
46025
46026 break;
46027 diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
46028 index 452782b..0c10e40 100644
46029 --- a/drivers/mmc/card/block.c
46030 +++ b/drivers/mmc/card/block.c
46031 @@ -574,7 +574,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
46032 if (idata->ic.postsleep_min_us)
46033 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
46034
46035 - if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
46036 + if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
46037 err = -EFAULT;
46038 goto cmd_rel_host;
46039 }
46040 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
46041 index f51b5ba..86614a7 100644
46042 --- a/drivers/mmc/core/mmc_ops.c
46043 +++ b/drivers/mmc/core/mmc_ops.c
46044 @@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
46045 void *data_buf;
46046 int is_on_stack;
46047
46048 - is_on_stack = object_is_on_stack(buf);
46049 + is_on_stack = object_starts_on_stack(buf);
46050 if (is_on_stack) {
46051 /*
46052 * dma onto stack is unsafe/nonportable, but callers to this
46053 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
46054 index 6834977..824ee1b 100644
46055 --- a/drivers/mmc/host/dw_mmc.h
46056 +++ b/drivers/mmc/host/dw_mmc.h
46057 @@ -259,5 +259,5 @@ struct dw_mci_drv_data {
46058 int (*parse_dt)(struct dw_mci *host);
46059 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
46060 struct dw_mci_tuning_data *tuning_data);
46061 -};
46062 +} __do_const;
46063 #endif /* _DW_MMC_H_ */
46064 diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
46065 index 771c60a..12cb615 100644
46066 --- a/drivers/mmc/host/mmci.c
46067 +++ b/drivers/mmc/host/mmci.c
46068 @@ -1570,7 +1570,9 @@ static int mmci_probe(struct amba_device *dev,
46069 mmc->caps2 = plat->capabilities2;
46070
46071 if (variant->busy_detect) {
46072 - mmci_ops.card_busy = mmci_card_busy;
46073 + pax_open_kernel();
46074 + *(void **)&mmci_ops.card_busy = mmci_card_busy;
46075 + pax_close_kernel();
46076 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
46077 mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY;
46078 mmc->max_busy_timeout = 0;
46079 diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
46080 index b841bb7..d82712f5 100644
46081 --- a/drivers/mmc/host/sdhci-esdhc-imx.c
46082 +++ b/drivers/mmc/host/sdhci-esdhc-imx.c
46083 @@ -1031,9 +1031,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
46084 host->mmc->caps |= MMC_CAP_1_8V_DDR;
46085 }
46086
46087 - if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
46088 - sdhci_esdhc_ops.platform_execute_tuning =
46089 + if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
46090 + pax_open_kernel();
46091 + *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
46092 esdhc_executing_tuning;
46093 + pax_close_kernel();
46094 + }
46095
46096 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
46097 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
46098 diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
46099 index d61eb5a..88c0f5d 100644
46100 --- a/drivers/mmc/host/sdhci-s3c.c
46101 +++ b/drivers/mmc/host/sdhci-s3c.c
46102 @@ -657,9 +657,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
46103 * we can use overriding functions instead of default.
46104 */
46105 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
46106 - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
46107 - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
46108 - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
46109 + pax_open_kernel();
46110 + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
46111 + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
46112 + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
46113 + pax_close_kernel();
46114 }
46115
46116 /* It supports additional host capabilities if needed */
46117 diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
46118 index 6293855..3415551 100644
46119 --- a/drivers/mtd/chips/cfi_cmdset_0020.c
46120 +++ b/drivers/mtd/chips/cfi_cmdset_0020.c
46121 @@ -666,7 +666,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
46122 size_t totlen = 0, thislen;
46123 int ret = 0;
46124 size_t buflen = 0;
46125 - static char *buffer;
46126 + char *buffer;
46127
46128 if (!ECCBUF_SIZE) {
46129 /* We should fall back to a general writev implementation.
46130 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
46131 index c07cd57..61c4fbd 100644
46132 --- a/drivers/mtd/nand/denali.c
46133 +++ b/drivers/mtd/nand/denali.c
46134 @@ -24,6 +24,7 @@
46135 #include <linux/slab.h>
46136 #include <linux/mtd/mtd.h>
46137 #include <linux/module.h>
46138 +#include <linux/slab.h>
46139
46140 #include "denali.h"
46141
46142 diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
46143 index bb77f75..47539b1 100644
46144 --- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
46145 +++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
46146 @@ -370,7 +370,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
46147
46148 /* first try to map the upper buffer directly */
46149 if (virt_addr_valid(this->upper_buf) &&
46150 - !object_is_on_stack(this->upper_buf)) {
46151 + !object_starts_on_stack(this->upper_buf)) {
46152 sg_init_one(sgl, this->upper_buf, this->upper_len);
46153 ret = dma_map_sg(this->dev, sgl, 1, dr);
46154 if (ret == 0)
46155 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
46156 index 51b9d6a..52af9a7 100644
46157 --- a/drivers/mtd/nftlmount.c
46158 +++ b/drivers/mtd/nftlmount.c
46159 @@ -24,6 +24,7 @@
46160 #include <asm/errno.h>
46161 #include <linux/delay.h>
46162 #include <linux/slab.h>
46163 +#include <linux/sched.h>
46164 #include <linux/mtd/mtd.h>
46165 #include <linux/mtd/nand.h>
46166 #include <linux/mtd/nftl.h>
46167 diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
46168 index cf49c22..971b133 100644
46169 --- a/drivers/mtd/sm_ftl.c
46170 +++ b/drivers/mtd/sm_ftl.c
46171 @@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
46172 #define SM_CIS_VENDOR_OFFSET 0x59
46173 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
46174 {
46175 - struct attribute_group *attr_group;
46176 + attribute_group_no_const *attr_group;
46177 struct attribute **attributes;
46178 struct sm_sysfs_attribute *vendor_attribute;
46179 char *vendor;
46180 diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
46181 index f847e16..fc8dbe9 100644
46182 --- a/drivers/net/bonding/bond_netlink.c
46183 +++ b/drivers/net/bonding/bond_netlink.c
46184 @@ -542,7 +542,7 @@ nla_put_failure:
46185 return -EMSGSIZE;
46186 }
46187
46188 -struct rtnl_link_ops bond_link_ops __read_mostly = {
46189 +struct rtnl_link_ops bond_link_ops = {
46190 .kind = "bond",
46191 .priv_size = sizeof(struct bonding),
46192 .setup = bond_setup,
46193 diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
46194 index 9e7d95d..d447b88 100644
46195 --- a/drivers/net/can/Kconfig
46196 +++ b/drivers/net/can/Kconfig
46197 @@ -104,7 +104,7 @@ config CAN_JANZ_ICAN3
46198
46199 config CAN_FLEXCAN
46200 tristate "Support for Freescale FLEXCAN based chips"
46201 - depends on ARM || PPC
46202 + depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
46203 ---help---
46204 Say Y here if you want to support for Freescale FlexCAN.
46205
46206 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
46207 index 455d4c3..3353ee7 100644
46208 --- a/drivers/net/ethernet/8390/ax88796.c
46209 +++ b/drivers/net/ethernet/8390/ax88796.c
46210 @@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
46211 if (ax->plat->reg_offsets)
46212 ei_local->reg_offset = ax->plat->reg_offsets;
46213 else {
46214 + resource_size_t _mem_size = mem_size;
46215 + do_div(_mem_size, 0x18);
46216 ei_local->reg_offset = ax->reg_offsets;
46217 for (ret = 0; ret < 0x18; ret++)
46218 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
46219 + ax->reg_offsets[ret] = _mem_size * ret;
46220 }
46221
46222 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
46223 diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
46224 index 7330681..7e9e463 100644
46225 --- a/drivers/net/ethernet/altera/altera_tse_main.c
46226 +++ b/drivers/net/ethernet/altera/altera_tse_main.c
46227 @@ -1182,7 +1182,7 @@ static int tse_shutdown(struct net_device *dev)
46228 return 0;
46229 }
46230
46231 -static struct net_device_ops altera_tse_netdev_ops = {
46232 +static net_device_ops_no_const altera_tse_netdev_ops __read_only = {
46233 .ndo_open = tse_open,
46234 .ndo_stop = tse_shutdown,
46235 .ndo_start_xmit = tse_start_xmit,
46236 @@ -1439,11 +1439,13 @@ static int altera_tse_probe(struct platform_device *pdev)
46237 ndev->netdev_ops = &altera_tse_netdev_ops;
46238 altera_tse_set_ethtool_ops(ndev);
46239
46240 + pax_open_kernel();
46241 altera_tse_netdev_ops.ndo_set_rx_mode = tse_set_rx_mode;
46242
46243 if (priv->hash_filter)
46244 altera_tse_netdev_ops.ndo_set_rx_mode =
46245 tse_set_rx_mode_hashfilter;
46246 + pax_close_kernel();
46247
46248 /* Scatter/gather IO is not supported,
46249 * so it is turned off
46250 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
46251 index 3448cc0..67b2dc4 100644
46252 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
46253 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
46254 @@ -1058,7 +1058,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
46255 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
46256 {
46257 /* RX_MODE controlling object */
46258 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
46259 + bnx2x_init_rx_mode_obj(bp);
46260
46261 /* multicast configuration controlling object */
46262 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
46263 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
46264 index 31297266..944cf6e 100644
46265 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
46266 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
46267 @@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
46268 return rc;
46269 }
46270
46271 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
46272 - struct bnx2x_rx_mode_obj *o)
46273 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
46274 {
46275 if (CHIP_IS_E1x(bp)) {
46276 - o->wait_comp = bnx2x_empty_rx_mode_wait;
46277 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
46278 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
46279 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
46280 } else {
46281 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
46282 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
46283 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
46284 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
46285 }
46286 }
46287
46288 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
46289 index 80f6c79..fb7d12d 100644
46290 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
46291 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
46292 @@ -1340,8 +1340,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
46293
46294 /********************* RX MODE ****************/
46295
46296 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
46297 - struct bnx2x_rx_mode_obj *o);
46298 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
46299
46300 /**
46301 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
46302 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.h
46303 index 6929adb..cc68830 100644
46304 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.h
46305 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.h
46306 @@ -571,7 +571,7 @@ static inline void __iomem *bnx2x_vf_doorbells(struct bnx2x *bp)
46307 return NULL;
46308 }
46309
46310 -static inline void bnx2x_vf_pci_dealloc(struct bnx2 *bp) {return 0; }
46311 +static inline void bnx2x_vf_pci_dealloc(struct bnx2x *bp) { }
46312 static inline int bnx2x_vf_pci_alloc(struct bnx2x *bp) {return 0; }
46313 static inline void bnx2x_pf_set_vfs_vlan(struct bnx2x *bp) {}
46314 static inline int bnx2x_sriov_configure(struct pci_dev *dev, int num_vfs) {return 0; }
46315 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
46316 index 04321e5..b51cdc4 100644
46317 --- a/drivers/net/ethernet/broadcom/tg3.h
46318 +++ b/drivers/net/ethernet/broadcom/tg3.h
46319 @@ -150,6 +150,7 @@
46320 #define CHIPREV_ID_5750_A0 0x4000
46321 #define CHIPREV_ID_5750_A1 0x4001
46322 #define CHIPREV_ID_5750_A3 0x4003
46323 +#define CHIPREV_ID_5750_C1 0x4201
46324 #define CHIPREV_ID_5750_C2 0x4202
46325 #define CHIPREV_ID_5752_A0_HW 0x5000
46326 #define CHIPREV_ID_5752_A0 0x6000
46327 diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
46328 index 13f9636..228040f 100644
46329 --- a/drivers/net/ethernet/brocade/bna/bna_enet.c
46330 +++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
46331 @@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
46332 }
46333
46334 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
46335 - bna_cb_ioceth_enable,
46336 - bna_cb_ioceth_disable,
46337 - bna_cb_ioceth_hbfail,
46338 - bna_cb_ioceth_reset
46339 + .enable_cbfn = bna_cb_ioceth_enable,
46340 + .disable_cbfn = bna_cb_ioceth_disable,
46341 + .hbfail_cbfn = bna_cb_ioceth_hbfail,
46342 + .reset_cbfn = bna_cb_ioceth_reset
46343 };
46344
46345 static void bna_attr_init(struct bna_ioceth *ioceth)
46346 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
46347 index 8cffcdf..aadf043 100644
46348 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
46349 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
46350 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
46351 */
46352 struct l2t_skb_cb {
46353 arp_failure_handler_func arp_failure_handler;
46354 -};
46355 +} __no_const;
46356
46357 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
46358
46359 diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
46360 index 24e16e3..bfe6ef2 100644
46361 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
46362 +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
46363 @@ -2139,7 +2139,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
46364
46365 int i;
46366 struct adapter *ap = netdev2adap(dev);
46367 - static const unsigned int *reg_ranges;
46368 + const unsigned int *reg_ranges;
46369 int arr_size = 0, buf_size = 0;
46370
46371 if (is_t4(ap->params.chip)) {
46372 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
46373 index c05b66d..ed69872 100644
46374 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
46375 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
46376 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
46377 for (i=0; i<ETH_ALEN; i++) {
46378 tmp.addr[i] = dev->dev_addr[i];
46379 }
46380 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
46381 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
46382 break;
46383
46384 case DE4X5_SET_HWADDR: /* Set the hardware address */
46385 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
46386 spin_lock_irqsave(&lp->lock, flags);
46387 memcpy(&statbuf, &lp->pktStats, ioc->len);
46388 spin_unlock_irqrestore(&lp->lock, flags);
46389 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
46390 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
46391 return -EFAULT;
46392 break;
46393 }
46394 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
46395 index 2b5ab7c..20e2e7f 100644
46396 --- a/drivers/net/ethernet/emulex/benet/be_main.c
46397 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
46398 @@ -535,7 +535,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
46399
46400 if (wrapped)
46401 newacc += 65536;
46402 - ACCESS_ONCE(*acc) = newacc;
46403 + ACCESS_ONCE_RW(*acc) = newacc;
46404 }
46405
46406 static void populate_erx_stats(struct be_adapter *adapter,
46407 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
46408 index 68069ea..c4484f6 100644
46409 --- a/drivers/net/ethernet/faraday/ftgmac100.c
46410 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
46411 @@ -30,6 +30,8 @@
46412 #include <linux/netdevice.h>
46413 #include <linux/phy.h>
46414 #include <linux/platform_device.h>
46415 +#include <linux/interrupt.h>
46416 +#include <linux/irqreturn.h>
46417 #include <net/ip.h>
46418
46419 #include "ftgmac100.h"
46420 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
46421 index 8be5b40..081bc1b 100644
46422 --- a/drivers/net/ethernet/faraday/ftmac100.c
46423 +++ b/drivers/net/ethernet/faraday/ftmac100.c
46424 @@ -31,6 +31,8 @@
46425 #include <linux/module.h>
46426 #include <linux/netdevice.h>
46427 #include <linux/platform_device.h>
46428 +#include <linux/interrupt.h>
46429 +#include <linux/irqreturn.h>
46430
46431 #include "ftmac100.h"
46432
46433 diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
46434 index e61e637..9117795 100644
46435 --- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
46436 +++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
46437 @@ -436,7 +436,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
46438 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
46439
46440 /* Update the base adjustement value. */
46441 - ACCESS_ONCE(pf->ptp_base_adj) = incval;
46442 + ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
46443 smp_mb(); /* Force the above update. */
46444 }
46445
46446 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46447 index 8902ae6..e7bcdce 100644
46448 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46449 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46450 @@ -771,7 +771,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
46451 }
46452
46453 /* update the base incval used to calculate frequency adjustment */
46454 - ACCESS_ONCE(adapter->base_incval) = incval;
46455 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
46456 smp_mb();
46457
46458 /* need lock to prevent incorrect read while modifying cyclecounter */
46459 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
46460 index 089b713..28d87ae 100644
46461 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
46462 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
46463 @@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
46464 struct __vxge_hw_fifo *fifo;
46465 struct vxge_hw_fifo_config *config;
46466 u32 txdl_size, txdl_per_memblock;
46467 - struct vxge_hw_mempool_cbs fifo_mp_callback;
46468 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
46469 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
46470 + };
46471 +
46472 struct __vxge_hw_virtualpath *vpath;
46473
46474 if ((vp == NULL) || (attr == NULL)) {
46475 @@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
46476 goto exit;
46477 }
46478
46479 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
46480 -
46481 fifo->mempool =
46482 __vxge_hw_mempool_create(vpath->hldev,
46483 fifo->config->memblock_size,
46484 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46485 index ba20c72..f30c0fe 100644
46486 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46487 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46488 @@ -2176,7 +2176,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
46489 max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
46490 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
46491 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
46492 - adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
46493 + pax_open_kernel();
46494 + *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
46495 + pax_close_kernel();
46496 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46497 max_sds_rings = QLCNIC_MAX_SDS_RINGS;
46498 max_tx_rings = QLCNIC_MAX_TX_RINGS;
46499 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46500 index be7d7a6..a8983f8 100644
46501 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46502 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46503 @@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
46504 case QLCNIC_NON_PRIV_FUNC:
46505 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
46506 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46507 - nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
46508 + pax_open_kernel();
46509 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
46510 + pax_close_kernel();
46511 break;
46512 case QLCNIC_PRIV_FUNC:
46513 ahw->op_mode = QLCNIC_PRIV_FUNC;
46514 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
46515 - nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
46516 + pax_open_kernel();
46517 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
46518 + pax_close_kernel();
46519 break;
46520 case QLCNIC_MGMT_FUNC:
46521 ahw->op_mode = QLCNIC_MGMT_FUNC;
46522 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46523 - nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
46524 + pax_open_kernel();
46525 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
46526 + pax_close_kernel();
46527 break;
46528 default:
46529 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
46530 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46531 index 37b979b..50f5b95 100644
46532 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46533 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46534 @@ -1217,7 +1217,7 @@ flash_temp:
46535 int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
46536 {
46537 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
46538 - static const struct qlcnic_dump_operations *fw_dump_ops;
46539 + const struct qlcnic_dump_operations *fw_dump_ops;
46540 struct qlcnic_83xx_dump_template_hdr *hdr_83xx;
46541 u32 entry_offset, dump, no_entries, buf_offset = 0;
46542 int i, k, ops_cnt, ops_index, dump_size = 0;
46543 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
46544 index aa1c079..2b1a3e8 100644
46545 --- a/drivers/net/ethernet/realtek/r8169.c
46546 +++ b/drivers/net/ethernet/realtek/r8169.c
46547 @@ -758,22 +758,22 @@ struct rtl8169_private {
46548 struct mdio_ops {
46549 void (*write)(struct rtl8169_private *, int, int);
46550 int (*read)(struct rtl8169_private *, int);
46551 - } mdio_ops;
46552 + } __no_const mdio_ops;
46553
46554 struct pll_power_ops {
46555 void (*down)(struct rtl8169_private *);
46556 void (*up)(struct rtl8169_private *);
46557 - } pll_power_ops;
46558 + } __no_const pll_power_ops;
46559
46560 struct jumbo_ops {
46561 void (*enable)(struct rtl8169_private *);
46562 void (*disable)(struct rtl8169_private *);
46563 - } jumbo_ops;
46564 + } __no_const jumbo_ops;
46565
46566 struct csi_ops {
46567 void (*write)(struct rtl8169_private *, int, int);
46568 u32 (*read)(struct rtl8169_private *, int);
46569 - } csi_ops;
46570 + } __no_const csi_ops;
46571
46572 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
46573 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
46574 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
46575 index 6b861e3..204ac86 100644
46576 --- a/drivers/net/ethernet/sfc/ptp.c
46577 +++ b/drivers/net/ethernet/sfc/ptp.c
46578 @@ -822,7 +822,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
46579 ptp->start.dma_addr);
46580
46581 /* Clear flag that signals MC ready */
46582 - ACCESS_ONCE(*start) = 0;
46583 + ACCESS_ONCE_RW(*start) = 0;
46584 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
46585 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
46586 EFX_BUG_ON_PARANOID(rc);
46587 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46588 index 50617c5..b13724c 100644
46589 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46590 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46591 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
46592
46593 writel(value, ioaddr + MMC_CNTRL);
46594
46595 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46596 - MMC_CNTRL, value);
46597 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46598 +// MMC_CNTRL, value);
46599 }
46600
46601 /* To mask all all interrupts.*/
46602 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
46603 index d18f711d..5755800 100644
46604 --- a/drivers/net/hyperv/hyperv_net.h
46605 +++ b/drivers/net/hyperv/hyperv_net.h
46606 @@ -101,7 +101,7 @@ struct rndis_device {
46607
46608 enum rndis_device_state state;
46609 bool link_state;
46610 - atomic_t new_req_id;
46611 + atomic_unchecked_t new_req_id;
46612
46613 spinlock_t request_lock;
46614 struct list_head req_list;
46615 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
46616 index 143a98c..d54fbaa 100644
46617 --- a/drivers/net/hyperv/rndis_filter.c
46618 +++ b/drivers/net/hyperv/rndis_filter.c
46619 @@ -100,7 +100,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
46620 * template
46621 */
46622 set = &rndis_msg->msg.set_req;
46623 - set->req_id = atomic_inc_return(&dev->new_req_id);
46624 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46625
46626 /* Add to the request list */
46627 spin_lock_irqsave(&dev->request_lock, flags);
46628 @@ -834,7 +834,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
46629
46630 /* Setup the rndis set */
46631 halt = &request->request_msg.msg.halt_req;
46632 - halt->req_id = atomic_inc_return(&dev->new_req_id);
46633 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46634
46635 /* Ignore return since this msg is optional. */
46636 rndis_filter_send_request(dev, request);
46637 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
46638 index 78f18be..1d19c62 100644
46639 --- a/drivers/net/ieee802154/fakehard.c
46640 +++ b/drivers/net/ieee802154/fakehard.c
46641 @@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
46642 phy->transmit_power = 0xbf;
46643
46644 dev->netdev_ops = &fake_ops;
46645 - dev->ml_priv = &fake_mlme;
46646 + dev->ml_priv = (void *)&fake_mlme;
46647
46648 priv = netdev_priv(dev);
46649 priv->phy = phy;
46650 diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
46651 index d650b91..7717c68 100644
46652 --- a/drivers/net/macvlan.c
46653 +++ b/drivers/net/macvlan.c
46654 @@ -985,13 +985,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
46655 int macvlan_link_register(struct rtnl_link_ops *ops)
46656 {
46657 /* common fields */
46658 - ops->priv_size = sizeof(struct macvlan_dev);
46659 - ops->validate = macvlan_validate;
46660 - ops->maxtype = IFLA_MACVLAN_MAX;
46661 - ops->policy = macvlan_policy;
46662 - ops->changelink = macvlan_changelink;
46663 - ops->get_size = macvlan_get_size;
46664 - ops->fill_info = macvlan_fill_info;
46665 + pax_open_kernel();
46666 + *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
46667 + *(void **)&ops->validate = macvlan_validate;
46668 + *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
46669 + *(const void **)&ops->policy = macvlan_policy;
46670 + *(void **)&ops->changelink = macvlan_changelink;
46671 + *(void **)&ops->get_size = macvlan_get_size;
46672 + *(void **)&ops->fill_info = macvlan_fill_info;
46673 + pax_close_kernel();
46674
46675 return rtnl_link_register(ops);
46676 };
46677 @@ -1045,7 +1047,7 @@ static int macvlan_device_event(struct notifier_block *unused,
46678 return NOTIFY_DONE;
46679 }
46680
46681 -static struct notifier_block macvlan_notifier_block __read_mostly = {
46682 +static struct notifier_block macvlan_notifier_block = {
46683 .notifier_call = macvlan_device_event,
46684 };
46685
46686 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
46687 index 3381c4f..dea5fd5 100644
46688 --- a/drivers/net/macvtap.c
46689 +++ b/drivers/net/macvtap.c
46690 @@ -1020,7 +1020,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
46691 }
46692
46693 ret = 0;
46694 - if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46695 + if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46696 put_user(q->flags, &ifr->ifr_flags))
46697 ret = -EFAULT;
46698 macvtap_put_vlan(vlan);
46699 @@ -1190,7 +1190,7 @@ static int macvtap_device_event(struct notifier_block *unused,
46700 return NOTIFY_DONE;
46701 }
46702
46703 -static struct notifier_block macvtap_notifier_block __read_mostly = {
46704 +static struct notifier_block macvtap_notifier_block = {
46705 .notifier_call = macvtap_device_event,
46706 };
46707
46708 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
46709 index 3c41a83..5fe2d7f 100644
46710 --- a/drivers/net/ppp/ppp_generic.c
46711 +++ b/drivers/net/ppp/ppp_generic.c
46712 @@ -1016,7 +1016,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46713 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
46714 struct ppp_stats stats;
46715 struct ppp_comp_stats cstats;
46716 - char *vers;
46717
46718 switch (cmd) {
46719 case SIOCGPPPSTATS:
46720 @@ -1038,8 +1037,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46721 break;
46722
46723 case SIOCGPPPVER:
46724 - vers = PPP_VERSION;
46725 - if (copy_to_user(addr, vers, strlen(vers) + 1))
46726 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
46727 break;
46728 err = 0;
46729 break;
46730 diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
46731 index 1252d9c..80e660b 100644
46732 --- a/drivers/net/slip/slhc.c
46733 +++ b/drivers/net/slip/slhc.c
46734 @@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
46735 register struct tcphdr *thp;
46736 register struct iphdr *ip;
46737 register struct cstate *cs;
46738 - int len, hdrlen;
46739 + long len, hdrlen;
46740 unsigned char *cp = icp;
46741
46742 /* We've got a compressed packet; read the change byte */
46743 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
46744 index ce4989b..b40b328 100644
46745 --- a/drivers/net/team/team.c
46746 +++ b/drivers/net/team/team.c
46747 @@ -2868,7 +2868,7 @@ static int team_device_event(struct notifier_block *unused,
46748 return NOTIFY_DONE;
46749 }
46750
46751 -static struct notifier_block team_notifier_block __read_mostly = {
46752 +static struct notifier_block team_notifier_block = {
46753 .notifier_call = team_device_event,
46754 };
46755
46756 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
46757 index ee328ba..c4a0041 100644
46758 --- a/drivers/net/tun.c
46759 +++ b/drivers/net/tun.c
46760 @@ -1876,7 +1876,7 @@ unlock:
46761 }
46762
46763 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46764 - unsigned long arg, int ifreq_len)
46765 + unsigned long arg, size_t ifreq_len)
46766 {
46767 struct tun_file *tfile = file->private_data;
46768 struct tun_struct *tun;
46769 @@ -1889,6 +1889,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46770 unsigned int ifindex;
46771 int ret;
46772
46773 + if (ifreq_len > sizeof ifr)
46774 + return -EFAULT;
46775 +
46776 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
46777 if (copy_from_user(&ifr, argp, ifreq_len))
46778 return -EFAULT;
46779 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
46780 index 660bd5e..ac59452 100644
46781 --- a/drivers/net/usb/hso.c
46782 +++ b/drivers/net/usb/hso.c
46783 @@ -71,7 +71,7 @@
46784 #include <asm/byteorder.h>
46785 #include <linux/serial_core.h>
46786 #include <linux/serial.h>
46787 -
46788 +#include <asm/local.h>
46789
46790 #define MOD_AUTHOR "Option Wireless"
46791 #define MOD_DESCRIPTION "USB High Speed Option driver"
46792 @@ -1179,7 +1179,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
46793 struct urb *urb;
46794
46795 urb = serial->rx_urb[0];
46796 - if (serial->port.count > 0) {
46797 + if (atomic_read(&serial->port.count) > 0) {
46798 count = put_rxbuf_data(urb, serial);
46799 if (count == -1)
46800 return;
46801 @@ -1217,7 +1217,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
46802 DUMP1(urb->transfer_buffer, urb->actual_length);
46803
46804 /* Anyone listening? */
46805 - if (serial->port.count == 0)
46806 + if (atomic_read(&serial->port.count) == 0)
46807 return;
46808
46809 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
46810 @@ -1287,8 +1287,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46811 tty_port_tty_set(&serial->port, tty);
46812
46813 /* check for port already opened, if not set the termios */
46814 - serial->port.count++;
46815 - if (serial->port.count == 1) {
46816 + if (atomic_inc_return(&serial->port.count) == 1) {
46817 serial->rx_state = RX_IDLE;
46818 /* Force default termio settings */
46819 _hso_serial_set_termios(tty, NULL);
46820 @@ -1300,7 +1299,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46821 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
46822 if (result) {
46823 hso_stop_serial_device(serial->parent);
46824 - serial->port.count--;
46825 + atomic_dec(&serial->port.count);
46826 kref_put(&serial->parent->ref, hso_serial_ref_free);
46827 }
46828 } else {
46829 @@ -1337,10 +1336,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
46830
46831 /* reset the rts and dtr */
46832 /* do the actual close */
46833 - serial->port.count--;
46834 + atomic_dec(&serial->port.count);
46835
46836 - if (serial->port.count <= 0) {
46837 - serial->port.count = 0;
46838 + if (atomic_read(&serial->port.count) <= 0) {
46839 + atomic_set(&serial->port.count, 0);
46840 tty_port_tty_set(&serial->port, NULL);
46841 if (!usb_gone)
46842 hso_stop_serial_device(serial->parent);
46843 @@ -1416,7 +1415,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
46844
46845 /* the actual setup */
46846 spin_lock_irqsave(&serial->serial_lock, flags);
46847 - if (serial->port.count)
46848 + if (atomic_read(&serial->port.count))
46849 _hso_serial_set_termios(tty, old);
46850 else
46851 tty->termios = *old;
46852 @@ -1885,7 +1884,7 @@ static void intr_callback(struct urb *urb)
46853 D1("Pending read interrupt on port %d\n", i);
46854 spin_lock(&serial->serial_lock);
46855 if (serial->rx_state == RX_IDLE &&
46856 - serial->port.count > 0) {
46857 + atomic_read(&serial->port.count) > 0) {
46858 /* Setup and send a ctrl req read on
46859 * port i */
46860 if (!serial->rx_urb_filled[0]) {
46861 @@ -3061,7 +3060,7 @@ static int hso_resume(struct usb_interface *iface)
46862 /* Start all serial ports */
46863 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
46864 if (serial_table[i] && (serial_table[i]->interface == iface)) {
46865 - if (dev2ser(serial_table[i])->port.count) {
46866 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
46867 result =
46868 hso_start_serial_device(serial_table[i], GFP_NOIO);
46869 hso_kick_transmit(dev2ser(serial_table[i]));
46870 diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
46871 index d2c0070..3c3da43 100644
46872 --- a/drivers/net/usb/r8152.c
46873 +++ b/drivers/net/usb/r8152.c
46874 @@ -567,7 +567,7 @@ struct r8152 {
46875 void (*up)(struct r8152 *);
46876 void (*down)(struct r8152 *);
46877 void (*unload)(struct r8152 *);
46878 - } rtl_ops;
46879 + } __no_const rtl_ops;
46880
46881 int intr_interval;
46882 u32 saved_wolopts;
46883 diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
46884 index a2515887..6d13233 100644
46885 --- a/drivers/net/usb/sierra_net.c
46886 +++ b/drivers/net/usb/sierra_net.c
46887 @@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
46888 /* atomic counter partially included in MAC address to make sure 2 devices
46889 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
46890 */
46891 -static atomic_t iface_counter = ATOMIC_INIT(0);
46892 +static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
46893
46894 /*
46895 * SYNC Timer Delay definition used to set the expiry time
46896 @@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
46897 dev->net->netdev_ops = &sierra_net_device_ops;
46898
46899 /* change MAC addr to include, ifacenum, and to be unique */
46900 - dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
46901 + dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
46902 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
46903
46904 /* we will have to manufacture ethernet headers, prepare template */
46905 diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
46906 index 8a852b5..668a4b6 100644
46907 --- a/drivers/net/virtio_net.c
46908 +++ b/drivers/net/virtio_net.c
46909 @@ -47,7 +47,7 @@ module_param(gso, bool, 0444);
46910 #define RECEIVE_AVG_WEIGHT 64
46911
46912 /* Minimum alignment for mergeable packet buffers. */
46913 -#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256)
46914 +#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256UL)
46915
46916 #define VIRTNET_DRIVER_VERSION "1.0.0"
46917
46918 diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
46919 index 77dcf92..549924a 100644
46920 --- a/drivers/net/vxlan.c
46921 +++ b/drivers/net/vxlan.c
46922 @@ -2839,7 +2839,7 @@ nla_put_failure:
46923 return -EMSGSIZE;
46924 }
46925
46926 -static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
46927 +static struct rtnl_link_ops vxlan_link_ops = {
46928 .kind = "vxlan",
46929 .maxtype = IFLA_VXLAN_MAX,
46930 .policy = vxlan_policy,
46931 @@ -2886,7 +2886,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
46932 return NOTIFY_DONE;
46933 }
46934
46935 -static struct notifier_block vxlan_notifier_block __read_mostly = {
46936 +static struct notifier_block vxlan_notifier_block = {
46937 .notifier_call = vxlan_lowerdev_event,
46938 };
46939
46940 diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
46941 index 5920c99..ff2e4a5 100644
46942 --- a/drivers/net/wan/lmc/lmc_media.c
46943 +++ b/drivers/net/wan/lmc/lmc_media.c
46944 @@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
46945 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
46946
46947 lmc_media_t lmc_ds3_media = {
46948 - lmc_ds3_init, /* special media init stuff */
46949 - lmc_ds3_default, /* reset to default state */
46950 - lmc_ds3_set_status, /* reset status to state provided */
46951 - lmc_dummy_set_1, /* set clock source */
46952 - lmc_dummy_set2_1, /* set line speed */
46953 - lmc_ds3_set_100ft, /* set cable length */
46954 - lmc_ds3_set_scram, /* set scrambler */
46955 - lmc_ds3_get_link_status, /* get link status */
46956 - lmc_dummy_set_1, /* set link status */
46957 - lmc_ds3_set_crc_length, /* set CRC length */
46958 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
46959 - lmc_ds3_watchdog
46960 + .init = lmc_ds3_init, /* special media init stuff */
46961 + .defaults = lmc_ds3_default, /* reset to default state */
46962 + .set_status = lmc_ds3_set_status, /* reset status to state provided */
46963 + .set_clock_source = lmc_dummy_set_1, /* set clock source */
46964 + .set_speed = lmc_dummy_set2_1, /* set line speed */
46965 + .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
46966 + .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
46967 + .get_link_status = lmc_ds3_get_link_status, /* get link status */
46968 + .set_link_status = lmc_dummy_set_1, /* set link status */
46969 + .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
46970 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46971 + .watchdog = lmc_ds3_watchdog
46972 };
46973
46974 lmc_media_t lmc_hssi_media = {
46975 - lmc_hssi_init, /* special media init stuff */
46976 - lmc_hssi_default, /* reset to default state */
46977 - lmc_hssi_set_status, /* reset status to state provided */
46978 - lmc_hssi_set_clock, /* set clock source */
46979 - lmc_dummy_set2_1, /* set line speed */
46980 - lmc_dummy_set_1, /* set cable length */
46981 - lmc_dummy_set_1, /* set scrambler */
46982 - lmc_hssi_get_link_status, /* get link status */
46983 - lmc_hssi_set_link_status, /* set link status */
46984 - lmc_hssi_set_crc_length, /* set CRC length */
46985 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
46986 - lmc_hssi_watchdog
46987 + .init = lmc_hssi_init, /* special media init stuff */
46988 + .defaults = lmc_hssi_default, /* reset to default state */
46989 + .set_status = lmc_hssi_set_status, /* reset status to state provided */
46990 + .set_clock_source = lmc_hssi_set_clock, /* set clock source */
46991 + .set_speed = lmc_dummy_set2_1, /* set line speed */
46992 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
46993 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46994 + .get_link_status = lmc_hssi_get_link_status, /* get link status */
46995 + .set_link_status = lmc_hssi_set_link_status, /* set link status */
46996 + .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
46997 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46998 + .watchdog = lmc_hssi_watchdog
46999 };
47000
47001 -lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
47002 - lmc_ssi_default, /* reset to default state */
47003 - lmc_ssi_set_status, /* reset status to state provided */
47004 - lmc_ssi_set_clock, /* set clock source */
47005 - lmc_ssi_set_speed, /* set line speed */
47006 - lmc_dummy_set_1, /* set cable length */
47007 - lmc_dummy_set_1, /* set scrambler */
47008 - lmc_ssi_get_link_status, /* get link status */
47009 - lmc_ssi_set_link_status, /* set link status */
47010 - lmc_ssi_set_crc_length, /* set CRC length */
47011 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
47012 - lmc_ssi_watchdog
47013 +lmc_media_t lmc_ssi_media = {
47014 + .init = lmc_ssi_init, /* special media init stuff */
47015 + .defaults = lmc_ssi_default, /* reset to default state */
47016 + .set_status = lmc_ssi_set_status, /* reset status to state provided */
47017 + .set_clock_source = lmc_ssi_set_clock, /* set clock source */
47018 + .set_speed = lmc_ssi_set_speed, /* set line speed */
47019 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
47020 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
47021 + .get_link_status = lmc_ssi_get_link_status, /* get link status */
47022 + .set_link_status = lmc_ssi_set_link_status, /* set link status */
47023 + .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
47024 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
47025 + .watchdog = lmc_ssi_watchdog
47026 };
47027
47028 lmc_media_t lmc_t1_media = {
47029 - lmc_t1_init, /* special media init stuff */
47030 - lmc_t1_default, /* reset to default state */
47031 - lmc_t1_set_status, /* reset status to state provided */
47032 - lmc_t1_set_clock, /* set clock source */
47033 - lmc_dummy_set2_1, /* set line speed */
47034 - lmc_dummy_set_1, /* set cable length */
47035 - lmc_dummy_set_1, /* set scrambler */
47036 - lmc_t1_get_link_status, /* get link status */
47037 - lmc_dummy_set_1, /* set link status */
47038 - lmc_t1_set_crc_length, /* set CRC length */
47039 - lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
47040 - lmc_t1_watchdog
47041 + .init = lmc_t1_init, /* special media init stuff */
47042 + .defaults = lmc_t1_default, /* reset to default state */
47043 + .set_status = lmc_t1_set_status, /* reset status to state provided */
47044 + .set_clock_source = lmc_t1_set_clock, /* set clock source */
47045 + .set_speed = lmc_dummy_set2_1, /* set line speed */
47046 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
47047 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
47048 + .get_link_status = lmc_t1_get_link_status, /* get link status */
47049 + .set_link_status = lmc_dummy_set_1, /* set link status */
47050 + .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
47051 + .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
47052 + .watchdog = lmc_t1_watchdog
47053 };
47054
47055 static void
47056 diff --git a/drivers/net/wan/x25_asy.c b/drivers/net/wan/x25_asy.c
47057 index 5895f19..fa9fdfa 100644
47058 --- a/drivers/net/wan/x25_asy.c
47059 +++ b/drivers/net/wan/x25_asy.c
47060 @@ -122,8 +122,12 @@ static int x25_asy_change_mtu(struct net_device *dev, int newmtu)
47061 {
47062 struct x25_asy *sl = netdev_priv(dev);
47063 unsigned char *xbuff, *rbuff;
47064 - int len = 2 * newmtu;
47065 + int len;
47066
47067 + if (newmtu > 65534)
47068 + return -EINVAL;
47069 +
47070 + len = 2 * newmtu;
47071 xbuff = kmalloc(len + 4, GFP_ATOMIC);
47072 rbuff = kmalloc(len + 4, GFP_ATOMIC);
47073
47074 diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
47075 index feacc3b..5bac0de 100644
47076 --- a/drivers/net/wan/z85230.c
47077 +++ b/drivers/net/wan/z85230.c
47078 @@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
47079
47080 struct z8530_irqhandler z8530_sync =
47081 {
47082 - z8530_rx,
47083 - z8530_tx,
47084 - z8530_status
47085 + .rx = z8530_rx,
47086 + .tx = z8530_tx,
47087 + .status = z8530_status
47088 };
47089
47090 EXPORT_SYMBOL(z8530_sync);
47091 @@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
47092 }
47093
47094 static struct z8530_irqhandler z8530_dma_sync = {
47095 - z8530_dma_rx,
47096 - z8530_dma_tx,
47097 - z8530_dma_status
47098 + .rx = z8530_dma_rx,
47099 + .tx = z8530_dma_tx,
47100 + .status = z8530_dma_status
47101 };
47102
47103 static struct z8530_irqhandler z8530_txdma_sync = {
47104 - z8530_rx,
47105 - z8530_dma_tx,
47106 - z8530_dma_status
47107 + .rx = z8530_rx,
47108 + .tx = z8530_dma_tx,
47109 + .status = z8530_dma_status
47110 };
47111
47112 /**
47113 @@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
47114
47115 struct z8530_irqhandler z8530_nop=
47116 {
47117 - z8530_rx_clear,
47118 - z8530_tx_clear,
47119 - z8530_status_clear
47120 + .rx = z8530_rx_clear,
47121 + .tx = z8530_tx_clear,
47122 + .status = z8530_status_clear
47123 };
47124
47125
47126 diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
47127 index 0b60295..b8bfa5b 100644
47128 --- a/drivers/net/wimax/i2400m/rx.c
47129 +++ b/drivers/net/wimax/i2400m/rx.c
47130 @@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
47131 if (i2400m->rx_roq == NULL)
47132 goto error_roq_alloc;
47133
47134 - rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
47135 + rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
47136 GFP_KERNEL);
47137 if (rd == NULL) {
47138 result = -ENOMEM;
47139 diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
47140 index 64747d4..17c4cf3 100644
47141 --- a/drivers/net/wireless/airo.c
47142 +++ b/drivers/net/wireless/airo.c
47143 @@ -7846,7 +7846,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
47144 struct airo_info *ai = dev->ml_priv;
47145 int ridcode;
47146 int enabled;
47147 - static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
47148 + int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
47149 unsigned char *iobuf;
47150
47151 /* Only super-user can write RIDs */
47152 diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
47153 index 99b3bfa..9559372 100644
47154 --- a/drivers/net/wireless/at76c50x-usb.c
47155 +++ b/drivers/net/wireless/at76c50x-usb.c
47156 @@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
47157 }
47158
47159 /* Convert timeout from the DFU status to jiffies */
47160 -static inline unsigned long at76_get_timeout(struct dfu_status *s)
47161 +static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
47162 {
47163 return msecs_to_jiffies((s->poll_timeout[2] << 16)
47164 | (s->poll_timeout[1] << 8)
47165 diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
47166 index 7f1bccd..ca2ffca 100644
47167 --- a/drivers/net/wireless/ath/ath10k/htc.c
47168 +++ b/drivers/net/wireless/ath/ath10k/htc.c
47169 @@ -840,7 +840,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
47170 /* registered target arrival callback from the HIF layer */
47171 int ath10k_htc_init(struct ath10k *ar)
47172 {
47173 - struct ath10k_hif_cb htc_callbacks;
47174 + static struct ath10k_hif_cb htc_callbacks = {
47175 + .rx_completion = ath10k_htc_rx_completion_handler,
47176 + .tx_completion = ath10k_htc_tx_completion_handler,
47177 + };
47178 struct ath10k_htc_ep *ep = NULL;
47179 struct ath10k_htc *htc = &ar->htc;
47180
47181 @@ -850,8 +853,6 @@ int ath10k_htc_init(struct ath10k *ar)
47182 ath10k_htc_reset_endpoint_states(htc);
47183
47184 /* setup HIF layer callbacks */
47185 - htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
47186 - htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
47187 htc->ar = ar;
47188
47189 /* Get HIF default pipe for HTC message exchange */
47190 diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
47191 index 4716d33..a688310 100644
47192 --- a/drivers/net/wireless/ath/ath10k/htc.h
47193 +++ b/drivers/net/wireless/ath/ath10k/htc.h
47194 @@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
47195
47196 struct ath10k_htc_ops {
47197 void (*target_send_suspend_complete)(struct ath10k *ar);
47198 -};
47199 +} __no_const;
47200
47201 struct ath10k_htc_ep_ops {
47202 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
47203 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
47204 void (*ep_tx_credits)(struct ath10k *);
47205 -};
47206 +} __no_const;
47207
47208 /* service connection information */
47209 struct ath10k_htc_svc_conn_req {
47210 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
47211 index 741b38d..b7ae41b 100644
47212 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
47213 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
47214 @@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47215 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
47216 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
47217
47218 - ACCESS_ONCE(ads->ds_link) = i->link;
47219 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
47220 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
47221 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
47222
47223 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
47224 ctl6 = SM(i->keytype, AR_EncrType);
47225 @@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47226
47227 if ((i->is_first || i->is_last) &&
47228 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
47229 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
47230 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
47231 | set11nTries(i->rates, 1)
47232 | set11nTries(i->rates, 2)
47233 | set11nTries(i->rates, 3)
47234 | (i->dur_update ? AR_DurUpdateEna : 0)
47235 | SM(0, AR_BurstDur);
47236
47237 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
47238 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
47239 | set11nRate(i->rates, 1)
47240 | set11nRate(i->rates, 2)
47241 | set11nRate(i->rates, 3);
47242 } else {
47243 - ACCESS_ONCE(ads->ds_ctl2) = 0;
47244 - ACCESS_ONCE(ads->ds_ctl3) = 0;
47245 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
47246 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
47247 }
47248
47249 if (!i->is_first) {
47250 - ACCESS_ONCE(ads->ds_ctl0) = 0;
47251 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
47252 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
47253 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
47254 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
47255 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
47256 return;
47257 }
47258
47259 @@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47260 break;
47261 }
47262
47263 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
47264 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
47265 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
47266 | SM(i->txpower, AR_XmitPower)
47267 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
47268 @@ -289,19 +289,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47269 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
47270 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
47271
47272 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
47273 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
47274 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
47275 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
47276
47277 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
47278 return;
47279
47280 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
47281 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
47282 | set11nPktDurRTSCTS(i->rates, 1);
47283
47284 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
47285 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
47286 | set11nPktDurRTSCTS(i->rates, 3);
47287
47288 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
47289 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
47290 | set11nRateFlags(i->rates, 1)
47291 | set11nRateFlags(i->rates, 2)
47292 | set11nRateFlags(i->rates, 3)
47293 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
47294 index 729ffbf..49f50e3 100644
47295 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
47296 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
47297 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47298 (i->qcu << AR_TxQcuNum_S) | desc_len;
47299
47300 checksum += val;
47301 - ACCESS_ONCE(ads->info) = val;
47302 + ACCESS_ONCE_RW(ads->info) = val;
47303
47304 checksum += i->link;
47305 - ACCESS_ONCE(ads->link) = i->link;
47306 + ACCESS_ONCE_RW(ads->link) = i->link;
47307
47308 checksum += i->buf_addr[0];
47309 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
47310 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
47311 checksum += i->buf_addr[1];
47312 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
47313 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
47314 checksum += i->buf_addr[2];
47315 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
47316 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
47317 checksum += i->buf_addr[3];
47318 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
47319 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
47320
47321 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
47322 - ACCESS_ONCE(ads->ctl3) = val;
47323 + ACCESS_ONCE_RW(ads->ctl3) = val;
47324 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
47325 - ACCESS_ONCE(ads->ctl5) = val;
47326 + ACCESS_ONCE_RW(ads->ctl5) = val;
47327 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
47328 - ACCESS_ONCE(ads->ctl7) = val;
47329 + ACCESS_ONCE_RW(ads->ctl7) = val;
47330 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
47331 - ACCESS_ONCE(ads->ctl9) = val;
47332 + ACCESS_ONCE_RW(ads->ctl9) = val;
47333
47334 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
47335 - ACCESS_ONCE(ads->ctl10) = checksum;
47336 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
47337
47338 if (i->is_first || i->is_last) {
47339 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
47340 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
47341 | set11nTries(i->rates, 1)
47342 | set11nTries(i->rates, 2)
47343 | set11nTries(i->rates, 3)
47344 | (i->dur_update ? AR_DurUpdateEna : 0)
47345 | SM(0, AR_BurstDur);
47346
47347 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
47348 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
47349 | set11nRate(i->rates, 1)
47350 | set11nRate(i->rates, 2)
47351 | set11nRate(i->rates, 3);
47352 } else {
47353 - ACCESS_ONCE(ads->ctl13) = 0;
47354 - ACCESS_ONCE(ads->ctl14) = 0;
47355 + ACCESS_ONCE_RW(ads->ctl13) = 0;
47356 + ACCESS_ONCE_RW(ads->ctl14) = 0;
47357 }
47358
47359 ads->ctl20 = 0;
47360 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47361
47362 ctl17 = SM(i->keytype, AR_EncrType);
47363 if (!i->is_first) {
47364 - ACCESS_ONCE(ads->ctl11) = 0;
47365 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
47366 - ACCESS_ONCE(ads->ctl15) = 0;
47367 - ACCESS_ONCE(ads->ctl16) = 0;
47368 - ACCESS_ONCE(ads->ctl17) = ctl17;
47369 - ACCESS_ONCE(ads->ctl18) = 0;
47370 - ACCESS_ONCE(ads->ctl19) = 0;
47371 + ACCESS_ONCE_RW(ads->ctl11) = 0;
47372 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
47373 + ACCESS_ONCE_RW(ads->ctl15) = 0;
47374 + ACCESS_ONCE_RW(ads->ctl16) = 0;
47375 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
47376 + ACCESS_ONCE_RW(ads->ctl18) = 0;
47377 + ACCESS_ONCE_RW(ads->ctl19) = 0;
47378 return;
47379 }
47380
47381 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
47382 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
47383 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
47384 | SM(i->txpower, AR_XmitPower)
47385 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
47386 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47387 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
47388 ctl12 |= SM(val, AR_PAPRDChainMask);
47389
47390 - ACCESS_ONCE(ads->ctl12) = ctl12;
47391 - ACCESS_ONCE(ads->ctl17) = ctl17;
47392 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
47393 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
47394
47395 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
47396 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
47397 | set11nPktDurRTSCTS(i->rates, 1);
47398
47399 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
47400 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
47401 | set11nPktDurRTSCTS(i->rates, 3);
47402
47403 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
47404 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
47405 | set11nRateFlags(i->rates, 1)
47406 | set11nRateFlags(i->rates, 2)
47407 | set11nRateFlags(i->rates, 3)
47408 | SM(i->rtscts_rate, AR_RTSCTSRate);
47409
47410 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
47411 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
47412 }
47413
47414 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
47415 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
47416 index 0acd4b5..0591c91 100644
47417 --- a/drivers/net/wireless/ath/ath9k/hw.h
47418 +++ b/drivers/net/wireless/ath/ath9k/hw.h
47419 @@ -629,7 +629,7 @@ struct ath_hw_private_ops {
47420
47421 /* ANI */
47422 void (*ani_cache_ini_regs)(struct ath_hw *ah);
47423 -};
47424 +} __no_const;
47425
47426 /**
47427 * struct ath_spec_scan - parameters for Atheros spectral scan
47428 @@ -706,7 +706,7 @@ struct ath_hw_ops {
47429 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
47430 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
47431 #endif
47432 -};
47433 +} __no_const;
47434
47435 struct ath_nf_limits {
47436 s16 max;
47437 diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
47438 index 92190da..f3a4c4c 100644
47439 --- a/drivers/net/wireless/b43/phy_lp.c
47440 +++ b/drivers/net/wireless/b43/phy_lp.c
47441 @@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
47442 {
47443 struct ssb_bus *bus = dev->dev->sdev->bus;
47444
47445 - static const struct b206x_channel *chandata = NULL;
47446 + const struct b206x_channel *chandata = NULL;
47447 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
47448 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
47449 u16 old_comm15, scale;
47450 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
47451 index dc1d20c..f7a4f06 100644
47452 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
47453 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
47454 @@ -3633,7 +3633,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
47455 */
47456 if (il3945_mod_params.disable_hw_scan) {
47457 D_INFO("Disabling hw_scan\n");
47458 - il3945_mac_ops.hw_scan = NULL;
47459 + pax_open_kernel();
47460 + *(void **)&il3945_mac_ops.hw_scan = NULL;
47461 + pax_close_kernel();
47462 }
47463
47464 D_INFO("*** LOAD DRIVER ***\n");
47465 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47466 index d2fe259..0c4c682 100644
47467 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47468 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47469 @@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
47470 {
47471 struct iwl_priv *priv = file->private_data;
47472 char buf[64];
47473 - int buf_size;
47474 + size_t buf_size;
47475 u32 offset, len;
47476
47477 memset(buf, 0, sizeof(buf));
47478 @@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
47479 struct iwl_priv *priv = file->private_data;
47480
47481 char buf[8];
47482 - int buf_size;
47483 + size_t buf_size;
47484 u32 reset_flag;
47485
47486 memset(buf, 0, sizeof(buf));
47487 @@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
47488 {
47489 struct iwl_priv *priv = file->private_data;
47490 char buf[8];
47491 - int buf_size;
47492 + size_t buf_size;
47493 int ht40;
47494
47495 memset(buf, 0, sizeof(buf));
47496 @@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
47497 {
47498 struct iwl_priv *priv = file->private_data;
47499 char buf[8];
47500 - int buf_size;
47501 + size_t buf_size;
47502 int value;
47503
47504 memset(buf, 0, sizeof(buf));
47505 @@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
47506 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
47507 DEBUGFS_READ_FILE_OPS(current_sleep_command);
47508
47509 -static const char *fmt_value = " %-30s %10u\n";
47510 -static const char *fmt_hex = " %-30s 0x%02X\n";
47511 -static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
47512 -static const char *fmt_header =
47513 +static const char fmt_value[] = " %-30s %10u\n";
47514 +static const char fmt_hex[] = " %-30s 0x%02X\n";
47515 +static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
47516 +static const char fmt_header[] =
47517 "%-32s current cumulative delta max\n";
47518
47519 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
47520 @@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
47521 {
47522 struct iwl_priv *priv = file->private_data;
47523 char buf[8];
47524 - int buf_size;
47525 + size_t buf_size;
47526 int clear;
47527
47528 memset(buf, 0, sizeof(buf));
47529 @@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
47530 {
47531 struct iwl_priv *priv = file->private_data;
47532 char buf[8];
47533 - int buf_size;
47534 + size_t buf_size;
47535 int trace;
47536
47537 memset(buf, 0, sizeof(buf));
47538 @@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
47539 {
47540 struct iwl_priv *priv = file->private_data;
47541 char buf[8];
47542 - int buf_size;
47543 + size_t buf_size;
47544 int missed;
47545
47546 memset(buf, 0, sizeof(buf));
47547 @@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
47548
47549 struct iwl_priv *priv = file->private_data;
47550 char buf[8];
47551 - int buf_size;
47552 + size_t buf_size;
47553 int plcp;
47554
47555 memset(buf, 0, sizeof(buf));
47556 @@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
47557
47558 struct iwl_priv *priv = file->private_data;
47559 char buf[8];
47560 - int buf_size;
47561 + size_t buf_size;
47562 int flush;
47563
47564 memset(buf, 0, sizeof(buf));
47565 @@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
47566
47567 struct iwl_priv *priv = file->private_data;
47568 char buf[8];
47569 - int buf_size;
47570 + size_t buf_size;
47571 int rts;
47572
47573 if (!priv->cfg->ht_params)
47574 @@ -2205,7 +2205,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
47575 {
47576 struct iwl_priv *priv = file->private_data;
47577 char buf[8];
47578 - int buf_size;
47579 + size_t buf_size;
47580
47581 memset(buf, 0, sizeof(buf));
47582 buf_size = min(count, sizeof(buf) - 1);
47583 @@ -2239,7 +2239,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
47584 struct iwl_priv *priv = file->private_data;
47585 u32 event_log_flag;
47586 char buf[8];
47587 - int buf_size;
47588 + size_t buf_size;
47589
47590 /* check that the interface is up */
47591 if (!iwl_is_ready(priv))
47592 @@ -2293,7 +2293,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
47593 struct iwl_priv *priv = file->private_data;
47594 char buf[8];
47595 u32 calib_disabled;
47596 - int buf_size;
47597 + size_t buf_size;
47598
47599 memset(buf, 0, sizeof(buf));
47600 buf_size = min(count, sizeof(buf) - 1);
47601 diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
47602 index 6a6df71..eb5c93a 100644
47603 --- a/drivers/net/wireless/iwlwifi/dvm/main.c
47604 +++ b/drivers/net/wireless/iwlwifi/dvm/main.c
47605 @@ -1127,7 +1127,7 @@ static void iwl_option_config(struct iwl_priv *priv)
47606 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47607 {
47608 struct iwl_nvm_data *data = priv->nvm_data;
47609 - char *debug_msg;
47610 + static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47611
47612 if (data->sku_cap_11n_enable &&
47613 !priv->cfg->ht_params) {
47614 @@ -1141,7 +1141,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47615 return -EINVAL;
47616 }
47617
47618 - debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47619 IWL_DEBUG_INFO(priv, debug_msg,
47620 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
47621 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
47622 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
47623 index 295b24c..cb4f823 100644
47624 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
47625 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
47626 @@ -1558,7 +1558,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
47627 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
47628
47629 char buf[8];
47630 - int buf_size;
47631 + size_t buf_size;
47632 u32 reset_flag;
47633
47634 memset(buf, 0, sizeof(buf));
47635 @@ -1579,7 +1579,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
47636 {
47637 struct iwl_trans *trans = file->private_data;
47638 char buf[8];
47639 - int buf_size;
47640 + size_t buf_size;
47641 int csr;
47642
47643 memset(buf, 0, sizeof(buf));
47644 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
47645 index 9d7a52f..2729a99 100644
47646 --- a/drivers/net/wireless/mac80211_hwsim.c
47647 +++ b/drivers/net/wireless/mac80211_hwsim.c
47648 @@ -2570,20 +2570,20 @@ static int __init init_mac80211_hwsim(void)
47649 if (channels < 1)
47650 return -EINVAL;
47651
47652 - mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
47653 - mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47654 - mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47655 - mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47656 - mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47657 - mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47658 - mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47659 - mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47660 - mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47661 - mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47662 - mac80211_hwsim_mchan_ops.assign_vif_chanctx =
47663 - mac80211_hwsim_assign_vif_chanctx;
47664 - mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
47665 - mac80211_hwsim_unassign_vif_chanctx;
47666 + pax_open_kernel();
47667 + memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
47668 + *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47669 + *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47670 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47671 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47672 + *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47673 + *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47674 + *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47675 + *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47676 + *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47677 + *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
47678 + *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
47679 + pax_close_kernel();
47680
47681 spin_lock_init(&hwsim_radio_lock);
47682 INIT_LIST_HEAD(&hwsim_radios);
47683 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
47684 index 39d22a1..4ec8612 100644
47685 --- a/drivers/net/wireless/rndis_wlan.c
47686 +++ b/drivers/net/wireless/rndis_wlan.c
47687 @@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
47688
47689 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
47690
47691 - if (rts_threshold < 0 || rts_threshold > 2347)
47692 + if (rts_threshold > 2347)
47693 rts_threshold = 2347;
47694
47695 tmp = cpu_to_le32(rts_threshold);
47696 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
47697 index 5d45a1a..6f5f041 100644
47698 --- a/drivers/net/wireless/rt2x00/rt2x00.h
47699 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
47700 @@ -375,7 +375,7 @@ struct rt2x00_intf {
47701 * for hardware which doesn't support hardware
47702 * sequence counting.
47703 */
47704 - atomic_t seqno;
47705 + atomic_unchecked_t seqno;
47706 };
47707
47708 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
47709 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
47710 index 5642ccc..01f03eb 100644
47711 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
47712 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
47713 @@ -250,9 +250,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
47714 * sequence counter given by mac80211.
47715 */
47716 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
47717 - seqno = atomic_add_return(0x10, &intf->seqno);
47718 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
47719 else
47720 - seqno = atomic_read(&intf->seqno);
47721 + seqno = atomic_read_unchecked(&intf->seqno);
47722
47723 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
47724 hdr->seq_ctrl |= cpu_to_le16(seqno);
47725 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
47726 index b661f896..ddf7d2b 100644
47727 --- a/drivers/net/wireless/ti/wl1251/sdio.c
47728 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
47729 @@ -282,13 +282,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
47730
47731 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
47732
47733 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47734 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47735 + pax_open_kernel();
47736 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47737 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47738 + pax_close_kernel();
47739
47740 wl1251_info("using dedicated interrupt line");
47741 } else {
47742 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47743 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47744 + pax_open_kernel();
47745 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47746 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47747 + pax_close_kernel();
47748
47749 wl1251_info("using SDIO interrupt");
47750 }
47751 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
47752 index d50dfac..0a6f5be3 100644
47753 --- a/drivers/net/wireless/ti/wl12xx/main.c
47754 +++ b/drivers/net/wireless/ti/wl12xx/main.c
47755 @@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47756 sizeof(wl->conf.mem));
47757
47758 /* read data preparation is only needed by wl127x */
47759 - wl->ops->prepare_read = wl127x_prepare_read;
47760 + pax_open_kernel();
47761 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47762 + pax_close_kernel();
47763
47764 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47765 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47766 @@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47767 sizeof(wl->conf.mem));
47768
47769 /* read data preparation is only needed by wl127x */
47770 - wl->ops->prepare_read = wl127x_prepare_read;
47771 + pax_open_kernel();
47772 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47773 + pax_close_kernel();
47774
47775 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47776 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47777 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
47778 index de5b4fa..7996ec6 100644
47779 --- a/drivers/net/wireless/ti/wl18xx/main.c
47780 +++ b/drivers/net/wireless/ti/wl18xx/main.c
47781 @@ -1900,8 +1900,10 @@ static int wl18xx_setup(struct wl1271 *wl)
47782 }
47783
47784 if (!checksum_param) {
47785 - wl18xx_ops.set_rx_csum = NULL;
47786 - wl18xx_ops.init_vif = NULL;
47787 + pax_open_kernel();
47788 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
47789 + *(void **)&wl18xx_ops.init_vif = NULL;
47790 + pax_close_kernel();
47791 }
47792
47793 /* Enable 11a Band only if we have 5G antennas */
47794 diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
47795 index a912dc0..a8225ba 100644
47796 --- a/drivers/net/wireless/zd1211rw/zd_usb.c
47797 +++ b/drivers/net/wireless/zd1211rw/zd_usb.c
47798 @@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
47799 {
47800 struct zd_usb *usb = urb->context;
47801 struct zd_usb_interrupt *intr = &usb->intr;
47802 - int len;
47803 + unsigned int len;
47804 u16 int_num;
47805
47806 ZD_ASSERT(in_interrupt());
47807 diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
47808 index 683671a..4519fc2 100644
47809 --- a/drivers/nfc/nfcwilink.c
47810 +++ b/drivers/nfc/nfcwilink.c
47811 @@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
47812
47813 static int nfcwilink_probe(struct platform_device *pdev)
47814 {
47815 - static struct nfcwilink *drv;
47816 + struct nfcwilink *drv;
47817 int rc;
47818 __u32 protocols;
47819
47820 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
47821 index d93b2b6..ae50401 100644
47822 --- a/drivers/oprofile/buffer_sync.c
47823 +++ b/drivers/oprofile/buffer_sync.c
47824 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
47825 if (cookie == NO_COOKIE)
47826 offset = pc;
47827 if (cookie == INVALID_COOKIE) {
47828 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47829 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47830 offset = pc;
47831 }
47832 if (cookie != last_cookie) {
47833 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
47834 /* add userspace sample */
47835
47836 if (!mm) {
47837 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
47838 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
47839 return 0;
47840 }
47841
47842 cookie = lookup_dcookie(mm, s->eip, &offset);
47843
47844 if (cookie == INVALID_COOKIE) {
47845 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47846 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47847 return 0;
47848 }
47849
47850 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
47851 /* ignore backtraces if failed to add a sample */
47852 if (state == sb_bt_start) {
47853 state = sb_bt_ignore;
47854 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
47855 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
47856 }
47857 }
47858 release_mm(mm);
47859 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
47860 index c0cc4e7..44d4e54 100644
47861 --- a/drivers/oprofile/event_buffer.c
47862 +++ b/drivers/oprofile/event_buffer.c
47863 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
47864 }
47865
47866 if (buffer_pos == buffer_size) {
47867 - atomic_inc(&oprofile_stats.event_lost_overflow);
47868 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
47869 return;
47870 }
47871
47872 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
47873 index ed2c3ec..deda85a 100644
47874 --- a/drivers/oprofile/oprof.c
47875 +++ b/drivers/oprofile/oprof.c
47876 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
47877 if (oprofile_ops.switch_events())
47878 return;
47879
47880 - atomic_inc(&oprofile_stats.multiplex_counter);
47881 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
47882 start_switch_worker();
47883 }
47884
47885 diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
47886 index ee2cfce..7f8f699 100644
47887 --- a/drivers/oprofile/oprofile_files.c
47888 +++ b/drivers/oprofile/oprofile_files.c
47889 @@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
47890
47891 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
47892
47893 -static ssize_t timeout_read(struct file *file, char __user *buf,
47894 +static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
47895 size_t count, loff_t *offset)
47896 {
47897 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
47898 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
47899 index 59659ce..6c860a0 100644
47900 --- a/drivers/oprofile/oprofile_stats.c
47901 +++ b/drivers/oprofile/oprofile_stats.c
47902 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
47903 cpu_buf->sample_invalid_eip = 0;
47904 }
47905
47906 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
47907 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
47908 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
47909 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
47910 - atomic_set(&oprofile_stats.multiplex_counter, 0);
47911 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
47912 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
47913 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
47914 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
47915 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
47916 }
47917
47918
47919 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
47920 index 1fc622b..8c48fc3 100644
47921 --- a/drivers/oprofile/oprofile_stats.h
47922 +++ b/drivers/oprofile/oprofile_stats.h
47923 @@ -13,11 +13,11 @@
47924 #include <linux/atomic.h>
47925
47926 struct oprofile_stat_struct {
47927 - atomic_t sample_lost_no_mm;
47928 - atomic_t sample_lost_no_mapping;
47929 - atomic_t bt_lost_no_mapping;
47930 - atomic_t event_lost_overflow;
47931 - atomic_t multiplex_counter;
47932 + atomic_unchecked_t sample_lost_no_mm;
47933 + atomic_unchecked_t sample_lost_no_mapping;
47934 + atomic_unchecked_t bt_lost_no_mapping;
47935 + atomic_unchecked_t event_lost_overflow;
47936 + atomic_unchecked_t multiplex_counter;
47937 };
47938
47939 extern struct oprofile_stat_struct oprofile_stats;
47940 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
47941 index 3f49345..c750d0b 100644
47942 --- a/drivers/oprofile/oprofilefs.c
47943 +++ b/drivers/oprofile/oprofilefs.c
47944 @@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
47945
47946 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
47947 {
47948 - atomic_t *val = file->private_data;
47949 - return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
47950 + atomic_unchecked_t *val = file->private_data;
47951 + return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
47952 }
47953
47954
47955 @@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
47956
47957
47958 int oprofilefs_create_ro_atomic(struct dentry *root,
47959 - char const *name, atomic_t *val)
47960 + char const *name, atomic_unchecked_t *val)
47961 {
47962 return __oprofilefs_create_file(root, name,
47963 &atomic_ro_fops, 0444, val);
47964 diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
47965 index 61be1d9..dec05d7 100644
47966 --- a/drivers/oprofile/timer_int.c
47967 +++ b/drivers/oprofile/timer_int.c
47968 @@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
47969 return NOTIFY_OK;
47970 }
47971
47972 -static struct notifier_block __refdata oprofile_cpu_notifier = {
47973 +static struct notifier_block oprofile_cpu_notifier = {
47974 .notifier_call = oprofile_cpu_notify,
47975 };
47976
47977 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
47978 index 92ed045..62d39bd7 100644
47979 --- a/drivers/parport/procfs.c
47980 +++ b/drivers/parport/procfs.c
47981 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
47982
47983 *ppos += len;
47984
47985 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
47986 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
47987 }
47988
47989 #ifdef CONFIG_PARPORT_1284
47990 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
47991
47992 *ppos += len;
47993
47994 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
47995 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
47996 }
47997 #endif /* IEEE1284.3 support. */
47998
47999 diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
48000 index 8dcccff..35d701d 100644
48001 --- a/drivers/pci/hotplug/acpiphp_ibm.c
48002 +++ b/drivers/pci/hotplug/acpiphp_ibm.c
48003 @@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
48004 goto init_cleanup;
48005 }
48006
48007 - ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
48008 + pax_open_kernel();
48009 + *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
48010 + pax_close_kernel();
48011 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
48012
48013 return retval;
48014 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
48015 index 7536eef..52dc8fa 100644
48016 --- a/drivers/pci/hotplug/cpcihp_generic.c
48017 +++ b/drivers/pci/hotplug/cpcihp_generic.c
48018 @@ -73,7 +73,6 @@ static u16 port;
48019 static unsigned int enum_bit;
48020 static u8 enum_mask;
48021
48022 -static struct cpci_hp_controller_ops generic_hpc_ops;
48023 static struct cpci_hp_controller generic_hpc;
48024
48025 static int __init validate_parameters(void)
48026 @@ -139,6 +138,10 @@ static int query_enum(void)
48027 return ((value & enum_mask) == enum_mask);
48028 }
48029
48030 +static struct cpci_hp_controller_ops generic_hpc_ops = {
48031 + .query_enum = query_enum,
48032 +};
48033 +
48034 static int __init cpcihp_generic_init(void)
48035 {
48036 int status;
48037 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
48038 pci_dev_put(dev);
48039
48040 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
48041 - generic_hpc_ops.query_enum = query_enum;
48042 generic_hpc.ops = &generic_hpc_ops;
48043
48044 status = cpci_hp_register_controller(&generic_hpc);
48045 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
48046 index e8c4a7c..7046f5c 100644
48047 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
48048 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
48049 @@ -59,7 +59,6 @@
48050 /* local variables */
48051 static bool debug;
48052 static bool poll;
48053 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
48054 static struct cpci_hp_controller zt5550_hpc;
48055
48056 /* Primary cPCI bus bridge device */
48057 @@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
48058 return 0;
48059 }
48060
48061 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
48062 + .query_enum = zt5550_hc_query_enum,
48063 +};
48064 +
48065 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
48066 {
48067 int status;
48068 @@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
48069 dbg("returned from zt5550_hc_config");
48070
48071 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
48072 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
48073 zt5550_hpc.ops = &zt5550_hpc_ops;
48074 if(!poll) {
48075 zt5550_hpc.irq = hc_dev->irq;
48076 zt5550_hpc.irq_flags = IRQF_SHARED;
48077 zt5550_hpc.dev_id = hc_dev;
48078
48079 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
48080 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
48081 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
48082 + pax_open_kernel();
48083 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
48084 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
48085 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
48086 + pax_open_kernel();
48087 } else {
48088 info("using ENUM# polling mode");
48089 }
48090 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
48091 index 76ba8a1..20ca857 100644
48092 --- a/drivers/pci/hotplug/cpqphp_nvram.c
48093 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
48094 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
48095
48096 void compaq_nvram_init (void __iomem *rom_start)
48097 {
48098 +
48099 +#ifndef CONFIG_PAX_KERNEXEC
48100 if (rom_start) {
48101 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
48102 }
48103 +#endif
48104 +
48105 dbg("int15 entry = %p\n", compaq_int15_entry_point);
48106
48107 /* initialize our int15 lock */
48108 diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
48109 index cfa92a9..29539c5 100644
48110 --- a/drivers/pci/hotplug/pci_hotplug_core.c
48111 +++ b/drivers/pci/hotplug/pci_hotplug_core.c
48112 @@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
48113 return -EINVAL;
48114 }
48115
48116 - slot->ops->owner = owner;
48117 - slot->ops->mod_name = mod_name;
48118 + pax_open_kernel();
48119 + *(struct module **)&slot->ops->owner = owner;
48120 + *(const char **)&slot->ops->mod_name = mod_name;
48121 + pax_close_kernel();
48122
48123 mutex_lock(&pci_hp_mutex);
48124 /*
48125 diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
48126 index 0e0a2ff..29dff57 100644
48127 --- a/drivers/pci/hotplug/pciehp_core.c
48128 +++ b/drivers/pci/hotplug/pciehp_core.c
48129 @@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
48130 struct slot *slot = ctrl->slot;
48131 struct hotplug_slot *hotplug = NULL;
48132 struct hotplug_slot_info *info = NULL;
48133 - struct hotplug_slot_ops *ops = NULL;
48134 + hotplug_slot_ops_no_const *ops = NULL;
48135 char name[SLOT_NAME_SIZE];
48136 int retval = -ENOMEM;
48137
48138 diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
48139 index fb02fc2..83dc2c3 100644
48140 --- a/drivers/pci/msi.c
48141 +++ b/drivers/pci/msi.c
48142 @@ -524,8 +524,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
48143 {
48144 struct attribute **msi_attrs;
48145 struct attribute *msi_attr;
48146 - struct device_attribute *msi_dev_attr;
48147 - struct attribute_group *msi_irq_group;
48148 + device_attribute_no_const *msi_dev_attr;
48149 + attribute_group_no_const *msi_irq_group;
48150 const struct attribute_group **msi_irq_groups;
48151 struct msi_desc *entry;
48152 int ret = -ENOMEM;
48153 @@ -589,7 +589,7 @@ error_attrs:
48154 count = 0;
48155 msi_attr = msi_attrs[count];
48156 while (msi_attr) {
48157 - msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
48158 + msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
48159 kfree(msi_attr->name);
48160 kfree(msi_dev_attr);
48161 ++count;
48162 diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
48163 index 4e0acef..bd98e31 100644
48164 --- a/drivers/pci/pci-sysfs.c
48165 +++ b/drivers/pci/pci-sysfs.c
48166 @@ -1101,7 +1101,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
48167 {
48168 /* allocate attribute structure, piggyback attribute name */
48169 int name_len = write_combine ? 13 : 10;
48170 - struct bin_attribute *res_attr;
48171 + bin_attribute_no_const *res_attr;
48172 int retval;
48173
48174 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
48175 @@ -1286,7 +1286,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
48176 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
48177 {
48178 int retval;
48179 - struct bin_attribute *attr;
48180 + bin_attribute_no_const *attr;
48181
48182 /* If the device has VPD, try to expose it in sysfs. */
48183 if (dev->vpd) {
48184 @@ -1333,7 +1333,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
48185 {
48186 int retval;
48187 int rom_size = 0;
48188 - struct bin_attribute *attr;
48189 + bin_attribute_no_const *attr;
48190
48191 if (!sysfs_initialized)
48192 return -EACCES;
48193 diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
48194 index 6bd0822..35bc2b3 100644
48195 --- a/drivers/pci/pci.h
48196 +++ b/drivers/pci/pci.h
48197 @@ -91,7 +91,7 @@ struct pci_vpd_ops {
48198 struct pci_vpd {
48199 unsigned int len;
48200 const struct pci_vpd_ops *ops;
48201 - struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
48202 + bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
48203 };
48204
48205 int pci_vpd_pci22_init(struct pci_dev *dev);
48206 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
48207 index e1e7026..d28dd33 100644
48208 --- a/drivers/pci/pcie/aspm.c
48209 +++ b/drivers/pci/pcie/aspm.c
48210 @@ -27,9 +27,9 @@
48211 #define MODULE_PARAM_PREFIX "pcie_aspm."
48212
48213 /* Note: those are not register definitions */
48214 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
48215 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
48216 -#define ASPM_STATE_L1 (4) /* L1 state */
48217 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
48218 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
48219 +#define ASPM_STATE_L1 (4U) /* L1 state */
48220 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
48221 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
48222
48223 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
48224 index ef09f5f..49ac62f 100644
48225 --- a/drivers/pci/probe.c
48226 +++ b/drivers/pci/probe.c
48227 @@ -175,7 +175,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
48228 struct pci_bus_region region, inverted_region;
48229 bool bar_too_big = false, bar_disabled = false;
48230
48231 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
48232 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
48233
48234 /* No printks while decoding is disabled! */
48235 if (!dev->mmio_always_on) {
48236 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
48237 index 46d1378..30e452b 100644
48238 --- a/drivers/pci/proc.c
48239 +++ b/drivers/pci/proc.c
48240 @@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
48241 static int __init pci_proc_init(void)
48242 {
48243 struct pci_dev *dev = NULL;
48244 +
48245 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48246 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48247 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
48248 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48249 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
48250 +#endif
48251 +#else
48252 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
48253 +#endif
48254 proc_create("devices", 0, proc_bus_pci_dir,
48255 &proc_bus_pci_dev_operations);
48256 proc_initialized = 1;
48257 diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
48258 index 7f3aad0..7d604bb 100644
48259 --- a/drivers/platform/chrome/chromeos_laptop.c
48260 +++ b/drivers/platform/chrome/chromeos_laptop.c
48261 @@ -406,7 +406,7 @@ static struct chromeos_laptop cr48 = {
48262 .callback = chromeos_laptop_dmi_matched, \
48263 .driver_data = (void *)&board_
48264
48265 -static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
48266 +static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
48267 {
48268 .ident = "Samsung Series 5 550",
48269 .matches = {
48270 diff --git a/drivers/platform/x86/alienware-wmi.c b/drivers/platform/x86/alienware-wmi.c
48271 index 541f951..4dfd598 100644
48272 --- a/drivers/platform/x86/alienware-wmi.c
48273 +++ b/drivers/platform/x86/alienware-wmi.c
48274 @@ -132,7 +132,7 @@ struct wmax_led_args {
48275 } __packed;
48276
48277 static struct platform_device *platform_device;
48278 -static struct device_attribute *zone_dev_attrs;
48279 +static device_attribute_no_const *zone_dev_attrs;
48280 static struct attribute **zone_attrs;
48281 static struct platform_zone *zone_data;
48282
48283 @@ -143,7 +143,7 @@ static struct platform_driver platform_driver = {
48284 }
48285 };
48286
48287 -static struct attribute_group zone_attribute_group = {
48288 +static attribute_group_no_const zone_attribute_group = {
48289 .name = "rgb_zones",
48290 };
48291
48292 diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
48293 index c5e082f..d6307a0 100644
48294 --- a/drivers/platform/x86/asus-wmi.c
48295 +++ b/drivers/platform/x86/asus-wmi.c
48296 @@ -1595,6 +1595,10 @@ static int show_dsts(struct seq_file *m, void *data)
48297 int err;
48298 u32 retval = -1;
48299
48300 +#ifdef CONFIG_GRKERNSEC_KMEM
48301 + return -EPERM;
48302 +#endif
48303 +
48304 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
48305
48306 if (err < 0)
48307 @@ -1611,6 +1615,10 @@ static int show_devs(struct seq_file *m, void *data)
48308 int err;
48309 u32 retval = -1;
48310
48311 +#ifdef CONFIG_GRKERNSEC_KMEM
48312 + return -EPERM;
48313 +#endif
48314 +
48315 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
48316 &retval);
48317
48318 @@ -1635,6 +1643,10 @@ static int show_call(struct seq_file *m, void *data)
48319 union acpi_object *obj;
48320 acpi_status status;
48321
48322 +#ifdef CONFIG_GRKERNSEC_KMEM
48323 + return -EPERM;
48324 +#endif
48325 +
48326 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
48327 1, asus->debug.method_id,
48328 &input, &output);
48329 diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
48330 index 62f8030..c7f2a45 100644
48331 --- a/drivers/platform/x86/msi-laptop.c
48332 +++ b/drivers/platform/x86/msi-laptop.c
48333 @@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
48334
48335 if (!quirks->ec_read_only) {
48336 /* allow userland write sysfs file */
48337 - dev_attr_bluetooth.store = store_bluetooth;
48338 - dev_attr_wlan.store = store_wlan;
48339 - dev_attr_threeg.store = store_threeg;
48340 - dev_attr_bluetooth.attr.mode |= S_IWUSR;
48341 - dev_attr_wlan.attr.mode |= S_IWUSR;
48342 - dev_attr_threeg.attr.mode |= S_IWUSR;
48343 + pax_open_kernel();
48344 + *(void **)&dev_attr_bluetooth.store = store_bluetooth;
48345 + *(void **)&dev_attr_wlan.store = store_wlan;
48346 + *(void **)&dev_attr_threeg.store = store_threeg;
48347 + *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
48348 + *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
48349 + *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
48350 + pax_close_kernel();
48351 }
48352
48353 /* disable hardware control by fn key */
48354 diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
48355 index 70222f2..8c8ce66 100644
48356 --- a/drivers/platform/x86/msi-wmi.c
48357 +++ b/drivers/platform/x86/msi-wmi.c
48358 @@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
48359 static void msi_wmi_notify(u32 value, void *context)
48360 {
48361 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
48362 - static struct key_entry *key;
48363 + struct key_entry *key;
48364 union acpi_object *obj;
48365 acpi_status status;
48366
48367 diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
48368 index 9c5a074..06c976a 100644
48369 --- a/drivers/platform/x86/sony-laptop.c
48370 +++ b/drivers/platform/x86/sony-laptop.c
48371 @@ -2527,7 +2527,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
48372 }
48373
48374 /* High speed charging function */
48375 -static struct device_attribute *hsc_handle;
48376 +static device_attribute_no_const *hsc_handle;
48377
48378 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
48379 struct device_attribute *attr,
48380 @@ -2601,7 +2601,7 @@ static void sony_nc_highspeed_charging_cleanup(struct platform_device *pd)
48381 }
48382
48383 /* low battery function */
48384 -static struct device_attribute *lowbatt_handle;
48385 +static device_attribute_no_const *lowbatt_handle;
48386
48387 static ssize_t sony_nc_lowbatt_store(struct device *dev,
48388 struct device_attribute *attr,
48389 @@ -2667,7 +2667,7 @@ static void sony_nc_lowbatt_cleanup(struct platform_device *pd)
48390 }
48391
48392 /* fan speed function */
48393 -static struct device_attribute *fan_handle, *hsf_handle;
48394 +static device_attribute_no_const *fan_handle, *hsf_handle;
48395
48396 static ssize_t sony_nc_hsfan_store(struct device *dev,
48397 struct device_attribute *attr,
48398 @@ -2774,7 +2774,7 @@ static void sony_nc_fanspeed_cleanup(struct platform_device *pd)
48399 }
48400
48401 /* USB charge function */
48402 -static struct device_attribute *uc_handle;
48403 +static device_attribute_no_const *uc_handle;
48404
48405 static ssize_t sony_nc_usb_charge_store(struct device *dev,
48406 struct device_attribute *attr,
48407 @@ -2848,7 +2848,7 @@ static void sony_nc_usb_charge_cleanup(struct platform_device *pd)
48408 }
48409
48410 /* Panel ID function */
48411 -static struct device_attribute *panel_handle;
48412 +static device_attribute_no_const *panel_handle;
48413
48414 static ssize_t sony_nc_panelid_show(struct device *dev,
48415 struct device_attribute *attr, char *buffer)
48416 @@ -2895,7 +2895,7 @@ static void sony_nc_panelid_cleanup(struct platform_device *pd)
48417 }
48418
48419 /* smart connect function */
48420 -static struct device_attribute *sc_handle;
48421 +static device_attribute_no_const *sc_handle;
48422
48423 static ssize_t sony_nc_smart_conn_store(struct device *dev,
48424 struct device_attribute *attr,
48425 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
48426 index 15e61c1..40a39c7 100644
48427 --- a/drivers/platform/x86/thinkpad_acpi.c
48428 +++ b/drivers/platform/x86/thinkpad_acpi.c
48429 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
48430 return 0;
48431 }
48432
48433 -void static hotkey_mask_warn_incomplete_mask(void)
48434 +static void hotkey_mask_warn_incomplete_mask(void)
48435 {
48436 /* log only what the user can fix... */
48437 const u32 wantedmask = hotkey_driver_mask &
48438 @@ -2438,10 +2438,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48439 && !tp_features.bright_unkfw)
48440 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
48441 }
48442 +}
48443
48444 #undef TPACPI_COMPARE_KEY
48445 #undef TPACPI_MAY_SEND_KEY
48446 -}
48447
48448 /*
48449 * Polling driver
48450 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
48451 index 438d4c7..ca8a2fb 100644
48452 --- a/drivers/pnp/pnpbios/bioscalls.c
48453 +++ b/drivers/pnp/pnpbios/bioscalls.c
48454 @@ -59,7 +59,7 @@ do { \
48455 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
48456 } while(0)
48457
48458 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
48459 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
48460 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
48461
48462 /*
48463 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
48464
48465 cpu = get_cpu();
48466 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
48467 +
48468 + pax_open_kernel();
48469 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
48470 + pax_close_kernel();
48471
48472 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
48473 spin_lock_irqsave(&pnp_bios_lock, flags);
48474 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
48475 :"memory");
48476 spin_unlock_irqrestore(&pnp_bios_lock, flags);
48477
48478 + pax_open_kernel();
48479 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
48480 + pax_close_kernel();
48481 +
48482 put_cpu();
48483
48484 /* If we get here and this is set then the PnP BIOS faulted on us. */
48485 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
48486 return status;
48487 }
48488
48489 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
48490 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
48491 {
48492 int i;
48493
48494 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
48495 pnp_bios_callpoint.offset = header->fields.pm16offset;
48496 pnp_bios_callpoint.segment = PNP_CS16;
48497
48498 + pax_open_kernel();
48499 +
48500 for_each_possible_cpu(i) {
48501 struct desc_struct *gdt = get_cpu_gdt_table(i);
48502 if (!gdt)
48503 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
48504 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
48505 (unsigned long)__va(header->fields.pm16dseg));
48506 }
48507 +
48508 + pax_close_kernel();
48509 }
48510 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
48511 index 01712cb..782e822 100644
48512 --- a/drivers/pnp/resource.c
48513 +++ b/drivers/pnp/resource.c
48514 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
48515 return 1;
48516
48517 /* check if the resource is valid */
48518 - if (*irq < 0 || *irq > 15)
48519 + if (*irq > 15)
48520 return 0;
48521
48522 /* check if the resource is reserved */
48523 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
48524 return 1;
48525
48526 /* check if the resource is valid */
48527 - if (*dma < 0 || *dma == 4 || *dma > 7)
48528 + if (*dma == 4 || *dma > 7)
48529 return 0;
48530
48531 /* check if the resource is reserved */
48532 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
48533 index 0c52e2a..3421ab7 100644
48534 --- a/drivers/power/pda_power.c
48535 +++ b/drivers/power/pda_power.c
48536 @@ -37,7 +37,11 @@ static int polling;
48537
48538 #if IS_ENABLED(CONFIG_USB_PHY)
48539 static struct usb_phy *transceiver;
48540 -static struct notifier_block otg_nb;
48541 +static int otg_handle_notification(struct notifier_block *nb,
48542 + unsigned long event, void *unused);
48543 +static struct notifier_block otg_nb = {
48544 + .notifier_call = otg_handle_notification
48545 +};
48546 #endif
48547
48548 static struct regulator *ac_draw;
48549 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
48550
48551 #if IS_ENABLED(CONFIG_USB_PHY)
48552 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
48553 - otg_nb.notifier_call = otg_handle_notification;
48554 ret = usb_register_notifier(transceiver, &otg_nb);
48555 if (ret) {
48556 dev_err(dev, "failure to register otg notifier\n");
48557 diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
48558 index cc439fd..8fa30df 100644
48559 --- a/drivers/power/power_supply.h
48560 +++ b/drivers/power/power_supply.h
48561 @@ -16,12 +16,12 @@ struct power_supply;
48562
48563 #ifdef CONFIG_SYSFS
48564
48565 -extern void power_supply_init_attrs(struct device_type *dev_type);
48566 +extern void power_supply_init_attrs(void);
48567 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
48568
48569 #else
48570
48571 -static inline void power_supply_init_attrs(struct device_type *dev_type) {}
48572 +static inline void power_supply_init_attrs(void) {}
48573 #define power_supply_uevent NULL
48574
48575 #endif /* CONFIG_SYSFS */
48576 diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
48577 index 2660664..75fcb04 100644
48578 --- a/drivers/power/power_supply_core.c
48579 +++ b/drivers/power/power_supply_core.c
48580 @@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
48581 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
48582 EXPORT_SYMBOL_GPL(power_supply_notifier);
48583
48584 -static struct device_type power_supply_dev_type;
48585 +extern const struct attribute_group *power_supply_attr_groups[];
48586 +static struct device_type power_supply_dev_type = {
48587 + .groups = power_supply_attr_groups,
48588 +};
48589
48590 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
48591 struct power_supply *supply)
48592 @@ -628,7 +631,7 @@ static int __init power_supply_class_init(void)
48593 return PTR_ERR(power_supply_class);
48594
48595 power_supply_class->dev_uevent = power_supply_uevent;
48596 - power_supply_init_attrs(&power_supply_dev_type);
48597 + power_supply_init_attrs();
48598
48599 return 0;
48600 }
48601 diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
48602 index 44420d1..967126e 100644
48603 --- a/drivers/power/power_supply_sysfs.c
48604 +++ b/drivers/power/power_supply_sysfs.c
48605 @@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
48606 .is_visible = power_supply_attr_is_visible,
48607 };
48608
48609 -static const struct attribute_group *power_supply_attr_groups[] = {
48610 +const struct attribute_group *power_supply_attr_groups[] = {
48611 &power_supply_attr_group,
48612 NULL,
48613 };
48614
48615 -void power_supply_init_attrs(struct device_type *dev_type)
48616 +void power_supply_init_attrs(void)
48617 {
48618 int i;
48619
48620 - dev_type->groups = power_supply_attr_groups;
48621 -
48622 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
48623 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
48624 }
48625 diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
48626 index 84419af..268ede8 100644
48627 --- a/drivers/powercap/powercap_sys.c
48628 +++ b/drivers/powercap/powercap_sys.c
48629 @@ -154,8 +154,77 @@ struct powercap_constraint_attr {
48630 struct device_attribute name_attr;
48631 };
48632
48633 +static ssize_t show_constraint_name(struct device *dev,
48634 + struct device_attribute *dev_attr,
48635 + char *buf);
48636 +
48637 static struct powercap_constraint_attr
48638 - constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
48639 + constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
48640 + [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
48641 + .power_limit_attr = {
48642 + .attr = {
48643 + .name = NULL,
48644 + .mode = S_IWUSR | S_IRUGO
48645 + },
48646 + .show = show_constraint_power_limit_uw,
48647 + .store = store_constraint_power_limit_uw
48648 + },
48649 +
48650 + .time_window_attr = {
48651 + .attr = {
48652 + .name = NULL,
48653 + .mode = S_IWUSR | S_IRUGO
48654 + },
48655 + .show = show_constraint_time_window_us,
48656 + .store = store_constraint_time_window_us
48657 + },
48658 +
48659 + .max_power_attr = {
48660 + .attr = {
48661 + .name = NULL,
48662 + .mode = S_IRUGO
48663 + },
48664 + .show = show_constraint_max_power_uw,
48665 + .store = NULL
48666 + },
48667 +
48668 + .min_power_attr = {
48669 + .attr = {
48670 + .name = NULL,
48671 + .mode = S_IRUGO
48672 + },
48673 + .show = show_constraint_min_power_uw,
48674 + .store = NULL
48675 + },
48676 +
48677 + .max_time_window_attr = {
48678 + .attr = {
48679 + .name = NULL,
48680 + .mode = S_IRUGO
48681 + },
48682 + .show = show_constraint_max_time_window_us,
48683 + .store = NULL
48684 + },
48685 +
48686 + .min_time_window_attr = {
48687 + .attr = {
48688 + .name = NULL,
48689 + .mode = S_IRUGO
48690 + },
48691 + .show = show_constraint_min_time_window_us,
48692 + .store = NULL
48693 + },
48694 +
48695 + .name_attr = {
48696 + .attr = {
48697 + .name = NULL,
48698 + .mode = S_IRUGO
48699 + },
48700 + .show = show_constraint_name,
48701 + .store = NULL
48702 + }
48703 + }
48704 +};
48705
48706 /* A list of powercap control_types */
48707 static LIST_HEAD(powercap_cntrl_list);
48708 @@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
48709 }
48710
48711 static int create_constraint_attribute(int id, const char *name,
48712 - int mode,
48713 - struct device_attribute *dev_attr,
48714 - ssize_t (*show)(struct device *,
48715 - struct device_attribute *, char *),
48716 - ssize_t (*store)(struct device *,
48717 - struct device_attribute *,
48718 - const char *, size_t)
48719 - )
48720 + struct device_attribute *dev_attr)
48721 {
48722 + name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
48723
48724 - dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
48725 - id, name);
48726 - if (!dev_attr->attr.name)
48727 + if (!name)
48728 return -ENOMEM;
48729 - dev_attr->attr.mode = mode;
48730 - dev_attr->show = show;
48731 - dev_attr->store = store;
48732 +
48733 + pax_open_kernel();
48734 + *(const char **)&dev_attr->attr.name = name;
48735 + pax_close_kernel();
48736
48737 return 0;
48738 }
48739 @@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
48740
48741 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
48742 ret = create_constraint_attribute(i, "power_limit_uw",
48743 - S_IWUSR | S_IRUGO,
48744 - &constraint_attrs[i].power_limit_attr,
48745 - show_constraint_power_limit_uw,
48746 - store_constraint_power_limit_uw);
48747 + &constraint_attrs[i].power_limit_attr);
48748 if (ret)
48749 goto err_alloc;
48750 ret = create_constraint_attribute(i, "time_window_us",
48751 - S_IWUSR | S_IRUGO,
48752 - &constraint_attrs[i].time_window_attr,
48753 - show_constraint_time_window_us,
48754 - store_constraint_time_window_us);
48755 + &constraint_attrs[i].time_window_attr);
48756 if (ret)
48757 goto err_alloc;
48758 - ret = create_constraint_attribute(i, "name", S_IRUGO,
48759 - &constraint_attrs[i].name_attr,
48760 - show_constraint_name,
48761 - NULL);
48762 + ret = create_constraint_attribute(i, "name",
48763 + &constraint_attrs[i].name_attr);
48764 if (ret)
48765 goto err_alloc;
48766 - ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
48767 - &constraint_attrs[i].max_power_attr,
48768 - show_constraint_max_power_uw,
48769 - NULL);
48770 + ret = create_constraint_attribute(i, "max_power_uw",
48771 + &constraint_attrs[i].max_power_attr);
48772 if (ret)
48773 goto err_alloc;
48774 - ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
48775 - &constraint_attrs[i].min_power_attr,
48776 - show_constraint_min_power_uw,
48777 - NULL);
48778 + ret = create_constraint_attribute(i, "min_power_uw",
48779 + &constraint_attrs[i].min_power_attr);
48780 if (ret)
48781 goto err_alloc;
48782 ret = create_constraint_attribute(i, "max_time_window_us",
48783 - S_IRUGO,
48784 - &constraint_attrs[i].max_time_window_attr,
48785 - show_constraint_max_time_window_us,
48786 - NULL);
48787 + &constraint_attrs[i].max_time_window_attr);
48788 if (ret)
48789 goto err_alloc;
48790 ret = create_constraint_attribute(i, "min_time_window_us",
48791 - S_IRUGO,
48792 - &constraint_attrs[i].min_time_window_attr,
48793 - show_constraint_min_time_window_us,
48794 - NULL);
48795 + &constraint_attrs[i].min_time_window_attr);
48796 if (ret)
48797 goto err_alloc;
48798
48799 @@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
48800 power_zone->zone_dev_attrs[count++] =
48801 &dev_attr_max_energy_range_uj.attr;
48802 if (power_zone->ops->get_energy_uj) {
48803 + pax_open_kernel();
48804 if (power_zone->ops->reset_energy_uj)
48805 - dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48806 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48807 else
48808 - dev_attr_energy_uj.attr.mode = S_IRUGO;
48809 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
48810 + pax_close_kernel();
48811 power_zone->zone_dev_attrs[count++] =
48812 &dev_attr_energy_uj.attr;
48813 }
48814 diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h
48815 index 9c5d414..c7900ce 100644
48816 --- a/drivers/ptp/ptp_private.h
48817 +++ b/drivers/ptp/ptp_private.h
48818 @@ -51,7 +51,7 @@ struct ptp_clock {
48819 struct mutex pincfg_mux; /* protect concurrent info->pin_config access */
48820 wait_queue_head_t tsev_wq;
48821 int defunct; /* tells readers to go away when clock is being removed */
48822 - struct device_attribute *pin_dev_attr;
48823 + device_attribute_no_const *pin_dev_attr;
48824 struct attribute **pin_attr;
48825 struct attribute_group pin_attr_group;
48826 };
48827 diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c
48828 index 302e626..12579af 100644
48829 --- a/drivers/ptp/ptp_sysfs.c
48830 +++ b/drivers/ptp/ptp_sysfs.c
48831 @@ -280,7 +280,7 @@ static int ptp_populate_pins(struct ptp_clock *ptp)
48832 goto no_pin_attr;
48833
48834 for (i = 0; i < n_pins; i++) {
48835 - struct device_attribute *da = &ptp->pin_dev_attr[i];
48836 + device_attribute_no_const *da = &ptp->pin_dev_attr[i];
48837 sysfs_attr_init(&da->attr);
48838 da->attr.name = info->pin_config[i].name;
48839 da->attr.mode = 0644;
48840 diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
48841 index 9a09f3c..450b523 100644
48842 --- a/drivers/regulator/core.c
48843 +++ b/drivers/regulator/core.c
48844 @@ -3380,7 +3380,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48845 {
48846 const struct regulation_constraints *constraints = NULL;
48847 const struct regulator_init_data *init_data;
48848 - static atomic_t regulator_no = ATOMIC_INIT(0);
48849 + static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
48850 struct regulator_dev *rdev;
48851 struct device *dev;
48852 int ret, i;
48853 @@ -3450,7 +3450,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48854 rdev->dev.of_node = config->of_node;
48855 rdev->dev.parent = dev;
48856 dev_set_name(&rdev->dev, "regulator.%d",
48857 - atomic_inc_return(&regulator_no) - 1);
48858 + atomic_inc_return_unchecked(&regulator_no) - 1);
48859 ret = device_register(&rdev->dev);
48860 if (ret != 0) {
48861 put_device(&rdev->dev);
48862 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
48863 index 2fc4111..6aa88ca 100644
48864 --- a/drivers/regulator/max8660.c
48865 +++ b/drivers/regulator/max8660.c
48866 @@ -424,8 +424,10 @@ static int max8660_probe(struct i2c_client *client,
48867 max8660->shadow_regs[MAX8660_OVER1] = 5;
48868 } else {
48869 /* Otherwise devices can be toggled via software */
48870 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
48871 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
48872 + pax_open_kernel();
48873 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
48874 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
48875 + pax_close_kernel();
48876 }
48877
48878 /*
48879 diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
48880 index dbedf17..18ff6b7 100644
48881 --- a/drivers/regulator/max8973-regulator.c
48882 +++ b/drivers/regulator/max8973-regulator.c
48883 @@ -403,9 +403,11 @@ static int max8973_probe(struct i2c_client *client,
48884 if (!pdata || !pdata->enable_ext_control) {
48885 max->desc.enable_reg = MAX8973_VOUT;
48886 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
48887 - max->ops.enable = regulator_enable_regmap;
48888 - max->ops.disable = regulator_disable_regmap;
48889 - max->ops.is_enabled = regulator_is_enabled_regmap;
48890 + pax_open_kernel();
48891 + *(void **)&max->ops.enable = regulator_enable_regmap;
48892 + *(void **)&max->ops.disable = regulator_disable_regmap;
48893 + *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
48894 + pax_close_kernel();
48895 }
48896
48897 if (pdata) {
48898 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
48899 index f374fa5..26f0683 100644
48900 --- a/drivers/regulator/mc13892-regulator.c
48901 +++ b/drivers/regulator/mc13892-regulator.c
48902 @@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
48903 }
48904 mc13xxx_unlock(mc13892);
48905
48906 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48907 + pax_open_kernel();
48908 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48909 = mc13892_vcam_set_mode;
48910 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48911 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48912 = mc13892_vcam_get_mode;
48913 + pax_close_kernel();
48914
48915 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
48916 ARRAY_SIZE(mc13892_regulators));
48917 diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
48918 index 0963c93..ea29cce 100644
48919 --- a/drivers/rtc/rtc-cmos.c
48920 +++ b/drivers/rtc/rtc-cmos.c
48921 @@ -777,7 +777,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
48922 hpet_rtc_timer_init();
48923
48924 /* export at least the first block of NVRAM */
48925 - nvram.size = address_space - NVRAM_OFFSET;
48926 + pax_open_kernel();
48927 + *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
48928 + pax_close_kernel();
48929 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
48930 if (retval < 0) {
48931 dev_dbg(dev, "can't create nvram file? %d\n", retval);
48932 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
48933 index d049393..bb20be0 100644
48934 --- a/drivers/rtc/rtc-dev.c
48935 +++ b/drivers/rtc/rtc-dev.c
48936 @@ -16,6 +16,7 @@
48937 #include <linux/module.h>
48938 #include <linux/rtc.h>
48939 #include <linux/sched.h>
48940 +#include <linux/grsecurity.h>
48941 #include "rtc-core.h"
48942
48943 static dev_t rtc_devt;
48944 @@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
48945 if (copy_from_user(&tm, uarg, sizeof(tm)))
48946 return -EFAULT;
48947
48948 + gr_log_timechange();
48949 +
48950 return rtc_set_time(rtc, &tm);
48951
48952 case RTC_PIE_ON:
48953 diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
48954 index f03d5ba..8325bf6 100644
48955 --- a/drivers/rtc/rtc-ds1307.c
48956 +++ b/drivers/rtc/rtc-ds1307.c
48957 @@ -107,7 +107,7 @@ struct ds1307 {
48958 u8 offset; /* register's offset */
48959 u8 regs[11];
48960 u16 nvram_offset;
48961 - struct bin_attribute *nvram;
48962 + bin_attribute_no_const *nvram;
48963 enum ds_type type;
48964 unsigned long flags;
48965 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
48966 diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
48967 index 11880c1..b823aa4 100644
48968 --- a/drivers/rtc/rtc-m48t59.c
48969 +++ b/drivers/rtc/rtc-m48t59.c
48970 @@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
48971 if (IS_ERR(m48t59->rtc))
48972 return PTR_ERR(m48t59->rtc);
48973
48974 - m48t59_nvram_attr.size = pdata->offset;
48975 + pax_open_kernel();
48976 + *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
48977 + pax_close_kernel();
48978
48979 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
48980 if (ret)
48981 diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
48982 index 14b5f8d..cc9bd26 100644
48983 --- a/drivers/scsi/aic7xxx/aic79xx_pci.c
48984 +++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
48985 @@ -827,7 +827,7 @@ ahd_pci_intr(struct ahd_softc *ahd)
48986 for (bit = 0; bit < 8; bit++) {
48987
48988 if ((pci_status[i] & (0x1 << bit)) != 0) {
48989 - static const char *s;
48990 + const char *s;
48991
48992 s = pci_status_strings[bit];
48993 if (i == 7/*TARG*/ && bit == 3)
48994 @@ -887,23 +887,15 @@ ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
48995
48996 for (bit = 0; bit < 8; bit++) {
48997
48998 - if ((split_status[i] & (0x1 << bit)) != 0) {
48999 - static const char *s;
49000 -
49001 - s = split_status_strings[bit];
49002 - printk(s, ahd_name(ahd),
49003 + if ((split_status[i] & (0x1 << bit)) != 0)
49004 + printk(split_status_strings[bit], ahd_name(ahd),
49005 split_status_source[i]);
49006 - }
49007
49008 if (i > 1)
49009 continue;
49010
49011 - if ((sg_split_status[i] & (0x1 << bit)) != 0) {
49012 - static const char *s;
49013 -
49014 - s = split_status_strings[bit];
49015 - printk(s, ahd_name(ahd), "SG");
49016 - }
49017 + if ((sg_split_status[i] & (0x1 << bit)) != 0)
49018 + printk(split_status_strings[bit], ahd_name(ahd), "SG");
49019 }
49020 }
49021 /*
49022 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
49023 index e693af6..2e525b6 100644
49024 --- a/drivers/scsi/bfa/bfa_fcpim.h
49025 +++ b/drivers/scsi/bfa/bfa_fcpim.h
49026 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
49027
49028 struct bfa_itn_s {
49029 bfa_isr_func_t isr;
49030 -};
49031 +} __no_const;
49032
49033 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
49034 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
49035 diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
49036 index a3ab5cc..8143622 100644
49037 --- a/drivers/scsi/bfa/bfa_fcs.c
49038 +++ b/drivers/scsi/bfa/bfa_fcs.c
49039 @@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
49040 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
49041
49042 static struct bfa_fcs_mod_s fcs_modules[] = {
49043 - { bfa_fcs_port_attach, NULL, NULL },
49044 - { bfa_fcs_uf_attach, NULL, NULL },
49045 - { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
49046 - bfa_fcs_fabric_modexit },
49047 + {
49048 + .attach = bfa_fcs_port_attach,
49049 + .modinit = NULL,
49050 + .modexit = NULL
49051 + },
49052 + {
49053 + .attach = bfa_fcs_uf_attach,
49054 + .modinit = NULL,
49055 + .modexit = NULL
49056 + },
49057 + {
49058 + .attach = bfa_fcs_fabric_attach,
49059 + .modinit = bfa_fcs_fabric_modinit,
49060 + .modexit = bfa_fcs_fabric_modexit
49061 + },
49062 };
49063
49064 /*
49065 diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
49066 index ff75ef8..2dfe00a 100644
49067 --- a/drivers/scsi/bfa/bfa_fcs_lport.c
49068 +++ b/drivers/scsi/bfa/bfa_fcs_lport.c
49069 @@ -89,15 +89,26 @@ static struct {
49070 void (*offline) (struct bfa_fcs_lport_s *port);
49071 } __port_action[] = {
49072 {
49073 - bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
49074 - bfa_fcs_lport_unknown_offline}, {
49075 - bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
49076 - bfa_fcs_lport_fab_offline}, {
49077 - bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
49078 - bfa_fcs_lport_n2n_offline}, {
49079 - bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
49080 - bfa_fcs_lport_loop_offline},
49081 - };
49082 + .init = bfa_fcs_lport_unknown_init,
49083 + .online = bfa_fcs_lport_unknown_online,
49084 + .offline = bfa_fcs_lport_unknown_offline
49085 + },
49086 + {
49087 + .init = bfa_fcs_lport_fab_init,
49088 + .online = bfa_fcs_lport_fab_online,
49089 + .offline = bfa_fcs_lport_fab_offline
49090 + },
49091 + {
49092 + .init = bfa_fcs_lport_n2n_init,
49093 + .online = bfa_fcs_lport_n2n_online,
49094 + .offline = bfa_fcs_lport_n2n_offline
49095 + },
49096 + {
49097 + .init = bfa_fcs_lport_loop_init,
49098 + .online = bfa_fcs_lport_loop_online,
49099 + .offline = bfa_fcs_lport_loop_offline
49100 + },
49101 +};
49102
49103 /*
49104 * fcs_port_sm FCS logical port state machine
49105 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
49106 index 2e28392..9d865b6 100644
49107 --- a/drivers/scsi/bfa/bfa_ioc.h
49108 +++ b/drivers/scsi/bfa/bfa_ioc.h
49109 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
49110 bfa_ioc_disable_cbfn_t disable_cbfn;
49111 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
49112 bfa_ioc_reset_cbfn_t reset_cbfn;
49113 -};
49114 +} __no_const;
49115
49116 /*
49117 * IOC event notification mechanism.
49118 @@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
49119 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
49120 enum bfi_ioc_state fwstate);
49121 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
49122 -};
49123 +} __no_const;
49124
49125 /*
49126 * Queue element to wait for room in request queue. FIFO order is
49127 diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
49128 index a14c784..6de6790 100644
49129 --- a/drivers/scsi/bfa/bfa_modules.h
49130 +++ b/drivers/scsi/bfa/bfa_modules.h
49131 @@ -78,12 +78,12 @@ enum {
49132 \
49133 extern struct bfa_module_s hal_mod_ ## __mod; \
49134 struct bfa_module_s hal_mod_ ## __mod = { \
49135 - bfa_ ## __mod ## _meminfo, \
49136 - bfa_ ## __mod ## _attach, \
49137 - bfa_ ## __mod ## _detach, \
49138 - bfa_ ## __mod ## _start, \
49139 - bfa_ ## __mod ## _stop, \
49140 - bfa_ ## __mod ## _iocdisable, \
49141 + .meminfo = bfa_ ## __mod ## _meminfo, \
49142 + .attach = bfa_ ## __mod ## _attach, \
49143 + .detach = bfa_ ## __mod ## _detach, \
49144 + .start = bfa_ ## __mod ## _start, \
49145 + .stop = bfa_ ## __mod ## _stop, \
49146 + .iocdisable = bfa_ ## __mod ## _iocdisable, \
49147 }
49148
49149 #define BFA_CACHELINE_SZ (256)
49150 diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
49151 index 045c4e1..13de803 100644
49152 --- a/drivers/scsi/fcoe/fcoe_sysfs.c
49153 +++ b/drivers/scsi/fcoe/fcoe_sysfs.c
49154 @@ -33,8 +33,8 @@
49155 */
49156 #include "libfcoe.h"
49157
49158 -static atomic_t ctlr_num;
49159 -static atomic_t fcf_num;
49160 +static atomic_unchecked_t ctlr_num;
49161 +static atomic_unchecked_t fcf_num;
49162
49163 /*
49164 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
49165 @@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
49166 if (!ctlr)
49167 goto out;
49168
49169 - ctlr->id = atomic_inc_return(&ctlr_num) - 1;
49170 + ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
49171 ctlr->f = f;
49172 ctlr->mode = FIP_CONN_TYPE_FABRIC;
49173 INIT_LIST_HEAD(&ctlr->fcfs);
49174 @@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
49175 fcf->dev.parent = &ctlr->dev;
49176 fcf->dev.bus = &fcoe_bus_type;
49177 fcf->dev.type = &fcoe_fcf_device_type;
49178 - fcf->id = atomic_inc_return(&fcf_num) - 1;
49179 + fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
49180 fcf->state = FCOE_FCF_STATE_UNKNOWN;
49181
49182 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
49183 @@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
49184 {
49185 int error;
49186
49187 - atomic_set(&ctlr_num, 0);
49188 - atomic_set(&fcf_num, 0);
49189 + atomic_set_unchecked(&ctlr_num, 0);
49190 + atomic_set_unchecked(&fcf_num, 0);
49191
49192 error = bus_register(&fcoe_bus_type);
49193 if (error)
49194 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
49195 index 3cbb57a..95e47a3 100644
49196 --- a/drivers/scsi/hosts.c
49197 +++ b/drivers/scsi/hosts.c
49198 @@ -42,7 +42,7 @@
49199 #include "scsi_logging.h"
49200
49201
49202 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
49203 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
49204
49205
49206 static void scsi_host_cls_release(struct device *dev)
49207 @@ -369,7 +369,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
49208 * subtract one because we increment first then return, but we need to
49209 * know what the next host number was before increment
49210 */
49211 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
49212 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
49213 shost->dma_channel = 0xff;
49214
49215 /* These three are default values which can be overridden */
49216 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
49217 index fda6cf1..7a6b5d8 100644
49218 --- a/drivers/scsi/hpsa.c
49219 +++ b/drivers/scsi/hpsa.c
49220 @@ -699,10 +699,10 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
49221 unsigned long flags;
49222
49223 if (h->transMethod & CFGTBL_Trans_io_accel1)
49224 - return h->access.command_completed(h, q);
49225 + return h->access->command_completed(h, q);
49226
49227 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
49228 - return h->access.command_completed(h, q);
49229 + return h->access->command_completed(h, q);
49230
49231 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
49232 a = rq->head[rq->current_entry];
49233 @@ -5460,7 +5460,7 @@ static void start_io(struct ctlr_info *h)
49234 while (!list_empty(&h->reqQ)) {
49235 c = list_entry(h->reqQ.next, struct CommandList, list);
49236 /* can't do anything if fifo is full */
49237 - if ((h->access.fifo_full(h))) {
49238 + if ((h->access->fifo_full(h))) {
49239 h->fifo_recently_full = 1;
49240 dev_warn(&h->pdev->dev, "fifo full\n");
49241 break;
49242 @@ -5484,7 +5484,7 @@ static void start_io(struct ctlr_info *h)
49243
49244 /* Tell the controller execute command */
49245 spin_unlock_irqrestore(&h->lock, flags);
49246 - h->access.submit_command(h, c);
49247 + h->access->submit_command(h, c);
49248 spin_lock_irqsave(&h->lock, flags);
49249 }
49250 spin_unlock_irqrestore(&h->lock, flags);
49251 @@ -5492,17 +5492,17 @@ static void start_io(struct ctlr_info *h)
49252
49253 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
49254 {
49255 - return h->access.command_completed(h, q);
49256 + return h->access->command_completed(h, q);
49257 }
49258
49259 static inline bool interrupt_pending(struct ctlr_info *h)
49260 {
49261 - return h->access.intr_pending(h);
49262 + return h->access->intr_pending(h);
49263 }
49264
49265 static inline long interrupt_not_for_us(struct ctlr_info *h)
49266 {
49267 - return (h->access.intr_pending(h) == 0) ||
49268 + return (h->access->intr_pending(h) == 0) ||
49269 (h->interrupts_enabled == 0);
49270 }
49271
49272 @@ -6456,7 +6456,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
49273 if (prod_index < 0)
49274 return -ENODEV;
49275 h->product_name = products[prod_index].product_name;
49276 - h->access = *(products[prod_index].access);
49277 + h->access = products[prod_index].access;
49278
49279 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
49280 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
49281 @@ -6735,7 +6735,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
49282 {
49283 unsigned long flags;
49284
49285 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
49286 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
49287 spin_lock_irqsave(&h->lock, flags);
49288 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
49289 spin_unlock_irqrestore(&h->lock, flags);
49290 @@ -6963,7 +6963,7 @@ reinit_after_soft_reset:
49291 }
49292
49293 /* make sure the board interrupts are off */
49294 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
49295 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
49296
49297 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
49298 goto clean2;
49299 @@ -6998,7 +6998,7 @@ reinit_after_soft_reset:
49300 * fake ones to scoop up any residual completions.
49301 */
49302 spin_lock_irqsave(&h->lock, flags);
49303 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
49304 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
49305 spin_unlock_irqrestore(&h->lock, flags);
49306 free_irqs(h);
49307 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
49308 @@ -7017,9 +7017,9 @@ reinit_after_soft_reset:
49309 dev_info(&h->pdev->dev, "Board READY.\n");
49310 dev_info(&h->pdev->dev,
49311 "Waiting for stale completions to drain.\n");
49312 - h->access.set_intr_mask(h, HPSA_INTR_ON);
49313 + h->access->set_intr_mask(h, HPSA_INTR_ON);
49314 msleep(10000);
49315 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
49316 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
49317
49318 rc = controller_reset_failed(h->cfgtable);
49319 if (rc)
49320 @@ -7045,7 +7045,7 @@ reinit_after_soft_reset:
49321 h->drv_req_rescan = 0;
49322
49323 /* Turn the interrupts on so we can service requests */
49324 - h->access.set_intr_mask(h, HPSA_INTR_ON);
49325 + h->access->set_intr_mask(h, HPSA_INTR_ON);
49326
49327 hpsa_hba_inquiry(h);
49328 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
49329 @@ -7114,7 +7114,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
49330 * To write all data in the battery backed cache to disks
49331 */
49332 hpsa_flush_cache(h);
49333 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
49334 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
49335 hpsa_free_irqs_and_disable_msix(h);
49336 }
49337
49338 @@ -7232,7 +7232,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
49339 CFGTBL_Trans_enable_directed_msix |
49340 (trans_support & (CFGTBL_Trans_io_accel1 |
49341 CFGTBL_Trans_io_accel2));
49342 - struct access_method access = SA5_performant_access;
49343 + struct access_method *access = &SA5_performant_access;
49344
49345 /* This is a bit complicated. There are 8 registers on
49346 * the controller which we write to to tell it 8 different
49347 @@ -7297,12 +7297,12 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
49348 * enable outbound interrupt coalescing in accelerator mode;
49349 */
49350 if (trans_support & CFGTBL_Trans_io_accel1) {
49351 - access = SA5_ioaccel_mode1_access;
49352 + access = &SA5_ioaccel_mode1_access;
49353 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
49354 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
49355 } else {
49356 if (trans_support & CFGTBL_Trans_io_accel2) {
49357 - access = SA5_ioaccel_mode2_access;
49358 + access = &SA5_ioaccel_mode2_access;
49359 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
49360 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
49361 }
49362 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
49363 index 44235a2..962e91b 100644
49364 --- a/drivers/scsi/hpsa.h
49365 +++ b/drivers/scsi/hpsa.h
49366 @@ -128,7 +128,7 @@ struct ctlr_info {
49367 unsigned int msix_vector;
49368 unsigned int msi_vector;
49369 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
49370 - struct access_method access;
49371 + struct access_method *access;
49372 char hba_mode_enabled;
49373
49374 /* queue and queue Info */
49375 @@ -541,35 +541,35 @@ static unsigned long SA5_ioaccel_mode1_completed(struct ctlr_info *h, u8 q)
49376 }
49377
49378 static struct access_method SA5_access = {
49379 - SA5_submit_command,
49380 - SA5_intr_mask,
49381 - SA5_fifo_full,
49382 - SA5_intr_pending,
49383 - SA5_completed,
49384 + .submit_command = SA5_submit_command,
49385 + .set_intr_mask = SA5_intr_mask,
49386 + .fifo_full = SA5_fifo_full,
49387 + .intr_pending = SA5_intr_pending,
49388 + .command_completed = SA5_completed,
49389 };
49390
49391 static struct access_method SA5_ioaccel_mode1_access = {
49392 - SA5_submit_command,
49393 - SA5_performant_intr_mask,
49394 - SA5_fifo_full,
49395 - SA5_ioaccel_mode1_intr_pending,
49396 - SA5_ioaccel_mode1_completed,
49397 + .submit_command = SA5_submit_command,
49398 + .set_intr_mask = SA5_performant_intr_mask,
49399 + .fifo_full = SA5_fifo_full,
49400 + .intr_pending = SA5_ioaccel_mode1_intr_pending,
49401 + .command_completed = SA5_ioaccel_mode1_completed,
49402 };
49403
49404 static struct access_method SA5_ioaccel_mode2_access = {
49405 - SA5_submit_command_ioaccel2,
49406 - SA5_performant_intr_mask,
49407 - SA5_fifo_full,
49408 - SA5_performant_intr_pending,
49409 - SA5_performant_completed,
49410 + .submit_command = SA5_submit_command_ioaccel2,
49411 + .set_intr_mask = SA5_performant_intr_mask,
49412 + .fifo_full = SA5_fifo_full,
49413 + .intr_pending = SA5_performant_intr_pending,
49414 + .command_completed = SA5_performant_completed,
49415 };
49416
49417 static struct access_method SA5_performant_access = {
49418 - SA5_submit_command,
49419 - SA5_performant_intr_mask,
49420 - SA5_fifo_full,
49421 - SA5_performant_intr_pending,
49422 - SA5_performant_completed,
49423 + .submit_command = SA5_submit_command,
49424 + .set_intr_mask = SA5_performant_intr_mask,
49425 + .fifo_full = SA5_fifo_full,
49426 + .intr_pending = SA5_performant_intr_pending,
49427 + .command_completed = SA5_performant_completed,
49428 };
49429
49430 struct board_type {
49431 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
49432 index 1b3a094..068e683 100644
49433 --- a/drivers/scsi/libfc/fc_exch.c
49434 +++ b/drivers/scsi/libfc/fc_exch.c
49435 @@ -101,12 +101,12 @@ struct fc_exch_mgr {
49436 u16 pool_max_index;
49437
49438 struct {
49439 - atomic_t no_free_exch;
49440 - atomic_t no_free_exch_xid;
49441 - atomic_t xid_not_found;
49442 - atomic_t xid_busy;
49443 - atomic_t seq_not_found;
49444 - atomic_t non_bls_resp;
49445 + atomic_unchecked_t no_free_exch;
49446 + atomic_unchecked_t no_free_exch_xid;
49447 + atomic_unchecked_t xid_not_found;
49448 + atomic_unchecked_t xid_busy;
49449 + atomic_unchecked_t seq_not_found;
49450 + atomic_unchecked_t non_bls_resp;
49451 } stats;
49452 };
49453
49454 @@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
49455 /* allocate memory for exchange */
49456 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
49457 if (!ep) {
49458 - atomic_inc(&mp->stats.no_free_exch);
49459 + atomic_inc_unchecked(&mp->stats.no_free_exch);
49460 goto out;
49461 }
49462 memset(ep, 0, sizeof(*ep));
49463 @@ -874,7 +874,7 @@ out:
49464 return ep;
49465 err:
49466 spin_unlock_bh(&pool->lock);
49467 - atomic_inc(&mp->stats.no_free_exch_xid);
49468 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
49469 mempool_free(ep, mp->ep_pool);
49470 return NULL;
49471 }
49472 @@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49473 xid = ntohs(fh->fh_ox_id); /* we originated exch */
49474 ep = fc_exch_find(mp, xid);
49475 if (!ep) {
49476 - atomic_inc(&mp->stats.xid_not_found);
49477 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49478 reject = FC_RJT_OX_ID;
49479 goto out;
49480 }
49481 @@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49482 ep = fc_exch_find(mp, xid);
49483 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
49484 if (ep) {
49485 - atomic_inc(&mp->stats.xid_busy);
49486 + atomic_inc_unchecked(&mp->stats.xid_busy);
49487 reject = FC_RJT_RX_ID;
49488 goto rel;
49489 }
49490 @@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49491 }
49492 xid = ep->xid; /* get our XID */
49493 } else if (!ep) {
49494 - atomic_inc(&mp->stats.xid_not_found);
49495 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49496 reject = FC_RJT_RX_ID; /* XID not found */
49497 goto out;
49498 }
49499 @@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49500 } else {
49501 sp = &ep->seq;
49502 if (sp->id != fh->fh_seq_id) {
49503 - atomic_inc(&mp->stats.seq_not_found);
49504 + atomic_inc_unchecked(&mp->stats.seq_not_found);
49505 if (f_ctl & FC_FC_END_SEQ) {
49506 /*
49507 * Update sequence_id based on incoming last
49508 @@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49509
49510 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
49511 if (!ep) {
49512 - atomic_inc(&mp->stats.xid_not_found);
49513 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49514 goto out;
49515 }
49516 if (ep->esb_stat & ESB_ST_COMPLETE) {
49517 - atomic_inc(&mp->stats.xid_not_found);
49518 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49519 goto rel;
49520 }
49521 if (ep->rxid == FC_XID_UNKNOWN)
49522 ep->rxid = ntohs(fh->fh_rx_id);
49523 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
49524 - atomic_inc(&mp->stats.xid_not_found);
49525 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49526 goto rel;
49527 }
49528 if (ep->did != ntoh24(fh->fh_s_id) &&
49529 ep->did != FC_FID_FLOGI) {
49530 - atomic_inc(&mp->stats.xid_not_found);
49531 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49532 goto rel;
49533 }
49534 sof = fr_sof(fp);
49535 @@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49536 sp->ssb_stat |= SSB_ST_RESP;
49537 sp->id = fh->fh_seq_id;
49538 } else if (sp->id != fh->fh_seq_id) {
49539 - atomic_inc(&mp->stats.seq_not_found);
49540 + atomic_inc_unchecked(&mp->stats.seq_not_found);
49541 goto rel;
49542 }
49543
49544 @@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49545 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
49546
49547 if (!sp)
49548 - atomic_inc(&mp->stats.xid_not_found);
49549 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49550 else
49551 - atomic_inc(&mp->stats.non_bls_resp);
49552 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
49553
49554 fc_frame_free(fp);
49555 }
49556 @@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
49557
49558 list_for_each_entry(ema, &lport->ema_list, ema_list) {
49559 mp = ema->mp;
49560 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
49561 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
49562 st->fc_no_free_exch_xid +=
49563 - atomic_read(&mp->stats.no_free_exch_xid);
49564 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
49565 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
49566 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
49567 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
49568 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
49569 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
49570 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
49571 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
49572 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
49573 }
49574 }
49575 EXPORT_SYMBOL(fc_exch_update_stats);
49576 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
49577 index 766098a..1c6c971 100644
49578 --- a/drivers/scsi/libsas/sas_ata.c
49579 +++ b/drivers/scsi/libsas/sas_ata.c
49580 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
49581 .postreset = ata_std_postreset,
49582 .error_handler = ata_std_error_handler,
49583 .post_internal_cmd = sas_ata_post_internal,
49584 - .qc_defer = ata_std_qc_defer,
49585 + .qc_defer = ata_std_qc_defer,
49586 .qc_prep = ata_noop_qc_prep,
49587 .qc_issue = sas_ata_qc_issue,
49588 .qc_fill_rtf = sas_ata_qc_fill_rtf,
49589 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
49590 index 94a3caf..a118dec 100644
49591 --- a/drivers/scsi/lpfc/lpfc.h
49592 +++ b/drivers/scsi/lpfc/lpfc.h
49593 @@ -430,7 +430,7 @@ struct lpfc_vport {
49594 struct dentry *debug_nodelist;
49595 struct dentry *vport_debugfs_root;
49596 struct lpfc_debugfs_trc *disc_trc;
49597 - atomic_t disc_trc_cnt;
49598 + atomic_unchecked_t disc_trc_cnt;
49599 #endif
49600 uint8_t stat_data_enabled;
49601 uint8_t stat_data_blocked;
49602 @@ -879,8 +879,8 @@ struct lpfc_hba {
49603 struct timer_list fabric_block_timer;
49604 unsigned long bit_flags;
49605 #define FABRIC_COMANDS_BLOCKED 0
49606 - atomic_t num_rsrc_err;
49607 - atomic_t num_cmd_success;
49608 + atomic_unchecked_t num_rsrc_err;
49609 + atomic_unchecked_t num_cmd_success;
49610 unsigned long last_rsrc_error_time;
49611 unsigned long last_ramp_down_time;
49612 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
49613 @@ -915,7 +915,7 @@ struct lpfc_hba {
49614
49615 struct dentry *debug_slow_ring_trc;
49616 struct lpfc_debugfs_trc *slow_ring_trc;
49617 - atomic_t slow_ring_trc_cnt;
49618 + atomic_unchecked_t slow_ring_trc_cnt;
49619 /* iDiag debugfs sub-directory */
49620 struct dentry *idiag_root;
49621 struct dentry *idiag_pci_cfg;
49622 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
49623 index 828c08e..e3378e0 100644
49624 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
49625 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
49626 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
49627
49628 #include <linux/debugfs.h>
49629
49630 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49631 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49632 static unsigned long lpfc_debugfs_start_time = 0L;
49633
49634 /* iDiag */
49635 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
49636 lpfc_debugfs_enable = 0;
49637
49638 len = 0;
49639 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
49640 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
49641 (lpfc_debugfs_max_disc_trc - 1);
49642 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
49643 dtp = vport->disc_trc + i;
49644 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
49645 lpfc_debugfs_enable = 0;
49646
49647 len = 0;
49648 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
49649 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
49650 (lpfc_debugfs_max_slow_ring_trc - 1);
49651 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
49652 dtp = phba->slow_ring_trc + i;
49653 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
49654 !vport || !vport->disc_trc)
49655 return;
49656
49657 - index = atomic_inc_return(&vport->disc_trc_cnt) &
49658 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
49659 (lpfc_debugfs_max_disc_trc - 1);
49660 dtp = vport->disc_trc + index;
49661 dtp->fmt = fmt;
49662 dtp->data1 = data1;
49663 dtp->data2 = data2;
49664 dtp->data3 = data3;
49665 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49666 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49667 dtp->jif = jiffies;
49668 #endif
49669 return;
49670 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
49671 !phba || !phba->slow_ring_trc)
49672 return;
49673
49674 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
49675 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
49676 (lpfc_debugfs_max_slow_ring_trc - 1);
49677 dtp = phba->slow_ring_trc + index;
49678 dtp->fmt = fmt;
49679 dtp->data1 = data1;
49680 dtp->data2 = data2;
49681 dtp->data3 = data3;
49682 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49683 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49684 dtp->jif = jiffies;
49685 #endif
49686 return;
49687 @@ -4268,7 +4268,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49688 "slow_ring buffer\n");
49689 goto debug_failed;
49690 }
49691 - atomic_set(&phba->slow_ring_trc_cnt, 0);
49692 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
49693 memset(phba->slow_ring_trc, 0,
49694 (sizeof(struct lpfc_debugfs_trc) *
49695 lpfc_debugfs_max_slow_ring_trc));
49696 @@ -4314,7 +4314,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49697 "buffer\n");
49698 goto debug_failed;
49699 }
49700 - atomic_set(&vport->disc_trc_cnt, 0);
49701 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
49702
49703 snprintf(name, sizeof(name), "discovery_trace");
49704 vport->debug_disc_trc =
49705 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
49706 index 635eeb3..038aef6 100644
49707 --- a/drivers/scsi/lpfc/lpfc_init.c
49708 +++ b/drivers/scsi/lpfc/lpfc_init.c
49709 @@ -11194,8 +11194,10 @@ lpfc_init(void)
49710 "misc_register returned with status %d", error);
49711
49712 if (lpfc_enable_npiv) {
49713 - lpfc_transport_functions.vport_create = lpfc_vport_create;
49714 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49715 + pax_open_kernel();
49716 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
49717 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49718 + pax_close_kernel();
49719 }
49720 lpfc_transport_template =
49721 fc_attach_transport(&lpfc_transport_functions);
49722 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
49723 index 462453e..c0023a6 100644
49724 --- a/drivers/scsi/lpfc/lpfc_scsi.c
49725 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
49726 @@ -382,7 +382,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
49727 uint32_t evt_posted;
49728
49729 spin_lock_irqsave(&phba->hbalock, flags);
49730 - atomic_inc(&phba->num_rsrc_err);
49731 + atomic_inc_unchecked(&phba->num_rsrc_err);
49732 phba->last_rsrc_error_time = jiffies;
49733
49734 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
49735 @@ -423,8 +423,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49736 unsigned long num_rsrc_err, num_cmd_success;
49737 int i;
49738
49739 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
49740 - num_cmd_success = atomic_read(&phba->num_cmd_success);
49741 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
49742 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
49743
49744 /*
49745 * The error and success command counters are global per
49746 @@ -452,8 +452,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49747 }
49748 }
49749 lpfc_destroy_vport_work_array(phba, vports);
49750 - atomic_set(&phba->num_rsrc_err, 0);
49751 - atomic_set(&phba->num_cmd_success, 0);
49752 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
49753 + atomic_set_unchecked(&phba->num_cmd_success, 0);
49754 }
49755
49756 /**
49757 diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49758 index 6fd7d40..b444223 100644
49759 --- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49760 +++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49761 @@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
49762 {
49763 struct scsi_device *sdev = to_scsi_device(dev);
49764 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49765 - static struct _raid_device *raid_device;
49766 + struct _raid_device *raid_device;
49767 unsigned long flags;
49768 Mpi2RaidVolPage0_t vol_pg0;
49769 Mpi2ConfigReply_t mpi_reply;
49770 @@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
49771 {
49772 struct scsi_device *sdev = to_scsi_device(dev);
49773 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49774 - static struct _raid_device *raid_device;
49775 + struct _raid_device *raid_device;
49776 unsigned long flags;
49777 Mpi2RaidVolPage0_t vol_pg0;
49778 Mpi2ConfigReply_t mpi_reply;
49779 @@ -6637,7 +6637,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
49780 struct fw_event_work *fw_event)
49781 {
49782 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
49783 - static struct _raid_device *raid_device;
49784 + struct _raid_device *raid_device;
49785 unsigned long flags;
49786 u16 handle;
49787
49788 @@ -7108,7 +7108,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
49789 u64 sas_address;
49790 struct _sas_device *sas_device;
49791 struct _sas_node *expander_device;
49792 - static struct _raid_device *raid_device;
49793 + struct _raid_device *raid_device;
49794 u8 retry_count;
49795 unsigned long flags;
49796
49797 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
49798 index be8ce54..94ed33a 100644
49799 --- a/drivers/scsi/pmcraid.c
49800 +++ b/drivers/scsi/pmcraid.c
49801 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
49802 res->scsi_dev = scsi_dev;
49803 scsi_dev->hostdata = res;
49804 res->change_detected = 0;
49805 - atomic_set(&res->read_failures, 0);
49806 - atomic_set(&res->write_failures, 0);
49807 + atomic_set_unchecked(&res->read_failures, 0);
49808 + atomic_set_unchecked(&res->write_failures, 0);
49809 rc = 0;
49810 }
49811 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
49812 @@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
49813
49814 /* If this was a SCSI read/write command keep count of errors */
49815 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
49816 - atomic_inc(&res->read_failures);
49817 + atomic_inc_unchecked(&res->read_failures);
49818 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
49819 - atomic_inc(&res->write_failures);
49820 + atomic_inc_unchecked(&res->write_failures);
49821
49822 if (!RES_IS_GSCSI(res->cfg_entry) &&
49823 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
49824 @@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
49825 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49826 * hrrq_id assigned here in queuecommand
49827 */
49828 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49829 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49830 pinstance->num_hrrq;
49831 cmd->cmd_done = pmcraid_io_done;
49832
49833 @@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
49834 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49835 * hrrq_id assigned here in queuecommand
49836 */
49837 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49838 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49839 pinstance->num_hrrq;
49840
49841 if (request_size) {
49842 @@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
49843
49844 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
49845 /* add resources only after host is added into system */
49846 - if (!atomic_read(&pinstance->expose_resources))
49847 + if (!atomic_read_unchecked(&pinstance->expose_resources))
49848 return;
49849
49850 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
49851 @@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
49852 init_waitqueue_head(&pinstance->reset_wait_q);
49853
49854 atomic_set(&pinstance->outstanding_cmds, 0);
49855 - atomic_set(&pinstance->last_message_id, 0);
49856 - atomic_set(&pinstance->expose_resources, 0);
49857 + atomic_set_unchecked(&pinstance->last_message_id, 0);
49858 + atomic_set_unchecked(&pinstance->expose_resources, 0);
49859
49860 INIT_LIST_HEAD(&pinstance->free_res_q);
49861 INIT_LIST_HEAD(&pinstance->used_res_q);
49862 @@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
49863 /* Schedule worker thread to handle CCN and take care of adding and
49864 * removing devices to OS
49865 */
49866 - atomic_set(&pinstance->expose_resources, 1);
49867 + atomic_set_unchecked(&pinstance->expose_resources, 1);
49868 schedule_work(&pinstance->worker_q);
49869 return rc;
49870
49871 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
49872 index e1d150f..6c6df44 100644
49873 --- a/drivers/scsi/pmcraid.h
49874 +++ b/drivers/scsi/pmcraid.h
49875 @@ -748,7 +748,7 @@ struct pmcraid_instance {
49876 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
49877
49878 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
49879 - atomic_t last_message_id;
49880 + atomic_unchecked_t last_message_id;
49881
49882 /* configuration table */
49883 struct pmcraid_config_table *cfg_table;
49884 @@ -777,7 +777,7 @@ struct pmcraid_instance {
49885 atomic_t outstanding_cmds;
49886
49887 /* should add/delete resources to mid-layer now ?*/
49888 - atomic_t expose_resources;
49889 + atomic_unchecked_t expose_resources;
49890
49891
49892
49893 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
49894 struct pmcraid_config_table_entry_ext cfg_entry_ext;
49895 };
49896 struct scsi_device *scsi_dev; /* Link scsi_device structure */
49897 - atomic_t read_failures; /* count of failed READ commands */
49898 - atomic_t write_failures; /* count of failed WRITE commands */
49899 + atomic_unchecked_t read_failures; /* count of failed READ commands */
49900 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
49901
49902 /* To indicate add/delete/modify during CCN */
49903 u8 change_detected;
49904 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
49905 index 07befcf..c0bff13 100644
49906 --- a/drivers/scsi/qla2xxx/qla_attr.c
49907 +++ b/drivers/scsi/qla2xxx/qla_attr.c
49908 @@ -2188,7 +2188,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
49909 return 0;
49910 }
49911
49912 -struct fc_function_template qla2xxx_transport_functions = {
49913 +fc_function_template_no_const qla2xxx_transport_functions = {
49914
49915 .show_host_node_name = 1,
49916 .show_host_port_name = 1,
49917 @@ -2236,7 +2236,7 @@ struct fc_function_template qla2xxx_transport_functions = {
49918 .bsg_timeout = qla24xx_bsg_timeout,
49919 };
49920
49921 -struct fc_function_template qla2xxx_transport_vport_functions = {
49922 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
49923
49924 .show_host_node_name = 1,
49925 .show_host_port_name = 1,
49926 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
49927 index e665e81..16e84e6 100644
49928 --- a/drivers/scsi/qla2xxx/qla_gbl.h
49929 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
49930 @@ -557,8 +557,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
49931 struct device_attribute;
49932 extern struct device_attribute *qla2x00_host_attrs[];
49933 struct fc_function_template;
49934 -extern struct fc_function_template qla2xxx_transport_functions;
49935 -extern struct fc_function_template qla2xxx_transport_vport_functions;
49936 +extern fc_function_template_no_const qla2xxx_transport_functions;
49937 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
49938 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
49939 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
49940 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
49941 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
49942 index 19e99cc..b3c0b7b 100644
49943 --- a/drivers/scsi/qla2xxx/qla_os.c
49944 +++ b/drivers/scsi/qla2xxx/qla_os.c
49945 @@ -1493,8 +1493,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
49946 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
49947 /* Ok, a 64bit DMA mask is applicable. */
49948 ha->flags.enable_64bit_addressing = 1;
49949 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49950 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49951 + pax_open_kernel();
49952 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49953 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49954 + pax_close_kernel();
49955 return;
49956 }
49957 }
49958 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
49959 index 73a5022..4e0797c 100644
49960 --- a/drivers/scsi/qla4xxx/ql4_def.h
49961 +++ b/drivers/scsi/qla4xxx/ql4_def.h
49962 @@ -305,7 +305,7 @@ struct ddb_entry {
49963 * (4000 only) */
49964 atomic_t relogin_timer; /* Max Time to wait for
49965 * relogin to complete */
49966 - atomic_t relogin_retry_count; /* Num of times relogin has been
49967 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
49968 * retried */
49969 uint32_t default_time2wait; /* Default Min time between
49970 * relogins (+aens) */
49971 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
49972 index 459b9f7..2930a68 100644
49973 --- a/drivers/scsi/qla4xxx/ql4_os.c
49974 +++ b/drivers/scsi/qla4xxx/ql4_os.c
49975 @@ -4499,12 +4499,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
49976 */
49977 if (!iscsi_is_session_online(cls_sess)) {
49978 /* Reset retry relogin timer */
49979 - atomic_inc(&ddb_entry->relogin_retry_count);
49980 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
49981 DEBUG2(ql4_printk(KERN_INFO, ha,
49982 "%s: index[%d] relogin timed out-retrying"
49983 " relogin (%d), retry (%d)\n", __func__,
49984 ddb_entry->fw_ddb_index,
49985 - atomic_read(&ddb_entry->relogin_retry_count),
49986 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
49987 ddb_entry->default_time2wait + 4));
49988 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
49989 atomic_set(&ddb_entry->retry_relogin_timer,
49990 @@ -6609,7 +6609,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
49991
49992 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
49993 atomic_set(&ddb_entry->relogin_timer, 0);
49994 - atomic_set(&ddb_entry->relogin_retry_count, 0);
49995 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
49996 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
49997 ddb_entry->default_relogin_timeout =
49998 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
49999 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
50000 index 88d46fe..7351be5 100644
50001 --- a/drivers/scsi/scsi.c
50002 +++ b/drivers/scsi/scsi.c
50003 @@ -640,7 +640,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
50004 struct Scsi_Host *host = cmd->device->host;
50005 int rtn = 0;
50006
50007 - atomic_inc(&cmd->device->iorequest_cnt);
50008 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
50009
50010 /* check if the device is still usable */
50011 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
50012 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
50013 index d99ab3b..c4ccdef 100644
50014 --- a/drivers/scsi/scsi_lib.c
50015 +++ b/drivers/scsi/scsi_lib.c
50016 @@ -1472,7 +1472,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
50017 shost = sdev->host;
50018 scsi_init_cmd_errh(cmd);
50019 cmd->result = DID_NO_CONNECT << 16;
50020 - atomic_inc(&cmd->device->iorequest_cnt);
50021 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
50022
50023 /*
50024 * SCSI request completion path will do scsi_device_unbusy(),
50025 @@ -1498,9 +1498,9 @@ static void scsi_softirq_done(struct request *rq)
50026
50027 INIT_LIST_HEAD(&cmd->eh_entry);
50028
50029 - atomic_inc(&cmd->device->iodone_cnt);
50030 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
50031 if (cmd->result)
50032 - atomic_inc(&cmd->device->ioerr_cnt);
50033 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
50034
50035 disposition = scsi_decide_disposition(cmd);
50036 if (disposition != SUCCESS &&
50037 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
50038 index 074e8cc..f612e5c 100644
50039 --- a/drivers/scsi/scsi_sysfs.c
50040 +++ b/drivers/scsi/scsi_sysfs.c
50041 @@ -780,7 +780,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
50042 char *buf) \
50043 { \
50044 struct scsi_device *sdev = to_scsi_device(dev); \
50045 - unsigned long long count = atomic_read(&sdev->field); \
50046 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
50047 return snprintf(buf, 20, "0x%llx\n", count); \
50048 } \
50049 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
50050 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
50051 index e51add0..1e06a96 100644
50052 --- a/drivers/scsi/scsi_tgt_lib.c
50053 +++ b/drivers/scsi/scsi_tgt_lib.c
50054 @@ -363,7 +363,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
50055 int err;
50056
50057 dprintk("%lx %u\n", uaddr, len);
50058 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
50059 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
50060 if (err) {
50061 /*
50062 * TODO: need to fixup sg_tablesize, max_segment_size,
50063 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
50064 index f80908f..22aba76 100644
50065 --- a/drivers/scsi/scsi_transport_fc.c
50066 +++ b/drivers/scsi/scsi_transport_fc.c
50067 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
50068 * Netlink Infrastructure
50069 */
50070
50071 -static atomic_t fc_event_seq;
50072 +static atomic_unchecked_t fc_event_seq;
50073
50074 /**
50075 * fc_get_event_number - Obtain the next sequential FC event number
50076 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
50077 u32
50078 fc_get_event_number(void)
50079 {
50080 - return atomic_add_return(1, &fc_event_seq);
50081 + return atomic_add_return_unchecked(1, &fc_event_seq);
50082 }
50083 EXPORT_SYMBOL(fc_get_event_number);
50084
50085 @@ -655,7 +655,7 @@ static __init int fc_transport_init(void)
50086 {
50087 int error;
50088
50089 - atomic_set(&fc_event_seq, 0);
50090 + atomic_set_unchecked(&fc_event_seq, 0);
50091
50092 error = transport_class_register(&fc_host_class);
50093 if (error)
50094 @@ -845,7 +845,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
50095 char *cp;
50096
50097 *val = simple_strtoul(buf, &cp, 0);
50098 - if ((*cp && (*cp != '\n')) || (*val < 0))
50099 + if (*cp && (*cp != '\n'))
50100 return -EINVAL;
50101 /*
50102 * Check for overflow; dev_loss_tmo is u32
50103 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
50104 index 0102a2d..cc3f8e9 100644
50105 --- a/drivers/scsi/scsi_transport_iscsi.c
50106 +++ b/drivers/scsi/scsi_transport_iscsi.c
50107 @@ -79,7 +79,7 @@ struct iscsi_internal {
50108 struct transport_container session_cont;
50109 };
50110
50111 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
50112 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
50113 static struct workqueue_struct *iscsi_eh_timer_workq;
50114
50115 static DEFINE_IDA(iscsi_sess_ida);
50116 @@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
50117 int err;
50118
50119 ihost = shost->shost_data;
50120 - session->sid = atomic_add_return(1, &iscsi_session_nr);
50121 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
50122
50123 if (target_id == ISCSI_MAX_TARGET) {
50124 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
50125 @@ -4511,7 +4511,7 @@ static __init int iscsi_transport_init(void)
50126 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
50127 ISCSI_TRANSPORT_VERSION);
50128
50129 - atomic_set(&iscsi_session_nr, 0);
50130 + atomic_set_unchecked(&iscsi_session_nr, 0);
50131
50132 err = class_register(&iscsi_transport_class);
50133 if (err)
50134 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
50135 index 13e8983..d306a68 100644
50136 --- a/drivers/scsi/scsi_transport_srp.c
50137 +++ b/drivers/scsi/scsi_transport_srp.c
50138 @@ -36,7 +36,7 @@
50139 #include "scsi_transport_srp_internal.h"
50140
50141 struct srp_host_attrs {
50142 - atomic_t next_port_id;
50143 + atomic_unchecked_t next_port_id;
50144 };
50145 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
50146
50147 @@ -101,7 +101,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
50148 struct Scsi_Host *shost = dev_to_shost(dev);
50149 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
50150
50151 - atomic_set(&srp_host->next_port_id, 0);
50152 + atomic_set_unchecked(&srp_host->next_port_id, 0);
50153 return 0;
50154 }
50155
50156 @@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
50157 rport_fast_io_fail_timedout);
50158 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
50159
50160 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
50161 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
50162 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
50163
50164 transport_setup_device(&rport->dev);
50165 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
50166 index bffbd4b..cb1b68a 100644
50167 --- a/drivers/scsi/sd.c
50168 +++ b/drivers/scsi/sd.c
50169 @@ -2971,7 +2971,7 @@ static int sd_probe(struct device *dev)
50170 sdkp->disk = gd;
50171 sdkp->index = index;
50172 atomic_set(&sdkp->openers, 0);
50173 - atomic_set(&sdkp->device->ioerr_cnt, 0);
50174 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
50175
50176 if (!sdp->request_queue->rq_timeout) {
50177 if (sdp->type != TYPE_MOD)
50178 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
50179 index df5e961..df6b97f 100644
50180 --- a/drivers/scsi/sg.c
50181 +++ b/drivers/scsi/sg.c
50182 @@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
50183 sdp->disk->disk_name,
50184 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
50185 NULL,
50186 - (char *)arg);
50187 + (char __user *)arg);
50188 case BLKTRACESTART:
50189 return blk_trace_startstop(sdp->device->request_queue, 1);
50190 case BLKTRACESTOP:
50191 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
50192 index 939edf4..3f50423 100644
50193 --- a/drivers/spi/spi.c
50194 +++ b/drivers/spi/spi.c
50195 @@ -2204,7 +2204,7 @@ int spi_bus_unlock(struct spi_master *master)
50196 EXPORT_SYMBOL_GPL(spi_bus_unlock);
50197
50198 /* portable code must never pass more than 32 bytes */
50199 -#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
50200 +#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
50201
50202 static u8 *buf;
50203
50204 diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
50205 index 2c61783..4d49e4e 100644
50206 --- a/drivers/staging/android/timed_output.c
50207 +++ b/drivers/staging/android/timed_output.c
50208 @@ -25,7 +25,7 @@
50209 #include "timed_output.h"
50210
50211 static struct class *timed_output_class;
50212 -static atomic_t device_count;
50213 +static atomic_unchecked_t device_count;
50214
50215 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
50216 char *buf)
50217 @@ -63,7 +63,7 @@ static int create_timed_output_class(void)
50218 timed_output_class = class_create(THIS_MODULE, "timed_output");
50219 if (IS_ERR(timed_output_class))
50220 return PTR_ERR(timed_output_class);
50221 - atomic_set(&device_count, 0);
50222 + atomic_set_unchecked(&device_count, 0);
50223 timed_output_class->dev_groups = timed_output_groups;
50224 }
50225
50226 @@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
50227 if (ret < 0)
50228 return ret;
50229
50230 - tdev->index = atomic_inc_return(&device_count);
50231 + tdev->index = atomic_inc_return_unchecked(&device_count);
50232 tdev->dev = device_create(timed_output_class, NULL,
50233 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
50234 if (IS_ERR(tdev->dev))
50235 diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
50236 index fe47cd3..19a1bd1 100644
50237 --- a/drivers/staging/gdm724x/gdm_tty.c
50238 +++ b/drivers/staging/gdm724x/gdm_tty.c
50239 @@ -44,7 +44,7 @@
50240 #define gdm_tty_send_control(n, r, v, d, l) (\
50241 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
50242
50243 -#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
50244 +#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
50245
50246 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
50247 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
50248 diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
50249 index c270c9a..94ddf82 100644
50250 --- a/drivers/staging/imx-drm/imx-drm-core.c
50251 +++ b/drivers/staging/imx-drm/imx-drm-core.c
50252 @@ -362,7 +362,7 @@ int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc,
50253 if (imxdrm->pipes >= MAX_CRTC)
50254 return -EINVAL;
50255
50256 - if (imxdrm->drm->open_count)
50257 + if (local_read(&imxdrm->drm->open_count))
50258 return -EBUSY;
50259
50260 imx_drm_crtc = kzalloc(sizeof(*imx_drm_crtc), GFP_KERNEL);
50261 diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
50262 index 3f8020c..649fded 100644
50263 --- a/drivers/staging/lustre/lnet/selftest/brw_test.c
50264 +++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
50265 @@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
50266 return 0;
50267 }
50268
50269 -sfw_test_client_ops_t brw_test_client;
50270 -void brw_init_test_client(void)
50271 -{
50272 - brw_test_client.tso_init = brw_client_init;
50273 - brw_test_client.tso_fini = brw_client_fini;
50274 - brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
50275 - brw_test_client.tso_done_rpc = brw_client_done_rpc;
50276 +sfw_test_client_ops_t brw_test_client = {
50277 + .tso_init = brw_client_init,
50278 + .tso_fini = brw_client_fini,
50279 + .tso_prep_rpc = brw_client_prep_rpc,
50280 + .tso_done_rpc = brw_client_done_rpc,
50281 };
50282
50283 srpc_service_t brw_test_service;
50284 diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
50285 index 050723a..fa6fdf1 100644
50286 --- a/drivers/staging/lustre/lnet/selftest/framework.c
50287 +++ b/drivers/staging/lustre/lnet/selftest/framework.c
50288 @@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
50289
50290 extern sfw_test_client_ops_t ping_test_client;
50291 extern srpc_service_t ping_test_service;
50292 -extern void ping_init_test_client(void);
50293 extern void ping_init_test_service(void);
50294
50295 extern sfw_test_client_ops_t brw_test_client;
50296 extern srpc_service_t brw_test_service;
50297 -extern void brw_init_test_client(void);
50298 extern void brw_init_test_service(void);
50299
50300
50301 @@ -1684,12 +1682,10 @@ sfw_startup (void)
50302 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
50303 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
50304
50305 - brw_init_test_client();
50306 brw_init_test_service();
50307 rc = sfw_register_test(&brw_test_service, &brw_test_client);
50308 LASSERT (rc == 0);
50309
50310 - ping_init_test_client();
50311 ping_init_test_service();
50312 rc = sfw_register_test(&ping_test_service, &ping_test_client);
50313 LASSERT (rc == 0);
50314 diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
50315 index 750cac4..e4d751f 100644
50316 --- a/drivers/staging/lustre/lnet/selftest/ping_test.c
50317 +++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
50318 @@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
50319 return 0;
50320 }
50321
50322 -sfw_test_client_ops_t ping_test_client;
50323 -void ping_init_test_client(void)
50324 -{
50325 - ping_test_client.tso_init = ping_client_init;
50326 - ping_test_client.tso_fini = ping_client_fini;
50327 - ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
50328 - ping_test_client.tso_done_rpc = ping_client_done_rpc;
50329 -}
50330 +sfw_test_client_ops_t ping_test_client = {
50331 + .tso_init = ping_client_init,
50332 + .tso_fini = ping_client_fini,
50333 + .tso_prep_rpc = ping_client_prep_rpc,
50334 + .tso_done_rpc = ping_client_done_rpc,
50335 +};
50336
50337 srpc_service_t ping_test_service;
50338 void ping_init_test_service(void)
50339 diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
50340 index 3e25f00..0d59cf5 100644
50341 --- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
50342 +++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
50343 @@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
50344 ldlm_completion_callback lcs_completion;
50345 ldlm_blocking_callback lcs_blocking;
50346 ldlm_glimpse_callback lcs_glimpse;
50347 -};
50348 +} __no_const;
50349
50350 /* ldlm_lockd.c */
50351 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
50352 diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
50353 index 72cf3fe..4beac19 100644
50354 --- a/drivers/staging/lustre/lustre/include/obd.h
50355 +++ b/drivers/staging/lustre/lustre/include/obd.h
50356 @@ -1427,7 +1427,7 @@ struct md_ops {
50357 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
50358 * wrapper function in include/linux/obd_class.h.
50359 */
50360 -};
50361 +} __no_const;
50362
50363 struct lsm_operations {
50364 void (*lsm_free)(struct lov_stripe_md *);
50365 diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
50366 index 986bf38..eab2558f 100644
50367 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
50368 +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
50369 @@ -259,7 +259,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
50370 int added = (mode == LCK_NL);
50371 int overlaps = 0;
50372 int splitted = 0;
50373 - const struct ldlm_callback_suite null_cbs = { NULL };
50374 + const struct ldlm_callback_suite null_cbs = { };
50375
50376 CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
50377 LPU64" end "LPU64"\n", *flags,
50378 diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
50379 index e947b91..f408990 100644
50380 --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
50381 +++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
50382 @@ -217,7 +217,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
50383 int LL_PROC_PROTO(proc_console_max_delay_cs)
50384 {
50385 int rc, max_delay_cs;
50386 - ctl_table_t dummy = *table;
50387 + ctl_table_no_const dummy = *table;
50388 cfs_duration_t d;
50389
50390 dummy.data = &max_delay_cs;
50391 @@ -248,7 +248,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
50392 int LL_PROC_PROTO(proc_console_min_delay_cs)
50393 {
50394 int rc, min_delay_cs;
50395 - ctl_table_t dummy = *table;
50396 + ctl_table_no_const dummy = *table;
50397 cfs_duration_t d;
50398
50399 dummy.data = &min_delay_cs;
50400 @@ -279,7 +279,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
50401 int LL_PROC_PROTO(proc_console_backoff)
50402 {
50403 int rc, backoff;
50404 - ctl_table_t dummy = *table;
50405 + ctl_table_no_const dummy = *table;
50406
50407 dummy.data = &backoff;
50408 dummy.proc_handler = &proc_dointvec;
50409 diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
50410 index 24ae26d..9d09cab 100644
50411 --- a/drivers/staging/lustre/lustre/libcfs/module.c
50412 +++ b/drivers/staging/lustre/lustre/libcfs/module.c
50413 @@ -313,11 +313,11 @@ out:
50414
50415
50416 struct cfs_psdev_ops libcfs_psdev_ops = {
50417 - libcfs_psdev_open,
50418 - libcfs_psdev_release,
50419 - NULL,
50420 - NULL,
50421 - libcfs_ioctl
50422 + .p_open = libcfs_psdev_open,
50423 + .p_close = libcfs_psdev_release,
50424 + .p_read = NULL,
50425 + .p_write = NULL,
50426 + .p_ioctl = libcfs_ioctl
50427 };
50428
50429 extern int insert_proc(void);
50430 diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
50431 index 7fbc18e..f982071 100644
50432 --- a/drivers/staging/lustre/lustre/llite/dir.c
50433 +++ b/drivers/staging/lustre/lustre/llite/dir.c
50434 @@ -660,7 +660,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
50435 int mode;
50436 int err;
50437
50438 - mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
50439 + mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
50440 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
50441 strlen(filename), mode, LUSTRE_OPC_MKDIR,
50442 lump);
50443 diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
50444 index f670469..03b7438 100644
50445 --- a/drivers/staging/media/solo6x10/solo6x10-core.c
50446 +++ b/drivers/staging/media/solo6x10/solo6x10-core.c
50447 @@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
50448
50449 static int solo_sysfs_init(struct solo_dev *solo_dev)
50450 {
50451 - struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
50452 + bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
50453 struct device *dev = &solo_dev->dev;
50454 const char *driver;
50455 int i;
50456 diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
50457 index 74f037b..5b5bb76 100644
50458 --- a/drivers/staging/media/solo6x10/solo6x10-g723.c
50459 +++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
50460 @@ -355,7 +355,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
50461
50462 int solo_g723_init(struct solo_dev *solo_dev)
50463 {
50464 - static struct snd_device_ops ops = { NULL };
50465 + static struct snd_device_ops ops = { };
50466 struct snd_card *card;
50467 struct snd_kcontrol_new kctl;
50468 char name[32];
50469 diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
50470 index 7f2f247..d999137 100644
50471 --- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
50472 +++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
50473 @@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
50474
50475 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
50476 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
50477 - p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
50478 + p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
50479 if (p2m_id < 0)
50480 p2m_id = -p2m_id;
50481 }
50482 diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
50483 index 8964f8b..36eb087 100644
50484 --- a/drivers/staging/media/solo6x10/solo6x10.h
50485 +++ b/drivers/staging/media/solo6x10/solo6x10.h
50486 @@ -237,7 +237,7 @@ struct solo_dev {
50487
50488 /* P2M DMA Engine */
50489 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
50490 - atomic_t p2m_count;
50491 + atomic_unchecked_t p2m_count;
50492 int p2m_jiffies;
50493 unsigned int p2m_timeouts;
50494
50495 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
50496 index a0f4868..139f1fb 100644
50497 --- a/drivers/staging/octeon/ethernet-rx.c
50498 +++ b/drivers/staging/octeon/ethernet-rx.c
50499 @@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
50500 /* Increment RX stats for virtual ports */
50501 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
50502 #ifdef CONFIG_64BIT
50503 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
50504 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
50505 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
50506 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
50507 #else
50508 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
50509 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
50510 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
50511 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
50512 #endif
50513 }
50514 netif_receive_skb(skb);
50515 @@ -432,9 +432,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
50516 dev->name);
50517 */
50518 #ifdef CONFIG_64BIT
50519 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
50520 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
50521 #else
50522 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
50523 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
50524 #endif
50525 dev_kfree_skb_irq(skb);
50526 }
50527 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
50528 index ff7214a..6dd90f0 100644
50529 --- a/drivers/staging/octeon/ethernet.c
50530 +++ b/drivers/staging/octeon/ethernet.c
50531 @@ -247,11 +247,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
50532 * since the RX tasklet also increments it.
50533 */
50534 #ifdef CONFIG_64BIT
50535 - atomic64_add(rx_status.dropped_packets,
50536 - (atomic64_t *)&priv->stats.rx_dropped);
50537 + atomic64_add_unchecked(rx_status.dropped_packets,
50538 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
50539 #else
50540 - atomic_add(rx_status.dropped_packets,
50541 - (atomic_t *)&priv->stats.rx_dropped);
50542 + atomic_add_unchecked(rx_status.dropped_packets,
50543 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
50544 #endif
50545 }
50546
50547 diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
50548 index c274b34..f84de76 100644
50549 --- a/drivers/staging/rtl8188eu/include/hal_intf.h
50550 +++ b/drivers/staging/rtl8188eu/include/hal_intf.h
50551 @@ -271,7 +271,7 @@ struct hal_ops {
50552 s32 (*c2h_handler)(struct adapter *padapter,
50553 struct c2h_evt_hdr *c2h_evt);
50554 c2h_id_filter c2h_id_filter_ccx;
50555 -};
50556 +} __no_const;
50557
50558 enum rt_eeprom_type {
50559 EEPROM_93C46,
50560 diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
50561 index e8790f8..b4a5980 100644
50562 --- a/drivers/staging/rtl8188eu/include/rtw_io.h
50563 +++ b/drivers/staging/rtl8188eu/include/rtw_io.h
50564 @@ -124,7 +124,7 @@ struct _io_ops {
50565 u32 (*_write_scsi)(struct intf_hdl *pintfhdl, u32 cnt, u8 *pmem);
50566 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
50567 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
50568 -};
50569 +} __no_const;
50570
50571 struct io_req {
50572 struct list_head list;
50573 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
50574 index dc23395..cf7e9b1 100644
50575 --- a/drivers/staging/rtl8712/rtl871x_io.h
50576 +++ b/drivers/staging/rtl8712/rtl871x_io.h
50577 @@ -108,7 +108,7 @@ struct _io_ops {
50578 u8 *pmem);
50579 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
50580 u8 *pmem);
50581 -};
50582 +} __no_const;
50583
50584 struct io_req {
50585 struct list_head list;
50586 diff --git a/drivers/staging/rtl8723au/include/hal_intf.h b/drivers/staging/rtl8723au/include/hal_intf.h
50587 index d183f4b..3f4903d 100644
50588 --- a/drivers/staging/rtl8723au/include/hal_intf.h
50589 +++ b/drivers/staging/rtl8723au/include/hal_intf.h
50590 @@ -251,7 +251,7 @@ struct hal_ops {
50591 void (*hal_reset_security_engine)(struct rtw_adapter *adapter);
50592 s32 (*c2h_handler)(struct rtw_adapter *padapter, struct c2h_evt_hdr *c2h_evt);
50593 c2h_id_filter c2h_id_filter_ccx;
50594 -};
50595 +} __no_const;
50596
50597 enum rt_eeprom_type {
50598 EEPROM_93C46,
50599 diff --git a/drivers/staging/rtl8723au/include/rtw_io.h b/drivers/staging/rtl8723au/include/rtw_io.h
50600 index 8d39d800..3f21c0c 100644
50601 --- a/drivers/staging/rtl8723au/include/rtw_io.h
50602 +++ b/drivers/staging/rtl8723au/include/rtw_io.h
50603 @@ -130,7 +130,7 @@ struct _io_ops
50604 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
50605 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
50606
50607 -};
50608 +} __no_const;
50609
50610 struct io_req {
50611 struct list_head list;
50612 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
50613 index fe6c951..72935ba 100644
50614 --- a/drivers/staging/sbe-2t3e3/netdev.c
50615 +++ b/drivers/staging/sbe-2t3e3/netdev.c
50616 @@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50617 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
50618
50619 if (rlen)
50620 - if (copy_to_user(data, &resp, rlen))
50621 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
50622 return -EFAULT;
50623
50624 return 0;
50625 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
50626 index a863a98..d272795 100644
50627 --- a/drivers/staging/usbip/vhci.h
50628 +++ b/drivers/staging/usbip/vhci.h
50629 @@ -83,7 +83,7 @@ struct vhci_hcd {
50630 unsigned resuming:1;
50631 unsigned long re_timeout;
50632
50633 - atomic_t seqnum;
50634 + atomic_unchecked_t seqnum;
50635
50636 /*
50637 * NOTE:
50638 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
50639 index 70e1755..de41855 100644
50640 --- a/drivers/staging/usbip/vhci_hcd.c
50641 +++ b/drivers/staging/usbip/vhci_hcd.c
50642 @@ -439,7 +439,7 @@ static void vhci_tx_urb(struct urb *urb)
50643
50644 spin_lock(&vdev->priv_lock);
50645
50646 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
50647 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50648 if (priv->seqnum == 0xffff)
50649 dev_info(&urb->dev->dev, "seqnum max\n");
50650
50651 @@ -685,7 +685,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
50652 return -ENOMEM;
50653 }
50654
50655 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
50656 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50657 if (unlink->seqnum == 0xffff)
50658 pr_info("seqnum max\n");
50659
50660 @@ -889,7 +889,7 @@ static int vhci_start(struct usb_hcd *hcd)
50661 vdev->rhport = rhport;
50662 }
50663
50664 - atomic_set(&vhci->seqnum, 0);
50665 + atomic_set_unchecked(&vhci->seqnum, 0);
50666 spin_lock_init(&vhci->lock);
50667
50668 hcd->power_budget = 0; /* no limit */
50669 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
50670 index d07fcb5..358e1e1 100644
50671 --- a/drivers/staging/usbip/vhci_rx.c
50672 +++ b/drivers/staging/usbip/vhci_rx.c
50673 @@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
50674 if (!urb) {
50675 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
50676 pr_info("max seqnum %d\n",
50677 - atomic_read(&the_controller->seqnum));
50678 + atomic_read_unchecked(&the_controller->seqnum));
50679 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
50680 return;
50681 }
50682 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
50683 index 6eecd53..29317c6 100644
50684 --- a/drivers/staging/vt6655/hostap.c
50685 +++ b/drivers/staging/vt6655/hostap.c
50686 @@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
50687 *
50688 */
50689
50690 +static net_device_ops_no_const apdev_netdev_ops;
50691 +
50692 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50693 {
50694 PSDevice apdev_priv;
50695 struct net_device *dev = pDevice->dev;
50696 int ret;
50697 - const struct net_device_ops apdev_netdev_ops = {
50698 - .ndo_start_xmit = pDevice->tx_80211,
50699 - };
50700
50701 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50702
50703 @@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50704 *apdev_priv = *pDevice;
50705 eth_hw_addr_inherit(pDevice->apdev, dev);
50706
50707 + /* only half broken now */
50708 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50709 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50710
50711 pDevice->apdev->type = ARPHRD_IEEE80211;
50712 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
50713 index 67ba48b..24e602f 100644
50714 --- a/drivers/staging/vt6656/hostap.c
50715 +++ b/drivers/staging/vt6656/hostap.c
50716 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
50717 *
50718 */
50719
50720 +static net_device_ops_no_const apdev_netdev_ops;
50721 +
50722 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50723 {
50724 struct vnt_private *apdev_priv;
50725 struct net_device *dev = pDevice->dev;
50726 int ret;
50727 - const struct net_device_ops apdev_netdev_ops = {
50728 - .ndo_start_xmit = pDevice->tx_80211,
50729 - };
50730
50731 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50732
50733 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50734 *apdev_priv = *pDevice;
50735 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
50736
50737 + /* only half broken now */
50738 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50739 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50740
50741 pDevice->apdev->type = ARPHRD_IEEE80211;
50742 diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
50743 index e7e9372..161f530 100644
50744 --- a/drivers/target/sbp/sbp_target.c
50745 +++ b/drivers/target/sbp/sbp_target.c
50746 @@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
50747
50748 #define SESSION_MAINTENANCE_INTERVAL HZ
50749
50750 -static atomic_t login_id = ATOMIC_INIT(0);
50751 +static atomic_unchecked_t login_id = ATOMIC_INIT(0);
50752
50753 static void session_maintenance_work(struct work_struct *);
50754 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
50755 @@ -444,7 +444,7 @@ static void sbp_management_request_login(
50756 login->lun = se_lun;
50757 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
50758 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
50759 - login->login_id = atomic_inc_return(&login_id);
50760 + login->login_id = atomic_inc_return_unchecked(&login_id);
50761
50762 login->tgt_agt = sbp_target_agent_register(login);
50763 if (IS_ERR(login->tgt_agt)) {
50764 diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
50765 index 6ea95d2..88607b4 100644
50766 --- a/drivers/target/target_core_device.c
50767 +++ b/drivers/target/target_core_device.c
50768 @@ -1525,7 +1525,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
50769 spin_lock_init(&dev->se_tmr_lock);
50770 spin_lock_init(&dev->qf_cmd_lock);
50771 sema_init(&dev->caw_sem, 1);
50772 - atomic_set(&dev->dev_ordered_id, 0);
50773 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
50774 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
50775 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
50776 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
50777 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
50778 index 14772e9..42d9f63 100644
50779 --- a/drivers/target/target_core_transport.c
50780 +++ b/drivers/target/target_core_transport.c
50781 @@ -1165,7 +1165,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
50782 * Used to determine when ORDERED commands should go from
50783 * Dormant to Active status.
50784 */
50785 - cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
50786 + cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
50787 smp_mb__after_atomic_inc();
50788 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
50789 cmd->se_ordered_id, cmd->sam_task_attr,
50790 diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
50791 index 04b1be7..5eff86d 100644
50792 --- a/drivers/thermal/of-thermal.c
50793 +++ b/drivers/thermal/of-thermal.c
50794 @@ -30,6 +30,7 @@
50795 #include <linux/err.h>
50796 #include <linux/export.h>
50797 #include <linux/string.h>
50798 +#include <linux/mm.h>
50799
50800 #include "thermal_core.h"
50801
50802 @@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
50803 tz->get_trend = get_trend;
50804 tz->sensor_data = data;
50805
50806 - tzd->ops->get_temp = of_thermal_get_temp;
50807 - tzd->ops->get_trend = of_thermal_get_trend;
50808 + pax_open_kernel();
50809 + *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
50810 + *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
50811 + pax_close_kernel();
50812 mutex_unlock(&tzd->lock);
50813
50814 return tzd;
50815 @@ -461,8 +464,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
50816 return;
50817
50818 mutex_lock(&tzd->lock);
50819 - tzd->ops->get_temp = NULL;
50820 - tzd->ops->get_trend = NULL;
50821 + pax_open_kernel();
50822 + *(void **)&tzd->ops->get_temp = NULL;
50823 + *(void **)&tzd->ops->get_trend = NULL;
50824 + pax_close_kernel();
50825
50826 tz->get_temp = NULL;
50827 tz->get_trend = NULL;
50828 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
50829 index a57bb5a..1f727d33 100644
50830 --- a/drivers/tty/cyclades.c
50831 +++ b/drivers/tty/cyclades.c
50832 @@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
50833 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
50834 info->port.count);
50835 #endif
50836 - info->port.count++;
50837 + atomic_inc(&info->port.count);
50838 #ifdef CY_DEBUG_COUNT
50839 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
50840 - current->pid, info->port.count);
50841 + current->pid, atomic_read(&info->port.count));
50842 #endif
50843
50844 /*
50845 @@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
50846 for (j = 0; j < cy_card[i].nports; j++) {
50847 info = &cy_card[i].ports[j];
50848
50849 - if (info->port.count) {
50850 + if (atomic_read(&info->port.count)) {
50851 /* XXX is the ldisc num worth this? */
50852 struct tty_struct *tty;
50853 struct tty_ldisc *ld;
50854 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
50855 index 0ff7fda..dbc7d52 100644
50856 --- a/drivers/tty/hvc/hvc_console.c
50857 +++ b/drivers/tty/hvc/hvc_console.c
50858 @@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
50859
50860 spin_lock_irqsave(&hp->port.lock, flags);
50861 /* Check and then increment for fast path open. */
50862 - if (hp->port.count++ > 0) {
50863 + if (atomic_inc_return(&hp->port.count) > 1) {
50864 spin_unlock_irqrestore(&hp->port.lock, flags);
50865 hvc_kick();
50866 return 0;
50867 @@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50868
50869 spin_lock_irqsave(&hp->port.lock, flags);
50870
50871 - if (--hp->port.count == 0) {
50872 + if (atomic_dec_return(&hp->port.count) == 0) {
50873 spin_unlock_irqrestore(&hp->port.lock, flags);
50874 /* We are done with the tty pointer now. */
50875 tty_port_tty_set(&hp->port, NULL);
50876 @@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50877 */
50878 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
50879 } else {
50880 - if (hp->port.count < 0)
50881 + if (atomic_read(&hp->port.count) < 0)
50882 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
50883 - hp->vtermno, hp->port.count);
50884 + hp->vtermno, atomic_read(&hp->port.count));
50885 spin_unlock_irqrestore(&hp->port.lock, flags);
50886 }
50887 }
50888 @@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
50889 * open->hangup case this can be called after the final close so prevent
50890 * that from happening for now.
50891 */
50892 - if (hp->port.count <= 0) {
50893 + if (atomic_read(&hp->port.count) <= 0) {
50894 spin_unlock_irqrestore(&hp->port.lock, flags);
50895 return;
50896 }
50897
50898 - hp->port.count = 0;
50899 + atomic_set(&hp->port.count, 0);
50900 spin_unlock_irqrestore(&hp->port.lock, flags);
50901 tty_port_tty_set(&hp->port, NULL);
50902
50903 @@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
50904 return -EPIPE;
50905
50906 /* FIXME what's this (unprotected) check for? */
50907 - if (hp->port.count <= 0)
50908 + if (atomic_read(&hp->port.count) <= 0)
50909 return -EIO;
50910
50911 spin_lock_irqsave(&hp->lock, flags);
50912 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
50913 index 81e939e..95ead10 100644
50914 --- a/drivers/tty/hvc/hvcs.c
50915 +++ b/drivers/tty/hvc/hvcs.c
50916 @@ -83,6 +83,7 @@
50917 #include <asm/hvcserver.h>
50918 #include <asm/uaccess.h>
50919 #include <asm/vio.h>
50920 +#include <asm/local.h>
50921
50922 /*
50923 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
50924 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
50925
50926 spin_lock_irqsave(&hvcsd->lock, flags);
50927
50928 - if (hvcsd->port.count > 0) {
50929 + if (atomic_read(&hvcsd->port.count) > 0) {
50930 spin_unlock_irqrestore(&hvcsd->lock, flags);
50931 printk(KERN_INFO "HVCS: vterm state unchanged. "
50932 "The hvcs device node is still in use.\n");
50933 @@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
50934 }
50935 }
50936
50937 - hvcsd->port.count = 0;
50938 + atomic_set(&hvcsd->port.count, 0);
50939 hvcsd->port.tty = tty;
50940 tty->driver_data = hvcsd;
50941
50942 @@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
50943 unsigned long flags;
50944
50945 spin_lock_irqsave(&hvcsd->lock, flags);
50946 - hvcsd->port.count++;
50947 + atomic_inc(&hvcsd->port.count);
50948 hvcsd->todo_mask |= HVCS_SCHED_READ;
50949 spin_unlock_irqrestore(&hvcsd->lock, flags);
50950
50951 @@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50952 hvcsd = tty->driver_data;
50953
50954 spin_lock_irqsave(&hvcsd->lock, flags);
50955 - if (--hvcsd->port.count == 0) {
50956 + if (atomic_dec_and_test(&hvcsd->port.count)) {
50957
50958 vio_disable_interrupts(hvcsd->vdev);
50959
50960 @@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50961
50962 free_irq(irq, hvcsd);
50963 return;
50964 - } else if (hvcsd->port.count < 0) {
50965 + } else if (atomic_read(&hvcsd->port.count) < 0) {
50966 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
50967 " is missmanaged.\n",
50968 - hvcsd->vdev->unit_address, hvcsd->port.count);
50969 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
50970 }
50971
50972 spin_unlock_irqrestore(&hvcsd->lock, flags);
50973 @@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50974
50975 spin_lock_irqsave(&hvcsd->lock, flags);
50976 /* Preserve this so that we know how many kref refs to put */
50977 - temp_open_count = hvcsd->port.count;
50978 + temp_open_count = atomic_read(&hvcsd->port.count);
50979
50980 /*
50981 * Don't kref put inside the spinlock because the destruction
50982 @@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50983 tty->driver_data = NULL;
50984 hvcsd->port.tty = NULL;
50985
50986 - hvcsd->port.count = 0;
50987 + atomic_set(&hvcsd->port.count, 0);
50988
50989 /* This will drop any buffered data on the floor which is OK in a hangup
50990 * scenario. */
50991 @@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
50992 * the middle of a write operation? This is a crummy place to do this
50993 * but we want to keep it all in the spinlock.
50994 */
50995 - if (hvcsd->port.count <= 0) {
50996 + if (atomic_read(&hvcsd->port.count) <= 0) {
50997 spin_unlock_irqrestore(&hvcsd->lock, flags);
50998 return -ENODEV;
50999 }
51000 @@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
51001 {
51002 struct hvcs_struct *hvcsd = tty->driver_data;
51003
51004 - if (!hvcsd || hvcsd->port.count <= 0)
51005 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
51006 return 0;
51007
51008 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
51009 diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
51010 index 4190199..06d5bfa 100644
51011 --- a/drivers/tty/hvc/hvsi.c
51012 +++ b/drivers/tty/hvc/hvsi.c
51013 @@ -85,7 +85,7 @@ struct hvsi_struct {
51014 int n_outbuf;
51015 uint32_t vtermno;
51016 uint32_t virq;
51017 - atomic_t seqno; /* HVSI packet sequence number */
51018 + atomic_unchecked_t seqno; /* HVSI packet sequence number */
51019 uint16_t mctrl;
51020 uint8_t state; /* HVSI protocol state */
51021 uint8_t flags;
51022 @@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
51023
51024 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
51025 packet.hdr.len = sizeof(struct hvsi_query_response);
51026 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
51027 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
51028 packet.verb = VSV_SEND_VERSION_NUMBER;
51029 packet.u.version = HVSI_VERSION;
51030 packet.query_seqno = query_seqno+1;
51031 @@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
51032
51033 packet.hdr.type = VS_QUERY_PACKET_HEADER;
51034 packet.hdr.len = sizeof(struct hvsi_query);
51035 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
51036 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
51037 packet.verb = verb;
51038
51039 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
51040 @@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
51041 int wrote;
51042
51043 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
51044 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
51045 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
51046 packet.hdr.len = sizeof(struct hvsi_control);
51047 packet.verb = VSV_SET_MODEM_CTL;
51048 packet.mask = HVSI_TSDTR;
51049 @@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
51050 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
51051
51052 packet.hdr.type = VS_DATA_PACKET_HEADER;
51053 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
51054 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
51055 packet.hdr.len = count + sizeof(struct hvsi_header);
51056 memcpy(&packet.data, buf, count);
51057
51058 @@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
51059 struct hvsi_control packet __ALIGNED__;
51060
51061 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
51062 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
51063 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
51064 packet.hdr.len = 6;
51065 packet.verb = VSV_CLOSE_PROTOCOL;
51066
51067 @@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
51068
51069 tty_port_tty_set(&hp->port, tty);
51070 spin_lock_irqsave(&hp->lock, flags);
51071 - hp->port.count++;
51072 + atomic_inc(&hp->port.count);
51073 atomic_set(&hp->seqno, 0);
51074 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
51075 spin_unlock_irqrestore(&hp->lock, flags);
51076 @@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
51077
51078 spin_lock_irqsave(&hp->lock, flags);
51079
51080 - if (--hp->port.count == 0) {
51081 + if (atomic_dec_return(&hp->port.count) == 0) {
51082 tty_port_tty_set(&hp->port, NULL);
51083 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
51084
51085 @@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
51086
51087 spin_lock_irqsave(&hp->lock, flags);
51088 }
51089 - } else if (hp->port.count < 0)
51090 + } else if (atomic_read(&hp->port.count) < 0)
51091 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
51092 - hp - hvsi_ports, hp->port.count);
51093 + hp - hvsi_ports, atomic_read(&hp->port.count));
51094
51095 spin_unlock_irqrestore(&hp->lock, flags);
51096 }
51097 @@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
51098 tty_port_tty_set(&hp->port, NULL);
51099
51100 spin_lock_irqsave(&hp->lock, flags);
51101 - hp->port.count = 0;
51102 + atomic_set(&hp->port.count, 0);
51103 hp->n_outbuf = 0;
51104 spin_unlock_irqrestore(&hp->lock, flags);
51105 }
51106 diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
51107 index 7ae6c29..05c6dba 100644
51108 --- a/drivers/tty/hvc/hvsi_lib.c
51109 +++ b/drivers/tty/hvc/hvsi_lib.c
51110 @@ -8,7 +8,7 @@
51111
51112 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
51113 {
51114 - packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
51115 + packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
51116
51117 /* Assumes that always succeeds, works in practice */
51118 return pv->put_chars(pv->termno, (char *)packet, packet->len);
51119 @@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
51120
51121 /* Reset state */
51122 pv->established = 0;
51123 - atomic_set(&pv->seqno, 0);
51124 + atomic_set_unchecked(&pv->seqno, 0);
51125
51126 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
51127
51128 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
51129 index 17ee3bf..8d2520d 100644
51130 --- a/drivers/tty/ipwireless/tty.c
51131 +++ b/drivers/tty/ipwireless/tty.c
51132 @@ -28,6 +28,7 @@
51133 #include <linux/tty_driver.h>
51134 #include <linux/tty_flip.h>
51135 #include <linux/uaccess.h>
51136 +#include <asm/local.h>
51137
51138 #include "tty.h"
51139 #include "network.h"
51140 @@ -98,10 +99,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
51141 mutex_unlock(&tty->ipw_tty_mutex);
51142 return -ENODEV;
51143 }
51144 - if (tty->port.count == 0)
51145 + if (atomic_read(&tty->port.count) == 0)
51146 tty->tx_bytes_queued = 0;
51147
51148 - tty->port.count++;
51149 + atomic_inc(&tty->port.count);
51150
51151 tty->port.tty = linux_tty;
51152 linux_tty->driver_data = tty;
51153 @@ -117,9 +118,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
51154
51155 static void do_ipw_close(struct ipw_tty *tty)
51156 {
51157 - tty->port.count--;
51158 -
51159 - if (tty->port.count == 0) {
51160 + if (atomic_dec_return(&tty->port.count) == 0) {
51161 struct tty_struct *linux_tty = tty->port.tty;
51162
51163 if (linux_tty != NULL) {
51164 @@ -140,7 +139,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
51165 return;
51166
51167 mutex_lock(&tty->ipw_tty_mutex);
51168 - if (tty->port.count == 0) {
51169 + if (atomic_read(&tty->port.count) == 0) {
51170 mutex_unlock(&tty->ipw_tty_mutex);
51171 return;
51172 }
51173 @@ -163,7 +162,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
51174
51175 mutex_lock(&tty->ipw_tty_mutex);
51176
51177 - if (!tty->port.count) {
51178 + if (!atomic_read(&tty->port.count)) {
51179 mutex_unlock(&tty->ipw_tty_mutex);
51180 return;
51181 }
51182 @@ -202,7 +201,7 @@ static int ipw_write(struct tty_struct *linux_tty,
51183 return -ENODEV;
51184
51185 mutex_lock(&tty->ipw_tty_mutex);
51186 - if (!tty->port.count) {
51187 + if (!atomic_read(&tty->port.count)) {
51188 mutex_unlock(&tty->ipw_tty_mutex);
51189 return -EINVAL;
51190 }
51191 @@ -242,7 +241,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
51192 if (!tty)
51193 return -ENODEV;
51194
51195 - if (!tty->port.count)
51196 + if (!atomic_read(&tty->port.count))
51197 return -EINVAL;
51198
51199 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
51200 @@ -284,7 +283,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
51201 if (!tty)
51202 return 0;
51203
51204 - if (!tty->port.count)
51205 + if (!atomic_read(&tty->port.count))
51206 return 0;
51207
51208 return tty->tx_bytes_queued;
51209 @@ -365,7 +364,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
51210 if (!tty)
51211 return -ENODEV;
51212
51213 - if (!tty->port.count)
51214 + if (!atomic_read(&tty->port.count))
51215 return -EINVAL;
51216
51217 return get_control_lines(tty);
51218 @@ -381,7 +380,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
51219 if (!tty)
51220 return -ENODEV;
51221
51222 - if (!tty->port.count)
51223 + if (!atomic_read(&tty->port.count))
51224 return -EINVAL;
51225
51226 return set_control_lines(tty, set, clear);
51227 @@ -395,7 +394,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
51228 if (!tty)
51229 return -ENODEV;
51230
51231 - if (!tty->port.count)
51232 + if (!atomic_read(&tty->port.count))
51233 return -EINVAL;
51234
51235 /* FIXME: Exactly how is the tty object locked here .. */
51236 @@ -551,7 +550,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
51237 * are gone */
51238 mutex_lock(&ttyj->ipw_tty_mutex);
51239 }
51240 - while (ttyj->port.count)
51241 + while (atomic_read(&ttyj->port.count))
51242 do_ipw_close(ttyj);
51243 ipwireless_disassociate_network_ttys(network,
51244 ttyj->channel_idx);
51245 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
51246 index 1deaca4..c8582d4 100644
51247 --- a/drivers/tty/moxa.c
51248 +++ b/drivers/tty/moxa.c
51249 @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
51250 }
51251
51252 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
51253 - ch->port.count++;
51254 + atomic_inc(&ch->port.count);
51255 tty->driver_data = ch;
51256 tty_port_tty_set(&ch->port, tty);
51257 mutex_lock(&ch->port.mutex);
51258 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
51259 index 2ebe47b..3205833 100644
51260 --- a/drivers/tty/n_gsm.c
51261 +++ b/drivers/tty/n_gsm.c
51262 @@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
51263 spin_lock_init(&dlci->lock);
51264 mutex_init(&dlci->mutex);
51265 dlci->fifo = &dlci->_fifo;
51266 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
51267 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
51268 kfree(dlci);
51269 return NULL;
51270 }
51271 @@ -2954,7 +2954,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
51272 struct gsm_dlci *dlci = tty->driver_data;
51273 struct tty_port *port = &dlci->port;
51274
51275 - port->count++;
51276 + atomic_inc(&port->count);
51277 tty_port_tty_set(port, tty);
51278
51279 dlci->modem_rx = 0;
51280 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
51281 index 0391f17..31fa586 100644
51282 --- a/drivers/tty/n_tty.c
51283 +++ b/drivers/tty/n_tty.c
51284 @@ -115,7 +115,7 @@ struct n_tty_data {
51285 int minimum_to_wake;
51286
51287 /* consumer-published */
51288 - size_t read_tail;
51289 + size_t read_tail __intentional_overflow(-1);
51290 size_t line_start;
51291
51292 /* protected by output lock */
51293 @@ -2517,6 +2517,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
51294 {
51295 *ops = tty_ldisc_N_TTY;
51296 ops->owner = NULL;
51297 - ops->refcount = ops->flags = 0;
51298 + atomic_set(&ops->refcount, 0);
51299 + ops->flags = 0;
51300 }
51301 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
51302 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
51303 index 25c9bc7..24077b7 100644
51304 --- a/drivers/tty/pty.c
51305 +++ b/drivers/tty/pty.c
51306 @@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
51307 panic("Couldn't register Unix98 pts driver");
51308
51309 /* Now create the /dev/ptmx special device */
51310 + pax_open_kernel();
51311 tty_default_fops(&ptmx_fops);
51312 - ptmx_fops.open = ptmx_open;
51313 + *(void **)&ptmx_fops.open = ptmx_open;
51314 + pax_close_kernel();
51315
51316 cdev_init(&ptmx_cdev, &ptmx_fops);
51317 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
51318 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
51319 index 383c4c7..d408e21 100644
51320 --- a/drivers/tty/rocket.c
51321 +++ b/drivers/tty/rocket.c
51322 @@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
51323 tty->driver_data = info;
51324 tty_port_tty_set(port, tty);
51325
51326 - if (port->count++ == 0) {
51327 + if (atomic_inc_return(&port->count) == 1) {
51328 atomic_inc(&rp_num_ports_open);
51329
51330 #ifdef ROCKET_DEBUG_OPEN
51331 @@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
51332 #endif
51333 }
51334 #ifdef ROCKET_DEBUG_OPEN
51335 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
51336 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
51337 #endif
51338
51339 /*
51340 @@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
51341 spin_unlock_irqrestore(&info->port.lock, flags);
51342 return;
51343 }
51344 - if (info->port.count)
51345 + if (atomic_read(&info->port.count))
51346 atomic_dec(&rp_num_ports_open);
51347 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
51348 spin_unlock_irqrestore(&info->port.lock, flags);
51349 diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
51350 index 1274499..f541382 100644
51351 --- a/drivers/tty/serial/ioc4_serial.c
51352 +++ b/drivers/tty/serial/ioc4_serial.c
51353 @@ -437,7 +437,7 @@ struct ioc4_soft {
51354 } is_intr_info[MAX_IOC4_INTR_ENTS];
51355
51356 /* Number of entries active in the above array */
51357 - atomic_t is_num_intrs;
51358 + atomic_unchecked_t is_num_intrs;
51359 } is_intr_type[IOC4_NUM_INTR_TYPES];
51360
51361 /* is_ir_lock must be held while
51362 @@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
51363 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
51364 || (type == IOC4_OTHER_INTR_TYPE)));
51365
51366 - i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
51367 + i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
51368 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
51369
51370 /* Save off the lower level interrupt handler */
51371 @@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
51372
51373 soft = arg;
51374 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
51375 - num_intrs = (int)atomic_read(
51376 + num_intrs = (int)atomic_read_unchecked(
51377 &soft->is_intr_type[intr_type].is_num_intrs);
51378
51379 this_mir = this_ir = pending_intrs(soft, intr_type);
51380 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
51381 index a260cde..6b2b5ce 100644
51382 --- a/drivers/tty/serial/kgdboc.c
51383 +++ b/drivers/tty/serial/kgdboc.c
51384 @@ -24,8 +24,9 @@
51385 #define MAX_CONFIG_LEN 40
51386
51387 static struct kgdb_io kgdboc_io_ops;
51388 +static struct kgdb_io kgdboc_io_ops_console;
51389
51390 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
51391 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
51392 static int configured = -1;
51393
51394 static char config[MAX_CONFIG_LEN];
51395 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
51396 kgdboc_unregister_kbd();
51397 if (configured == 1)
51398 kgdb_unregister_io_module(&kgdboc_io_ops);
51399 + else if (configured == 2)
51400 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
51401 }
51402
51403 static int configure_kgdboc(void)
51404 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
51405 int err;
51406 char *cptr = config;
51407 struct console *cons;
51408 + int is_console = 0;
51409
51410 err = kgdboc_option_setup(config);
51411 if (err || !strlen(config) || isspace(config[0]))
51412 goto noconfig;
51413
51414 err = -ENODEV;
51415 - kgdboc_io_ops.is_console = 0;
51416 kgdb_tty_driver = NULL;
51417
51418 kgdboc_use_kms = 0;
51419 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
51420 int idx;
51421 if (cons->device && cons->device(cons, &idx) == p &&
51422 idx == tty_line) {
51423 - kgdboc_io_ops.is_console = 1;
51424 + is_console = 1;
51425 break;
51426 }
51427 cons = cons->next;
51428 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
51429 kgdb_tty_line = tty_line;
51430
51431 do_register:
51432 - err = kgdb_register_io_module(&kgdboc_io_ops);
51433 + if (is_console) {
51434 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
51435 + configured = 2;
51436 + } else {
51437 + err = kgdb_register_io_module(&kgdboc_io_ops);
51438 + configured = 1;
51439 + }
51440 if (err)
51441 goto noconfig;
51442
51443 @@ -205,8 +214,6 @@ do_register:
51444 if (err)
51445 goto nmi_con_failed;
51446
51447 - configured = 1;
51448 -
51449 return 0;
51450
51451 nmi_con_failed:
51452 @@ -223,7 +230,7 @@ noconfig:
51453 static int __init init_kgdboc(void)
51454 {
51455 /* Already configured? */
51456 - if (configured == 1)
51457 + if (configured >= 1)
51458 return 0;
51459
51460 return configure_kgdboc();
51461 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
51462 if (config[len - 1] == '\n')
51463 config[len - 1] = '\0';
51464
51465 - if (configured == 1)
51466 + if (configured >= 1)
51467 cleanup_kgdboc();
51468
51469 /* Go and configure with the new params. */
51470 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
51471 .post_exception = kgdboc_post_exp_handler,
51472 };
51473
51474 +static struct kgdb_io kgdboc_io_ops_console = {
51475 + .name = "kgdboc",
51476 + .read_char = kgdboc_get_char,
51477 + .write_char = kgdboc_put_char,
51478 + .pre_exception = kgdboc_pre_exp_handler,
51479 + .post_exception = kgdboc_post_exp_handler,
51480 + .is_console = 1
51481 +};
51482 +
51483 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
51484 /* This is only available if kgdboc is a built in for early debugging */
51485 static int __init kgdboc_early_init(char *opt)
51486 diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
51487 index 7307dc4..ce4fe90 100644
51488 --- a/drivers/tty/serial/msm_serial.c
51489 +++ b/drivers/tty/serial/msm_serial.c
51490 @@ -1026,7 +1026,7 @@ static struct uart_driver msm_uart_driver = {
51491 .cons = MSM_CONSOLE,
51492 };
51493
51494 -static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
51495 +static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
51496
51497 static const struct of_device_id msm_uartdm_table[] = {
51498 { .compatible = "qcom,msm-uartdm-v1.1", .data = (void *)UARTDM_1P1 },
51499 @@ -1045,7 +1045,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
51500 int irq;
51501
51502 if (pdev->id == -1)
51503 - pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
51504 + pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
51505
51506 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
51507 return -ENXIO;
51508 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
51509 index 1f5505e..a1a767d 100644
51510 --- a/drivers/tty/serial/samsung.c
51511 +++ b/drivers/tty/serial/samsung.c
51512 @@ -463,11 +463,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
51513 }
51514 }
51515
51516 +static int s3c64xx_serial_startup(struct uart_port *port);
51517 static int s3c24xx_serial_startup(struct uart_port *port)
51518 {
51519 struct s3c24xx_uart_port *ourport = to_ourport(port);
51520 int ret;
51521
51522 + /* Startup sequence is different for s3c64xx and higher SoC's */
51523 + if (s3c24xx_serial_has_interrupt_mask(port))
51524 + return s3c64xx_serial_startup(port);
51525 +
51526 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
51527 port->mapbase, port->membase);
51528
51529 @@ -1141,10 +1146,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
51530 /* setup info for port */
51531 port->dev = &platdev->dev;
51532
51533 - /* Startup sequence is different for s3c64xx and higher SoC's */
51534 - if (s3c24xx_serial_has_interrupt_mask(port))
51535 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
51536 -
51537 port->uartclk = 1;
51538
51539 if (cfg->uart_flags & UPF_CONS_FLOW) {
51540 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
51541 index b68550d..a62d7f8 100644
51542 --- a/drivers/tty/serial/serial_core.c
51543 +++ b/drivers/tty/serial/serial_core.c
51544 @@ -1329,7 +1329,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
51545
51546 pr_debug("uart_close(%d) called\n", uport ? uport->line : -1);
51547
51548 - if (!port->count || tty_port_close_start(port, tty, filp) == 0)
51549 + if (!atomic_read(&port->count) || tty_port_close_start(port, tty, filp) == 0)
51550 return;
51551
51552 /*
51553 @@ -1456,7 +1456,7 @@ static void uart_hangup(struct tty_struct *tty)
51554 uart_flush_buffer(tty);
51555 uart_shutdown(tty, state);
51556 spin_lock_irqsave(&port->lock, flags);
51557 - port->count = 0;
51558 + atomic_set(&port->count, 0);
51559 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
51560 spin_unlock_irqrestore(&port->lock, flags);
51561 tty_port_tty_set(port, NULL);
51562 @@ -1554,7 +1554,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51563 goto end;
51564 }
51565
51566 - port->count++;
51567 + atomic_inc(&port->count);
51568 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
51569 retval = -ENXIO;
51570 goto err_dec_count;
51571 @@ -1594,7 +1594,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51572 end:
51573 return retval;
51574 err_dec_count:
51575 - port->count--;
51576 + atomic_inc(&port->count);
51577 mutex_unlock(&port->mutex);
51578 goto end;
51579 }
51580 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
51581 index d48e040..0f52764 100644
51582 --- a/drivers/tty/synclink.c
51583 +++ b/drivers/tty/synclink.c
51584 @@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51585
51586 if (debug_level >= DEBUG_LEVEL_INFO)
51587 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
51588 - __FILE__,__LINE__, info->device_name, info->port.count);
51589 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51590
51591 if (tty_port_close_start(&info->port, tty, filp) == 0)
51592 goto cleanup;
51593 @@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51594 cleanup:
51595 if (debug_level >= DEBUG_LEVEL_INFO)
51596 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
51597 - tty->driver->name, info->port.count);
51598 + tty->driver->name, atomic_read(&info->port.count));
51599
51600 } /* end of mgsl_close() */
51601
51602 @@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
51603
51604 mgsl_flush_buffer(tty);
51605 shutdown(info);
51606 -
51607 - info->port.count = 0;
51608 +
51609 + atomic_set(&info->port.count, 0);
51610 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51611 info->port.tty = NULL;
51612
51613 @@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51614
51615 if (debug_level >= DEBUG_LEVEL_INFO)
51616 printk("%s(%d):block_til_ready before block on %s count=%d\n",
51617 - __FILE__,__LINE__, tty->driver->name, port->count );
51618 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51619
51620 spin_lock_irqsave(&info->irq_spinlock, flags);
51621 if (!tty_hung_up_p(filp)) {
51622 extra_count = true;
51623 - port->count--;
51624 + atomic_dec(&port->count);
51625 }
51626 spin_unlock_irqrestore(&info->irq_spinlock, flags);
51627 port->blocked_open++;
51628 @@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51629
51630 if (debug_level >= DEBUG_LEVEL_INFO)
51631 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
51632 - __FILE__,__LINE__, tty->driver->name, port->count );
51633 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51634
51635 tty_unlock(tty);
51636 schedule();
51637 @@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51638
51639 /* FIXME: Racy on hangup during close wait */
51640 if (extra_count)
51641 - port->count++;
51642 + atomic_inc(&port->count);
51643 port->blocked_open--;
51644
51645 if (debug_level >= DEBUG_LEVEL_INFO)
51646 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
51647 - __FILE__,__LINE__, tty->driver->name, port->count );
51648 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51649
51650 if (!retval)
51651 port->flags |= ASYNC_NORMAL_ACTIVE;
51652 @@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51653
51654 if (debug_level >= DEBUG_LEVEL_INFO)
51655 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
51656 - __FILE__,__LINE__,tty->driver->name, info->port.count);
51657 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51658
51659 /* If port is closing, signal caller to try again */
51660 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51661 @@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51662 spin_unlock_irqrestore(&info->netlock, flags);
51663 goto cleanup;
51664 }
51665 - info->port.count++;
51666 + atomic_inc(&info->port.count);
51667 spin_unlock_irqrestore(&info->netlock, flags);
51668
51669 - if (info->port.count == 1) {
51670 + if (atomic_read(&info->port.count) == 1) {
51671 /* 1st open on this device, init hardware */
51672 retval = startup(info);
51673 if (retval < 0)
51674 @@ -3446,8 +3446,8 @@ cleanup:
51675 if (retval) {
51676 if (tty->count == 1)
51677 info->port.tty = NULL; /* tty layer will release tty struct */
51678 - if(info->port.count)
51679 - info->port.count--;
51680 + if (atomic_read(&info->port.count))
51681 + atomic_dec(&info->port.count);
51682 }
51683
51684 return retval;
51685 @@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51686 unsigned short new_crctype;
51687
51688 /* return error if TTY interface open */
51689 - if (info->port.count)
51690 + if (atomic_read(&info->port.count))
51691 return -EBUSY;
51692
51693 switch (encoding)
51694 @@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
51695
51696 /* arbitrate between network and tty opens */
51697 spin_lock_irqsave(&info->netlock, flags);
51698 - if (info->port.count != 0 || info->netcount != 0) {
51699 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51700 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51701 spin_unlock_irqrestore(&info->netlock, flags);
51702 return -EBUSY;
51703 @@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51704 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51705
51706 /* return error if TTY interface open */
51707 - if (info->port.count)
51708 + if (atomic_read(&info->port.count))
51709 return -EBUSY;
51710
51711 if (cmd != SIOCWANDEV)
51712 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
51713 index c359a91..959fc26 100644
51714 --- a/drivers/tty/synclink_gt.c
51715 +++ b/drivers/tty/synclink_gt.c
51716 @@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51717 tty->driver_data = info;
51718 info->port.tty = tty;
51719
51720 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
51721 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
51722
51723 /* If port is closing, signal caller to try again */
51724 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51725 @@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51726 mutex_unlock(&info->port.mutex);
51727 goto cleanup;
51728 }
51729 - info->port.count++;
51730 + atomic_inc(&info->port.count);
51731 spin_unlock_irqrestore(&info->netlock, flags);
51732
51733 - if (info->port.count == 1) {
51734 + if (atomic_read(&info->port.count) == 1) {
51735 /* 1st open on this device, init hardware */
51736 retval = startup(info);
51737 if (retval < 0) {
51738 @@ -715,8 +715,8 @@ cleanup:
51739 if (retval) {
51740 if (tty->count == 1)
51741 info->port.tty = NULL; /* tty layer will release tty struct */
51742 - if(info->port.count)
51743 - info->port.count--;
51744 + if(atomic_read(&info->port.count))
51745 + atomic_dec(&info->port.count);
51746 }
51747
51748 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
51749 @@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51750
51751 if (sanity_check(info, tty->name, "close"))
51752 return;
51753 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
51754 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
51755
51756 if (tty_port_close_start(&info->port, tty, filp) == 0)
51757 goto cleanup;
51758 @@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51759 tty_port_close_end(&info->port, tty);
51760 info->port.tty = NULL;
51761 cleanup:
51762 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
51763 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
51764 }
51765
51766 static void hangup(struct tty_struct *tty)
51767 @@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
51768 shutdown(info);
51769
51770 spin_lock_irqsave(&info->port.lock, flags);
51771 - info->port.count = 0;
51772 + atomic_set(&info->port.count, 0);
51773 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51774 info->port.tty = NULL;
51775 spin_unlock_irqrestore(&info->port.lock, flags);
51776 @@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51777 unsigned short new_crctype;
51778
51779 /* return error if TTY interface open */
51780 - if (info->port.count)
51781 + if (atomic_read(&info->port.count))
51782 return -EBUSY;
51783
51784 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
51785 @@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
51786
51787 /* arbitrate between network and tty opens */
51788 spin_lock_irqsave(&info->netlock, flags);
51789 - if (info->port.count != 0 || info->netcount != 0) {
51790 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51791 DBGINFO(("%s hdlc_open busy\n", dev->name));
51792 spin_unlock_irqrestore(&info->netlock, flags);
51793 return -EBUSY;
51794 @@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51795 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
51796
51797 /* return error if TTY interface open */
51798 - if (info->port.count)
51799 + if (atomic_read(&info->port.count))
51800 return -EBUSY;
51801
51802 if (cmd != SIOCWANDEV)
51803 @@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
51804 if (port == NULL)
51805 continue;
51806 spin_lock(&port->lock);
51807 - if ((port->port.count || port->netcount) &&
51808 + if ((atomic_read(&port->port.count) || port->netcount) &&
51809 port->pending_bh && !port->bh_running &&
51810 !port->bh_requested) {
51811 DBGISR(("%s bh queued\n", port->device_name));
51812 @@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51813 spin_lock_irqsave(&info->lock, flags);
51814 if (!tty_hung_up_p(filp)) {
51815 extra_count = true;
51816 - port->count--;
51817 + atomic_dec(&port->count);
51818 }
51819 spin_unlock_irqrestore(&info->lock, flags);
51820 port->blocked_open++;
51821 @@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51822 remove_wait_queue(&port->open_wait, &wait);
51823
51824 if (extra_count)
51825 - port->count++;
51826 + atomic_inc(&port->count);
51827 port->blocked_open--;
51828
51829 if (!retval)
51830 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
51831 index 53ba853..3c30f6d 100644
51832 --- a/drivers/tty/synclinkmp.c
51833 +++ b/drivers/tty/synclinkmp.c
51834 @@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51835
51836 if (debug_level >= DEBUG_LEVEL_INFO)
51837 printk("%s(%d):%s open(), old ref count = %d\n",
51838 - __FILE__,__LINE__,tty->driver->name, info->port.count);
51839 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51840
51841 /* If port is closing, signal caller to try again */
51842 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51843 @@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51844 spin_unlock_irqrestore(&info->netlock, flags);
51845 goto cleanup;
51846 }
51847 - info->port.count++;
51848 + atomic_inc(&info->port.count);
51849 spin_unlock_irqrestore(&info->netlock, flags);
51850
51851 - if (info->port.count == 1) {
51852 + if (atomic_read(&info->port.count) == 1) {
51853 /* 1st open on this device, init hardware */
51854 retval = startup(info);
51855 if (retval < 0)
51856 @@ -796,8 +796,8 @@ cleanup:
51857 if (retval) {
51858 if (tty->count == 1)
51859 info->port.tty = NULL; /* tty layer will release tty struct */
51860 - if(info->port.count)
51861 - info->port.count--;
51862 + if(atomic_read(&info->port.count))
51863 + atomic_dec(&info->port.count);
51864 }
51865
51866 return retval;
51867 @@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51868
51869 if (debug_level >= DEBUG_LEVEL_INFO)
51870 printk("%s(%d):%s close() entry, count=%d\n",
51871 - __FILE__,__LINE__, info->device_name, info->port.count);
51872 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51873
51874 if (tty_port_close_start(&info->port, tty, filp) == 0)
51875 goto cleanup;
51876 @@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51877 cleanup:
51878 if (debug_level >= DEBUG_LEVEL_INFO)
51879 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
51880 - tty->driver->name, info->port.count);
51881 + tty->driver->name, atomic_read(&info->port.count));
51882 }
51883
51884 /* Called by tty_hangup() when a hangup is signaled.
51885 @@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
51886 shutdown(info);
51887
51888 spin_lock_irqsave(&info->port.lock, flags);
51889 - info->port.count = 0;
51890 + atomic_set(&info->port.count, 0);
51891 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51892 info->port.tty = NULL;
51893 spin_unlock_irqrestore(&info->port.lock, flags);
51894 @@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51895 unsigned short new_crctype;
51896
51897 /* return error if TTY interface open */
51898 - if (info->port.count)
51899 + if (atomic_read(&info->port.count))
51900 return -EBUSY;
51901
51902 switch (encoding)
51903 @@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
51904
51905 /* arbitrate between network and tty opens */
51906 spin_lock_irqsave(&info->netlock, flags);
51907 - if (info->port.count != 0 || info->netcount != 0) {
51908 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51909 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51910 spin_unlock_irqrestore(&info->netlock, flags);
51911 return -EBUSY;
51912 @@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51913 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51914
51915 /* return error if TTY interface open */
51916 - if (info->port.count)
51917 + if (atomic_read(&info->port.count))
51918 return -EBUSY;
51919
51920 if (cmd != SIOCWANDEV)
51921 @@ -2621,7 +2621,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
51922 * do not request bottom half processing if the
51923 * device is not open in a normal mode.
51924 */
51925 - if ( port && (port->port.count || port->netcount) &&
51926 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
51927 port->pending_bh && !port->bh_running &&
51928 !port->bh_requested ) {
51929 if ( debug_level >= DEBUG_LEVEL_ISR )
51930 @@ -3319,12 +3319,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51931
51932 if (debug_level >= DEBUG_LEVEL_INFO)
51933 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
51934 - __FILE__,__LINE__, tty->driver->name, port->count );
51935 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51936
51937 spin_lock_irqsave(&info->lock, flags);
51938 if (!tty_hung_up_p(filp)) {
51939 extra_count = true;
51940 - port->count--;
51941 + atomic_dec(&port->count);
51942 }
51943 spin_unlock_irqrestore(&info->lock, flags);
51944 port->blocked_open++;
51945 @@ -3353,7 +3353,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51946
51947 if (debug_level >= DEBUG_LEVEL_INFO)
51948 printk("%s(%d):%s block_til_ready() count=%d\n",
51949 - __FILE__,__LINE__, tty->driver->name, port->count );
51950 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51951
51952 tty_unlock(tty);
51953 schedule();
51954 @@ -3364,12 +3364,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51955 remove_wait_queue(&port->open_wait, &wait);
51956
51957 if (extra_count)
51958 - port->count++;
51959 + atomic_inc(&port->count);
51960 port->blocked_open--;
51961
51962 if (debug_level >= DEBUG_LEVEL_INFO)
51963 printk("%s(%d):%s block_til_ready() after, count=%d\n",
51964 - __FILE__,__LINE__, tty->driver->name, port->count );
51965 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51966
51967 if (!retval)
51968 port->flags |= ASYNC_NORMAL_ACTIVE;
51969 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
51970 index ce396ec..04a37be 100644
51971 --- a/drivers/tty/sysrq.c
51972 +++ b/drivers/tty/sysrq.c
51973 @@ -1075,7 +1075,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
51974 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
51975 size_t count, loff_t *ppos)
51976 {
51977 - if (count) {
51978 + if (count && capable(CAP_SYS_ADMIN)) {
51979 char c;
51980
51981 if (get_user(c, buf))
51982 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
51983 index 3411071..86f2cf2 100644
51984 --- a/drivers/tty/tty_io.c
51985 +++ b/drivers/tty/tty_io.c
51986 @@ -3475,7 +3475,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
51987
51988 void tty_default_fops(struct file_operations *fops)
51989 {
51990 - *fops = tty_fops;
51991 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
51992 }
51993
51994 /*
51995 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
51996 index 2d822aa..a566234 100644
51997 --- a/drivers/tty/tty_ldisc.c
51998 +++ b/drivers/tty/tty_ldisc.c
51999 @@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
52000 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
52001 tty_ldiscs[disc] = new_ldisc;
52002 new_ldisc->num = disc;
52003 - new_ldisc->refcount = 0;
52004 + atomic_set(&new_ldisc->refcount, 0);
52005 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
52006
52007 return ret;
52008 @@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
52009 return -EINVAL;
52010
52011 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
52012 - if (tty_ldiscs[disc]->refcount)
52013 + if (atomic_read(&tty_ldiscs[disc]->refcount))
52014 ret = -EBUSY;
52015 else
52016 tty_ldiscs[disc] = NULL;
52017 @@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
52018 if (ldops) {
52019 ret = ERR_PTR(-EAGAIN);
52020 if (try_module_get(ldops->owner)) {
52021 - ldops->refcount++;
52022 + atomic_inc(&ldops->refcount);
52023 ret = ldops;
52024 }
52025 }
52026 @@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
52027 unsigned long flags;
52028
52029 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
52030 - ldops->refcount--;
52031 + atomic_dec(&ldops->refcount);
52032 module_put(ldops->owner);
52033 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
52034 }
52035 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
52036 index 3f746c8..2f2fcaa 100644
52037 --- a/drivers/tty/tty_port.c
52038 +++ b/drivers/tty/tty_port.c
52039 @@ -235,7 +235,7 @@ void tty_port_hangup(struct tty_port *port)
52040 unsigned long flags;
52041
52042 spin_lock_irqsave(&port->lock, flags);
52043 - port->count = 0;
52044 + atomic_set(&port->count, 0);
52045 port->flags &= ~ASYNC_NORMAL_ACTIVE;
52046 tty = port->tty;
52047 if (tty)
52048 @@ -393,7 +393,7 @@ int tty_port_block_til_ready(struct tty_port *port,
52049 /* The port lock protects the port counts */
52050 spin_lock_irqsave(&port->lock, flags);
52051 if (!tty_hung_up_p(filp))
52052 - port->count--;
52053 + atomic_dec(&port->count);
52054 port->blocked_open++;
52055 spin_unlock_irqrestore(&port->lock, flags);
52056
52057 @@ -435,7 +435,7 @@ int tty_port_block_til_ready(struct tty_port *port,
52058 we must not mess that up further */
52059 spin_lock_irqsave(&port->lock, flags);
52060 if (!tty_hung_up_p(filp))
52061 - port->count++;
52062 + atomic_inc(&port->count);
52063 port->blocked_open--;
52064 if (retval == 0)
52065 port->flags |= ASYNC_NORMAL_ACTIVE;
52066 @@ -469,19 +469,19 @@ int tty_port_close_start(struct tty_port *port,
52067 return 0;
52068 }
52069
52070 - if (tty->count == 1 && port->count != 1) {
52071 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
52072 printk(KERN_WARNING
52073 "tty_port_close_start: tty->count = 1 port count = %d.\n",
52074 - port->count);
52075 - port->count = 1;
52076 + atomic_read(&port->count));
52077 + atomic_set(&port->count, 1);
52078 }
52079 - if (--port->count < 0) {
52080 + if (atomic_dec_return(&port->count) < 0) {
52081 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
52082 - port->count);
52083 - port->count = 0;
52084 + atomic_read(&port->count));
52085 + atomic_set(&port->count, 0);
52086 }
52087
52088 - if (port->count) {
52089 + if (atomic_read(&port->count)) {
52090 spin_unlock_irqrestore(&port->lock, flags);
52091 return 0;
52092 }
52093 @@ -563,7 +563,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
52094 {
52095 spin_lock_irq(&port->lock);
52096 if (!tty_hung_up_p(filp))
52097 - ++port->count;
52098 + atomic_inc(&port->count);
52099 spin_unlock_irq(&port->lock);
52100 tty_port_tty_set(port, tty);
52101
52102 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
52103 index d0e3a44..5f8b754 100644
52104 --- a/drivers/tty/vt/keyboard.c
52105 +++ b/drivers/tty/vt/keyboard.c
52106 @@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
52107 kbd->kbdmode == VC_OFF) &&
52108 value != KVAL(K_SAK))
52109 return; /* SAK is allowed even in raw mode */
52110 +
52111 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
52112 + {
52113 + void *func = fn_handler[value];
52114 + if (func == fn_show_state || func == fn_show_ptregs ||
52115 + func == fn_show_mem)
52116 + return;
52117 + }
52118 +#endif
52119 +
52120 fn_handler[value](vc);
52121 }
52122
52123 @@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
52124 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
52125 return -EFAULT;
52126
52127 - if (!capable(CAP_SYS_TTY_CONFIG))
52128 - perm = 0;
52129 -
52130 switch (cmd) {
52131 case KDGKBENT:
52132 /* Ensure another thread doesn't free it under us */
52133 @@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
52134 spin_unlock_irqrestore(&kbd_event_lock, flags);
52135 return put_user(val, &user_kbe->kb_value);
52136 case KDSKBENT:
52137 + if (!capable(CAP_SYS_TTY_CONFIG))
52138 + perm = 0;
52139 +
52140 if (!perm)
52141 return -EPERM;
52142 if (!i && v == K_NOSUCHMAP) {
52143 @@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
52144 int i, j, k;
52145 int ret;
52146
52147 - if (!capable(CAP_SYS_TTY_CONFIG))
52148 - perm = 0;
52149 -
52150 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
52151 if (!kbs) {
52152 ret = -ENOMEM;
52153 @@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
52154 kfree(kbs);
52155 return ((p && *p) ? -EOVERFLOW : 0);
52156 case KDSKBSENT:
52157 + if (!capable(CAP_SYS_TTY_CONFIG))
52158 + perm = 0;
52159 +
52160 if (!perm) {
52161 ret = -EPERM;
52162 goto reterr;
52163 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
52164 index a673e5b..36e5d32 100644
52165 --- a/drivers/uio/uio.c
52166 +++ b/drivers/uio/uio.c
52167 @@ -25,6 +25,7 @@
52168 #include <linux/kobject.h>
52169 #include <linux/cdev.h>
52170 #include <linux/uio_driver.h>
52171 +#include <asm/local.h>
52172
52173 #define UIO_MAX_DEVICES (1U << MINORBITS)
52174
52175 @@ -32,7 +33,7 @@ struct uio_device {
52176 struct module *owner;
52177 struct device *dev;
52178 int minor;
52179 - atomic_t event;
52180 + atomic_unchecked_t event;
52181 struct fasync_struct *async_queue;
52182 wait_queue_head_t wait;
52183 struct uio_info *info;
52184 @@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
52185 struct device_attribute *attr, char *buf)
52186 {
52187 struct uio_device *idev = dev_get_drvdata(dev);
52188 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
52189 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
52190 }
52191 static DEVICE_ATTR_RO(event);
52192
52193 @@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
52194 {
52195 struct uio_device *idev = info->uio_dev;
52196
52197 - atomic_inc(&idev->event);
52198 + atomic_inc_unchecked(&idev->event);
52199 wake_up_interruptible(&idev->wait);
52200 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
52201 }
52202 @@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
52203 }
52204
52205 listener->dev = idev;
52206 - listener->event_count = atomic_read(&idev->event);
52207 + listener->event_count = atomic_read_unchecked(&idev->event);
52208 filep->private_data = listener;
52209
52210 if (idev->info->open) {
52211 @@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
52212 return -EIO;
52213
52214 poll_wait(filep, &idev->wait, wait);
52215 - if (listener->event_count != atomic_read(&idev->event))
52216 + if (listener->event_count != atomic_read_unchecked(&idev->event))
52217 return POLLIN | POLLRDNORM;
52218 return 0;
52219 }
52220 @@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
52221 do {
52222 set_current_state(TASK_INTERRUPTIBLE);
52223
52224 - event_count = atomic_read(&idev->event);
52225 + event_count = atomic_read_unchecked(&idev->event);
52226 if (event_count != listener->event_count) {
52227 if (copy_to_user(buf, &event_count, count))
52228 retval = -EFAULT;
52229 @@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
52230 static int uio_find_mem_index(struct vm_area_struct *vma)
52231 {
52232 struct uio_device *idev = vma->vm_private_data;
52233 + unsigned long size;
52234
52235 if (vma->vm_pgoff < MAX_UIO_MAPS) {
52236 - if (idev->info->mem[vma->vm_pgoff].size == 0)
52237 + size = idev->info->mem[vma->vm_pgoff].size;
52238 + if (size == 0)
52239 + return -1;
52240 + if (vma->vm_end - vma->vm_start > size)
52241 return -1;
52242 return (int)vma->vm_pgoff;
52243 }
52244 @@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
52245 idev->owner = owner;
52246 idev->info = info;
52247 init_waitqueue_head(&idev->wait);
52248 - atomic_set(&idev->event, 0);
52249 + atomic_set_unchecked(&idev->event, 0);
52250
52251 ret = uio_get_minor(idev);
52252 if (ret)
52253 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
52254 index 813d4d3..a71934f 100644
52255 --- a/drivers/usb/atm/cxacru.c
52256 +++ b/drivers/usb/atm/cxacru.c
52257 @@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
52258 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
52259 if (ret < 2)
52260 return -EINVAL;
52261 - if (index < 0 || index > 0x7f)
52262 + if (index > 0x7f)
52263 return -EINVAL;
52264 pos += tmp;
52265
52266 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
52267 index dada014..1d0d517 100644
52268 --- a/drivers/usb/atm/usbatm.c
52269 +++ b/drivers/usb/atm/usbatm.c
52270 @@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52271 if (printk_ratelimit())
52272 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
52273 __func__, vpi, vci);
52274 - atomic_inc(&vcc->stats->rx_err);
52275 + atomic_inc_unchecked(&vcc->stats->rx_err);
52276 return;
52277 }
52278
52279 @@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52280 if (length > ATM_MAX_AAL5_PDU) {
52281 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
52282 __func__, length, vcc);
52283 - atomic_inc(&vcc->stats->rx_err);
52284 + atomic_inc_unchecked(&vcc->stats->rx_err);
52285 goto out;
52286 }
52287
52288 @@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52289 if (sarb->len < pdu_length) {
52290 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
52291 __func__, pdu_length, sarb->len, vcc);
52292 - atomic_inc(&vcc->stats->rx_err);
52293 + atomic_inc_unchecked(&vcc->stats->rx_err);
52294 goto out;
52295 }
52296
52297 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
52298 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
52299 __func__, vcc);
52300 - atomic_inc(&vcc->stats->rx_err);
52301 + atomic_inc_unchecked(&vcc->stats->rx_err);
52302 goto out;
52303 }
52304
52305 @@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52306 if (printk_ratelimit())
52307 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
52308 __func__, length);
52309 - atomic_inc(&vcc->stats->rx_drop);
52310 + atomic_inc_unchecked(&vcc->stats->rx_drop);
52311 goto out;
52312 }
52313
52314 @@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52315
52316 vcc->push(vcc, skb);
52317
52318 - atomic_inc(&vcc->stats->rx);
52319 + atomic_inc_unchecked(&vcc->stats->rx);
52320 out:
52321 skb_trim(sarb, 0);
52322 }
52323 @@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
52324 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
52325
52326 usbatm_pop(vcc, skb);
52327 - atomic_inc(&vcc->stats->tx);
52328 + atomic_inc_unchecked(&vcc->stats->tx);
52329
52330 skb = skb_dequeue(&instance->sndqueue);
52331 }
52332 @@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
52333 if (!left--)
52334 return sprintf(page,
52335 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
52336 - atomic_read(&atm_dev->stats.aal5.tx),
52337 - atomic_read(&atm_dev->stats.aal5.tx_err),
52338 - atomic_read(&atm_dev->stats.aal5.rx),
52339 - atomic_read(&atm_dev->stats.aal5.rx_err),
52340 - atomic_read(&atm_dev->stats.aal5.rx_drop));
52341 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
52342 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
52343 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
52344 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
52345 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
52346
52347 if (!left--) {
52348 if (instance->disconnected)
52349 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
52350 index 2a3bbdf..91d72cf 100644
52351 --- a/drivers/usb/core/devices.c
52352 +++ b/drivers/usb/core/devices.c
52353 @@ -126,7 +126,7 @@ static const char format_endpt[] =
52354 * time it gets called.
52355 */
52356 static struct device_connect_event {
52357 - atomic_t count;
52358 + atomic_unchecked_t count;
52359 wait_queue_head_t wait;
52360 } device_event = {
52361 .count = ATOMIC_INIT(1),
52362 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
52363
52364 void usbfs_conn_disc_event(void)
52365 {
52366 - atomic_add(2, &device_event.count);
52367 + atomic_add_unchecked(2, &device_event.count);
52368 wake_up(&device_event.wait);
52369 }
52370
52371 @@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
52372
52373 poll_wait(file, &device_event.wait, wait);
52374
52375 - event_count = atomic_read(&device_event.count);
52376 + event_count = atomic_read_unchecked(&device_event.count);
52377 if (file->f_version != event_count) {
52378 file->f_version = event_count;
52379 return POLLIN | POLLRDNORM;
52380 diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
52381 index 257876e..4304364 100644
52382 --- a/drivers/usb/core/devio.c
52383 +++ b/drivers/usb/core/devio.c
52384 @@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
52385 struct usb_dev_state *ps = file->private_data;
52386 struct usb_device *dev = ps->dev;
52387 ssize_t ret = 0;
52388 - unsigned len;
52389 + size_t len;
52390 loff_t pos;
52391 int i;
52392
52393 @@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
52394 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
52395 struct usb_config_descriptor *config =
52396 (struct usb_config_descriptor *)dev->rawdescriptors[i];
52397 - unsigned int length = le16_to_cpu(config->wTotalLength);
52398 + size_t length = le16_to_cpu(config->wTotalLength);
52399
52400 if (*ppos < pos + length) {
52401
52402 /* The descriptor may claim to be longer than it
52403 * really is. Here is the actual allocated length. */
52404 - unsigned alloclen =
52405 + size_t alloclen =
52406 le16_to_cpu(dev->config[i].desc.wTotalLength);
52407
52408 - len = length - (*ppos - pos);
52409 + len = length + pos - *ppos;
52410 if (len > nbytes)
52411 len = nbytes;
52412
52413 /* Simply don't write (skip over) unallocated parts */
52414 if (alloclen > (*ppos - pos)) {
52415 - alloclen -= (*ppos - pos);
52416 + alloclen = alloclen + pos - *ppos;
52417 if (copy_to_user(buf,
52418 dev->rawdescriptors[i] + (*ppos - pos),
52419 min(len, alloclen))) {
52420 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
52421 index 9c4e292..b89877f 100644
52422 --- a/drivers/usb/core/hcd.c
52423 +++ b/drivers/usb/core/hcd.c
52424 @@ -1550,7 +1550,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
52425 */
52426 usb_get_urb(urb);
52427 atomic_inc(&urb->use_count);
52428 - atomic_inc(&urb->dev->urbnum);
52429 + atomic_inc_unchecked(&urb->dev->urbnum);
52430 usbmon_urb_submit(&hcd->self, urb);
52431
52432 /* NOTE requirements on root-hub callers (usbfs and the hub
52433 @@ -1577,7 +1577,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
52434 urb->hcpriv = NULL;
52435 INIT_LIST_HEAD(&urb->urb_list);
52436 atomic_dec(&urb->use_count);
52437 - atomic_dec(&urb->dev->urbnum);
52438 + atomic_dec_unchecked(&urb->dev->urbnum);
52439 if (atomic_read(&urb->reject))
52440 wake_up(&usb_kill_urb_queue);
52441 usb_put_urb(urb);
52442 diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
52443 index 00c4b96..b4498c8 100644
52444 --- a/drivers/usb/core/hub.c
52445 +++ b/drivers/usb/core/hub.c
52446 @@ -27,6 +27,7 @@
52447 #include <linux/freezer.h>
52448 #include <linux/random.h>
52449 #include <linux/pm_qos.h>
52450 +#include <linux/grsecurity.h>
52451
52452 #include <asm/uaccess.h>
52453 #include <asm/byteorder.h>
52454 @@ -4531,6 +4532,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
52455 goto done;
52456 return;
52457 }
52458 +
52459 + if (gr_handle_new_usb())
52460 + goto done;
52461 +
52462 if (hub_is_superspeed(hub->hdev))
52463 unit_load = 150;
52464 else
52465 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
52466 index 0c8a7fc..c45b40a 100644
52467 --- a/drivers/usb/core/message.c
52468 +++ b/drivers/usb/core/message.c
52469 @@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
52470 * Return: If successful, the number of bytes transferred. Otherwise, a negative
52471 * error number.
52472 */
52473 -int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
52474 +int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
52475 __u8 requesttype, __u16 value, __u16 index, void *data,
52476 __u16 size, int timeout)
52477 {
52478 @@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
52479 * If successful, 0. Otherwise a negative error number. The number of actual
52480 * bytes transferred will be stored in the @actual_length parameter.
52481 */
52482 -int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
52483 +int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
52484 void *data, int len, int *actual_length, int timeout)
52485 {
52486 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
52487 @@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
52488 * bytes transferred will be stored in the @actual_length parameter.
52489 *
52490 */
52491 -int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
52492 +int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
52493 void *data, int len, int *actual_length, int timeout)
52494 {
52495 struct urb *urb;
52496 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
52497 index 1236c60..d47a51c 100644
52498 --- a/drivers/usb/core/sysfs.c
52499 +++ b/drivers/usb/core/sysfs.c
52500 @@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
52501 struct usb_device *udev;
52502
52503 udev = to_usb_device(dev);
52504 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
52505 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
52506 }
52507 static DEVICE_ATTR_RO(urbnum);
52508
52509 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
52510 index 4d11449..f4ccabf 100644
52511 --- a/drivers/usb/core/usb.c
52512 +++ b/drivers/usb/core/usb.c
52513 @@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
52514 set_dev_node(&dev->dev, dev_to_node(bus->controller));
52515 dev->state = USB_STATE_ATTACHED;
52516 dev->lpm_disable_count = 1;
52517 - atomic_set(&dev->urbnum, 0);
52518 + atomic_set_unchecked(&dev->urbnum, 0);
52519
52520 INIT_LIST_HEAD(&dev->ep0.urb_list);
52521 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
52522 diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
52523 index 85f398d..d375bbe 100644
52524 --- a/drivers/usb/dwc3/gadget.c
52525 +++ b/drivers/usb/dwc3/gadget.c
52526 @@ -550,8 +550,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
52527 if (!usb_endpoint_xfer_isoc(desc))
52528 return 0;
52529
52530 - memset(&trb_link, 0, sizeof(trb_link));
52531 -
52532 /* Link TRB for ISOC. The HWO bit is never reset */
52533 trb_st_hw = &dep->trb_pool[0];
52534
52535 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
52536 index 8cfc319..4868255 100644
52537 --- a/drivers/usb/early/ehci-dbgp.c
52538 +++ b/drivers/usb/early/ehci-dbgp.c
52539 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
52540
52541 #ifdef CONFIG_KGDB
52542 static struct kgdb_io kgdbdbgp_io_ops;
52543 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
52544 +static struct kgdb_io kgdbdbgp_io_ops_console;
52545 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
52546 #else
52547 #define dbgp_kgdb_mode (0)
52548 #endif
52549 @@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
52550 .write_char = kgdbdbgp_write_char,
52551 };
52552
52553 +static struct kgdb_io kgdbdbgp_io_ops_console = {
52554 + .name = "kgdbdbgp",
52555 + .read_char = kgdbdbgp_read_char,
52556 + .write_char = kgdbdbgp_write_char,
52557 + .is_console = 1
52558 +};
52559 +
52560 static int kgdbdbgp_wait_time;
52561
52562 static int __init kgdbdbgp_parse_config(char *str)
52563 @@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
52564 ptr++;
52565 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
52566 }
52567 - kgdb_register_io_module(&kgdbdbgp_io_ops);
52568 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
52569 + if (early_dbgp_console.index != -1)
52570 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
52571 + else
52572 + kgdb_register_io_module(&kgdbdbgp_io_ops);
52573
52574 return 0;
52575 }
52576 diff --git a/drivers/usb/gadget/f_uac1.c b/drivers/usb/gadget/f_uac1.c
52577 index 2b4c82d..06a8ee6 100644
52578 --- a/drivers/usb/gadget/f_uac1.c
52579 +++ b/drivers/usb/gadget/f_uac1.c
52580 @@ -13,6 +13,7 @@
52581 #include <linux/kernel.h>
52582 #include <linux/device.h>
52583 #include <linux/atomic.h>
52584 +#include <linux/module.h>
52585
52586 #include "u_uac1.h"
52587
52588 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
52589 index ad0aca8..8ff84865 100644
52590 --- a/drivers/usb/gadget/u_serial.c
52591 +++ b/drivers/usb/gadget/u_serial.c
52592 @@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52593 spin_lock_irq(&port->port_lock);
52594
52595 /* already open? Great. */
52596 - if (port->port.count) {
52597 + if (atomic_read(&port->port.count)) {
52598 status = 0;
52599 - port->port.count++;
52600 + atomic_inc(&port->port.count);
52601
52602 /* currently opening/closing? wait ... */
52603 } else if (port->openclose) {
52604 @@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52605 tty->driver_data = port;
52606 port->port.tty = tty;
52607
52608 - port->port.count = 1;
52609 + atomic_set(&port->port.count, 1);
52610 port->openclose = false;
52611
52612 /* if connected, start the I/O stream */
52613 @@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52614
52615 spin_lock_irq(&port->port_lock);
52616
52617 - if (port->port.count != 1) {
52618 - if (port->port.count == 0)
52619 + if (atomic_read(&port->port.count) != 1) {
52620 + if (atomic_read(&port->port.count) == 0)
52621 WARN_ON(1);
52622 else
52623 - --port->port.count;
52624 + atomic_dec(&port->port.count);
52625 goto exit;
52626 }
52627
52628 @@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52629 * and sleep if necessary
52630 */
52631 port->openclose = true;
52632 - port->port.count = 0;
52633 + atomic_set(&port->port.count, 0);
52634
52635 gser = port->port_usb;
52636 if (gser && gser->disconnect)
52637 @@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
52638 int cond;
52639
52640 spin_lock_irq(&port->port_lock);
52641 - cond = (port->port.count == 0) && !port->openclose;
52642 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
52643 spin_unlock_irq(&port->port_lock);
52644 return cond;
52645 }
52646 @@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
52647 /* if it's already open, start I/O ... and notify the serial
52648 * protocol about open/close status (connect/disconnect).
52649 */
52650 - if (port->port.count) {
52651 + if (atomic_read(&port->port.count)) {
52652 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
52653 gs_start_io(port);
52654 if (gser->connect)
52655 @@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
52656
52657 port->port_usb = NULL;
52658 gser->ioport = NULL;
52659 - if (port->port.count > 0 || port->openclose) {
52660 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
52661 wake_up_interruptible(&port->drain_wait);
52662 if (port->port.tty)
52663 tty_hangup(port->port.tty);
52664 @@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
52665
52666 /* finally, free any unused/unusable I/O buffers */
52667 spin_lock_irqsave(&port->port_lock, flags);
52668 - if (port->port.count == 0 && !port->openclose)
52669 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
52670 gs_buf_free(&port->port_write_buf);
52671 gs_free_requests(gser->out, &port->read_pool, NULL);
52672 gs_free_requests(gser->out, &port->read_queue, NULL);
52673 diff --git a/drivers/usb/gadget/u_uac1.c b/drivers/usb/gadget/u_uac1.c
52674 index 7a55fea..cc0ed4f 100644
52675 --- a/drivers/usb/gadget/u_uac1.c
52676 +++ b/drivers/usb/gadget/u_uac1.c
52677 @@ -16,6 +16,7 @@
52678 #include <linux/ctype.h>
52679 #include <linux/random.h>
52680 #include <linux/syscalls.h>
52681 +#include <linux/module.h>
52682
52683 #include "u_uac1.h"
52684
52685 diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
52686 index 7ae0c4d..35521b7 100644
52687 --- a/drivers/usb/host/ehci-hub.c
52688 +++ b/drivers/usb/host/ehci-hub.c
52689 @@ -780,7 +780,7 @@ static struct urb *request_single_step_set_feature_urb(
52690 urb->transfer_flags = URB_DIR_IN;
52691 usb_get_urb(urb);
52692 atomic_inc(&urb->use_count);
52693 - atomic_inc(&urb->dev->urbnum);
52694 + atomic_inc_unchecked(&urb->dev->urbnum);
52695 urb->setup_dma = dma_map_single(
52696 hcd->self.controller,
52697 urb->setup_packet,
52698 @@ -847,7 +847,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
52699 urb->status = -EINPROGRESS;
52700 usb_get_urb(urb);
52701 atomic_inc(&urb->use_count);
52702 - atomic_inc(&urb->dev->urbnum);
52703 + atomic_inc_unchecked(&urb->dev->urbnum);
52704 retval = submit_single_step_set_feature(hcd, urb, 0);
52705 if (!retval && !wait_for_completion_timeout(&done,
52706 msecs_to_jiffies(2000))) {
52707 diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c
52708 index d0d8fad..668ef7b 100644
52709 --- a/drivers/usb/host/hwa-hc.c
52710 +++ b/drivers/usb/host/hwa-hc.c
52711 @@ -337,7 +337,10 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
52712 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
52713 struct wahc *wa = &hwahc->wa;
52714 struct device *dev = &wa->usb_iface->dev;
52715 - u8 mas_le[UWB_NUM_MAS/8];
52716 + u8 *mas_le = kmalloc(UWB_NUM_MAS/8, GFP_KERNEL);
52717 +
52718 + if (mas_le == NULL)
52719 + return -ENOMEM;
52720
52721 /* Set the stream index */
52722 result = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
52723 @@ -356,10 +359,12 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
52724 WUSB_REQ_SET_WUSB_MAS,
52725 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
52726 0, wa->usb_iface->cur_altsetting->desc.bInterfaceNumber,
52727 - mas_le, 32, USB_CTRL_SET_TIMEOUT);
52728 + mas_le, UWB_NUM_MAS/8, USB_CTRL_SET_TIMEOUT);
52729 if (result < 0)
52730 dev_err(dev, "Cannot set WUSB MAS allocation: %d\n", result);
52731 out:
52732 + kfree(mas_le);
52733 +
52734 return result;
52735 }
52736
52737 diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
52738 index ba6a5d6..f88f7f3 100644
52739 --- a/drivers/usb/misc/appledisplay.c
52740 +++ b/drivers/usb/misc/appledisplay.c
52741 @@ -83,7 +83,7 @@ struct appledisplay {
52742 spinlock_t lock;
52743 };
52744
52745 -static atomic_t count_displays = ATOMIC_INIT(0);
52746 +static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
52747 static struct workqueue_struct *wq;
52748
52749 static void appledisplay_complete(struct urb *urb)
52750 @@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
52751
52752 /* Register backlight device */
52753 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
52754 - atomic_inc_return(&count_displays) - 1);
52755 + atomic_inc_return_unchecked(&count_displays) - 1);
52756 memset(&props, 0, sizeof(struct backlight_properties));
52757 props.type = BACKLIGHT_RAW;
52758 props.max_brightness = 0xff;
52759 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
52760 index 8d7fc48..01c4986 100644
52761 --- a/drivers/usb/serial/console.c
52762 +++ b/drivers/usb/serial/console.c
52763 @@ -123,7 +123,7 @@ static int usb_console_setup(struct console *co, char *options)
52764
52765 info->port = port;
52766
52767 - ++port->port.count;
52768 + atomic_inc(&port->port.count);
52769 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
52770 if (serial->type->set_termios) {
52771 /*
52772 @@ -167,7 +167,7 @@ static int usb_console_setup(struct console *co, char *options)
52773 }
52774 /* Now that any required fake tty operations are completed restore
52775 * the tty port count */
52776 - --port->port.count;
52777 + atomic_dec(&port->port.count);
52778 /* The console is special in terms of closing the device so
52779 * indicate this port is now acting as a system console. */
52780 port->port.console = 1;
52781 @@ -180,7 +180,7 @@ static int usb_console_setup(struct console *co, char *options)
52782 free_tty:
52783 kfree(tty);
52784 reset_open_count:
52785 - port->port.count = 0;
52786 + atomic_set(&port->port.count, 0);
52787 usb_autopm_put_interface(serial->interface);
52788 error_get_interface:
52789 usb_serial_put(serial);
52790 @@ -191,7 +191,7 @@ static int usb_console_setup(struct console *co, char *options)
52791 static void usb_console_write(struct console *co,
52792 const char *buf, unsigned count)
52793 {
52794 - static struct usbcons_info *info = &usbcons_info;
52795 + struct usbcons_info *info = &usbcons_info;
52796 struct usb_serial_port *port = info->port;
52797 struct usb_serial *serial;
52798 int retval = -ENODEV;
52799 diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
52800 index 307e339..6aa97cb 100644
52801 --- a/drivers/usb/storage/usb.h
52802 +++ b/drivers/usb/storage/usb.h
52803 @@ -63,7 +63,7 @@ struct us_unusual_dev {
52804 __u8 useProtocol;
52805 __u8 useTransport;
52806 int (*initFunction)(struct us_data *);
52807 -};
52808 +} __do_const;
52809
52810
52811 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
52812 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
52813 index f2a8d29..7bc3fe7 100644
52814 --- a/drivers/usb/wusbcore/wa-hc.h
52815 +++ b/drivers/usb/wusbcore/wa-hc.h
52816 @@ -240,7 +240,7 @@ struct wahc {
52817 spinlock_t xfer_list_lock;
52818 struct work_struct xfer_enqueue_work;
52819 struct work_struct xfer_error_work;
52820 - atomic_t xfer_id_count;
52821 + atomic_unchecked_t xfer_id_count;
52822
52823 kernel_ulong_t quirks;
52824 };
52825 @@ -305,7 +305,7 @@ static inline void wa_init(struct wahc *wa)
52826 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
52827 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
52828 wa->dto_in_use = 0;
52829 - atomic_set(&wa->xfer_id_count, 1);
52830 + atomic_set_unchecked(&wa->xfer_id_count, 1);
52831 /* init the buf in URBs */
52832 for (index = 0; index < WA_MAX_BUF_IN_URBS; ++index)
52833 usb_init_urb(&(wa->buf_in_urbs[index]));
52834 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
52835 index 3e2e4ed..060c9b8 100644
52836 --- a/drivers/usb/wusbcore/wa-xfer.c
52837 +++ b/drivers/usb/wusbcore/wa-xfer.c
52838 @@ -314,7 +314,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
52839 */
52840 static void wa_xfer_id_init(struct wa_xfer *xfer)
52841 {
52842 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
52843 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
52844 }
52845
52846 /* Return the xfer's ID. */
52847 diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
52848 index 512f479..7e041d0 100644
52849 --- a/drivers/vfio/vfio.c
52850 +++ b/drivers/vfio/vfio.c
52851 @@ -487,7 +487,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
52852 return 0;
52853
52854 /* TODO Prevent device auto probing */
52855 - WARN("Device %s added to live group %d!\n", dev_name(dev),
52856 + WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
52857 iommu_group_id(group->iommu_group));
52858
52859 return 0;
52860 diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
52861 index 5174eba..451e6bc 100644
52862 --- a/drivers/vhost/vringh.c
52863 +++ b/drivers/vhost/vringh.c
52864 @@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
52865 /* Userspace access helpers: in this case, addresses are really userspace. */
52866 static inline int getu16_user(u16 *val, const u16 *p)
52867 {
52868 - return get_user(*val, (__force u16 __user *)p);
52869 + return get_user(*val, (u16 __force_user *)p);
52870 }
52871
52872 static inline int putu16_user(u16 *p, u16 val)
52873 {
52874 - return put_user(val, (__force u16 __user *)p);
52875 + return put_user(val, (u16 __force_user *)p);
52876 }
52877
52878 static inline int copydesc_user(void *dst, const void *src, size_t len)
52879 {
52880 - return copy_from_user(dst, (__force void __user *)src, len) ?
52881 + return copy_from_user(dst, (void __force_user *)src, len) ?
52882 -EFAULT : 0;
52883 }
52884
52885 @@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
52886 const struct vring_used_elem *src,
52887 unsigned int num)
52888 {
52889 - return copy_to_user((__force void __user *)dst, src,
52890 + return copy_to_user((void __force_user *)dst, src,
52891 sizeof(*dst) * num) ? -EFAULT : 0;
52892 }
52893
52894 static inline int xfer_from_user(void *src, void *dst, size_t len)
52895 {
52896 - return copy_from_user(dst, (__force void __user *)src, len) ?
52897 + return copy_from_user(dst, (void __force_user *)src, len) ?
52898 -EFAULT : 0;
52899 }
52900
52901 static inline int xfer_to_user(void *dst, void *src, size_t len)
52902 {
52903 - return copy_to_user((__force void __user *)dst, src, len) ?
52904 + return copy_to_user((void __force_user *)dst, src, len) ?
52905 -EFAULT : 0;
52906 }
52907
52908 @@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
52909 vrh->last_used_idx = 0;
52910 vrh->vring.num = num;
52911 /* vring expects kernel addresses, but only used via accessors. */
52912 - vrh->vring.desc = (__force struct vring_desc *)desc;
52913 - vrh->vring.avail = (__force struct vring_avail *)avail;
52914 - vrh->vring.used = (__force struct vring_used *)used;
52915 + vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
52916 + vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
52917 + vrh->vring.used = (__force_kernel struct vring_used *)used;
52918 return 0;
52919 }
52920 EXPORT_SYMBOL(vringh_init_user);
52921 @@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
52922
52923 static inline int putu16_kern(u16 *p, u16 val)
52924 {
52925 - ACCESS_ONCE(*p) = val;
52926 + ACCESS_ONCE_RW(*p) = val;
52927 return 0;
52928 }
52929
52930 diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
52931 index 84a110a..96312c3 100644
52932 --- a/drivers/video/backlight/kb3886_bl.c
52933 +++ b/drivers/video/backlight/kb3886_bl.c
52934 @@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
52935 static unsigned long kb3886bl_flags;
52936 #define KB3886BL_SUSPENDED 0x01
52937
52938 -static struct dmi_system_id kb3886bl_device_table[] __initdata = {
52939 +static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
52940 {
52941 .ident = "Sahara Touch-iT",
52942 .matches = {
52943 diff --git a/drivers/video/fbdev/arcfb.c b/drivers/video/fbdev/arcfb.c
52944 index 1b0b233..6f34c2c 100644
52945 --- a/drivers/video/fbdev/arcfb.c
52946 +++ b/drivers/video/fbdev/arcfb.c
52947 @@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
52948 return -ENOSPC;
52949
52950 err = 0;
52951 - if ((count + p) > fbmemlength) {
52952 + if (count > (fbmemlength - p)) {
52953 count = fbmemlength - p;
52954 err = -ENOSPC;
52955 }
52956 diff --git a/drivers/video/fbdev/aty/aty128fb.c b/drivers/video/fbdev/aty/aty128fb.c
52957 index 52108be..c7c110d 100644
52958 --- a/drivers/video/fbdev/aty/aty128fb.c
52959 +++ b/drivers/video/fbdev/aty/aty128fb.c
52960 @@ -149,7 +149,7 @@ enum {
52961 };
52962
52963 /* Must match above enum */
52964 -static char * const r128_family[] = {
52965 +static const char * const r128_family[] = {
52966 "AGP",
52967 "PCI",
52968 "PRO AGP",
52969 diff --git a/drivers/video/fbdev/aty/atyfb_base.c b/drivers/video/fbdev/aty/atyfb_base.c
52970 index c3d0074..0b9077e 100644
52971 --- a/drivers/video/fbdev/aty/atyfb_base.c
52972 +++ b/drivers/video/fbdev/aty/atyfb_base.c
52973 @@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
52974 par->accel_flags = var->accel_flags; /* hack */
52975
52976 if (var->accel_flags) {
52977 - info->fbops->fb_sync = atyfb_sync;
52978 + pax_open_kernel();
52979 + *(void **)&info->fbops->fb_sync = atyfb_sync;
52980 + pax_close_kernel();
52981 info->flags &= ~FBINFO_HWACCEL_DISABLED;
52982 } else {
52983 - info->fbops->fb_sync = NULL;
52984 + pax_open_kernel();
52985 + *(void **)&info->fbops->fb_sync = NULL;
52986 + pax_close_kernel();
52987 info->flags |= FBINFO_HWACCEL_DISABLED;
52988 }
52989
52990 diff --git a/drivers/video/fbdev/aty/mach64_cursor.c b/drivers/video/fbdev/aty/mach64_cursor.c
52991 index 2fa0317..4983f2a 100644
52992 --- a/drivers/video/fbdev/aty/mach64_cursor.c
52993 +++ b/drivers/video/fbdev/aty/mach64_cursor.c
52994 @@ -8,6 +8,7 @@
52995 #include "../core/fb_draw.h"
52996
52997 #include <asm/io.h>
52998 +#include <asm/pgtable.h>
52999
53000 #ifdef __sparc__
53001 #include <asm/fbio.h>
53002 @@ -218,7 +219,9 @@ int aty_init_cursor(struct fb_info *info)
53003 info->sprite.buf_align = 16; /* and 64 lines tall. */
53004 info->sprite.flags = FB_PIXMAP_IO;
53005
53006 - info->fbops->fb_cursor = atyfb_cursor;
53007 + pax_open_kernel();
53008 + *(void **)&info->fbops->fb_cursor = atyfb_cursor;
53009 + pax_close_kernel();
53010
53011 return 0;
53012 }
53013 diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
53014 index 900aa4e..6d49418 100644
53015 --- a/drivers/video/fbdev/core/fb_defio.c
53016 +++ b/drivers/video/fbdev/core/fb_defio.c
53017 @@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
53018
53019 BUG_ON(!fbdefio);
53020 mutex_init(&fbdefio->lock);
53021 - info->fbops->fb_mmap = fb_deferred_io_mmap;
53022 + pax_open_kernel();
53023 + *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
53024 + pax_close_kernel();
53025 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
53026 INIT_LIST_HEAD(&fbdefio->pagelist);
53027 if (fbdefio->delay == 0) /* set a default of 1 s */
53028 @@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
53029 page->mapping = NULL;
53030 }
53031
53032 - info->fbops->fb_mmap = NULL;
53033 + *(void **)&info->fbops->fb_mmap = NULL;
53034 mutex_destroy(&fbdefio->lock);
53035 }
53036 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
53037 diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
53038 index b6d5008..5bca7bf 100644
53039 --- a/drivers/video/fbdev/core/fbmem.c
53040 +++ b/drivers/video/fbdev/core/fbmem.c
53041 @@ -433,7 +433,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
53042 image->dx += image->width + 8;
53043 }
53044 } else if (rotate == FB_ROTATE_UD) {
53045 - for (x = 0; x < num && image->dx >= 0; x++) {
53046 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
53047 info->fbops->fb_imageblit(info, image);
53048 image->dx -= image->width + 8;
53049 }
53050 @@ -445,7 +445,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
53051 image->dy += image->height + 8;
53052 }
53053 } else if (rotate == FB_ROTATE_CCW) {
53054 - for (x = 0; x < num && image->dy >= 0; x++) {
53055 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
53056 info->fbops->fb_imageblit(info, image);
53057 image->dy -= image->height + 8;
53058 }
53059 @@ -1179,7 +1179,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
53060 return -EFAULT;
53061 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
53062 return -EINVAL;
53063 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
53064 + if (con2fb.framebuffer >= FB_MAX)
53065 return -EINVAL;
53066 if (!registered_fb[con2fb.framebuffer])
53067 request_module("fb%d", con2fb.framebuffer);
53068 @@ -1300,7 +1300,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
53069 __u32 data;
53070 int err;
53071
53072 - err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
53073 + err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
53074
53075 data = (__u32) (unsigned long) fix->smem_start;
53076 err |= put_user(data, &fix32->smem_start);
53077 diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
53078 index e23392e..8a77540 100644
53079 --- a/drivers/video/fbdev/hyperv_fb.c
53080 +++ b/drivers/video/fbdev/hyperv_fb.c
53081 @@ -235,7 +235,7 @@ static uint screen_fb_size;
53082 static inline int synthvid_send(struct hv_device *hdev,
53083 struct synthvid_msg *msg)
53084 {
53085 - static atomic64_t request_id = ATOMIC64_INIT(0);
53086 + static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
53087 int ret;
53088
53089 msg->pipe_hdr.type = PIPE_MSG_DATA;
53090 @@ -243,7 +243,7 @@ static inline int synthvid_send(struct hv_device *hdev,
53091
53092 ret = vmbus_sendpacket(hdev->channel, msg,
53093 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
53094 - atomic64_inc_return(&request_id),
53095 + atomic64_inc_return_unchecked(&request_id),
53096 VM_PKT_DATA_INBAND, 0);
53097
53098 if (ret)
53099 diff --git a/drivers/video/fbdev/i810/i810_accel.c b/drivers/video/fbdev/i810/i810_accel.c
53100 index 7672d2e..b56437f 100644
53101 --- a/drivers/video/fbdev/i810/i810_accel.c
53102 +++ b/drivers/video/fbdev/i810/i810_accel.c
53103 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
53104 }
53105 }
53106 printk("ringbuffer lockup!!!\n");
53107 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
53108 i810_report_error(mmio);
53109 par->dev_flags |= LOCKUP;
53110 info->pixmap.scan_align = 1;
53111 diff --git a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
53112 index a01147f..5d896f8 100644
53113 --- a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
53114 +++ b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
53115 @@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
53116
53117 #ifdef CONFIG_FB_MATROX_MYSTIQUE
53118 struct matrox_switch matrox_mystique = {
53119 - MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
53120 + .preinit = MGA1064_preinit,
53121 + .reset = MGA1064_reset,
53122 + .init = MGA1064_init,
53123 + .restore = MGA1064_restore,
53124 };
53125 EXPORT_SYMBOL(matrox_mystique);
53126 #endif
53127
53128 #ifdef CONFIG_FB_MATROX_G
53129 struct matrox_switch matrox_G100 = {
53130 - MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
53131 + .preinit = MGAG100_preinit,
53132 + .reset = MGAG100_reset,
53133 + .init = MGAG100_init,
53134 + .restore = MGAG100_restore,
53135 };
53136 EXPORT_SYMBOL(matrox_G100);
53137 #endif
53138 diff --git a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
53139 index 195ad7c..09743fc 100644
53140 --- a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
53141 +++ b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
53142 @@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
53143 }
53144
53145 struct matrox_switch matrox_millennium = {
53146 - Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
53147 + .preinit = Ti3026_preinit,
53148 + .reset = Ti3026_reset,
53149 + .init = Ti3026_init,
53150 + .restore = Ti3026_restore
53151 };
53152 EXPORT_SYMBOL(matrox_millennium);
53153 #endif
53154 diff --git a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
53155 index fe92eed..106e085 100644
53156 --- a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
53157 +++ b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
53158 @@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
53159 struct mb862xxfb_par *par = info->par;
53160
53161 if (info->var.bits_per_pixel == 32) {
53162 - info->fbops->fb_fillrect = cfb_fillrect;
53163 - info->fbops->fb_copyarea = cfb_copyarea;
53164 - info->fbops->fb_imageblit = cfb_imageblit;
53165 + pax_open_kernel();
53166 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
53167 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
53168 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
53169 + pax_close_kernel();
53170 } else {
53171 outreg(disp, GC_L0EM, 3);
53172 - info->fbops->fb_fillrect = mb86290fb_fillrect;
53173 - info->fbops->fb_copyarea = mb86290fb_copyarea;
53174 - info->fbops->fb_imageblit = mb86290fb_imageblit;
53175 + pax_open_kernel();
53176 + *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
53177 + *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
53178 + *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
53179 + pax_close_kernel();
53180 }
53181 outreg(draw, GDC_REG_DRAW_BASE, 0);
53182 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
53183 diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c
53184 index def0412..fed6529 100644
53185 --- a/drivers/video/fbdev/nvidia/nvidia.c
53186 +++ b/drivers/video/fbdev/nvidia/nvidia.c
53187 @@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
53188 info->fix.line_length = (info->var.xres_virtual *
53189 info->var.bits_per_pixel) >> 3;
53190 if (info->var.accel_flags) {
53191 - info->fbops->fb_imageblit = nvidiafb_imageblit;
53192 - info->fbops->fb_fillrect = nvidiafb_fillrect;
53193 - info->fbops->fb_copyarea = nvidiafb_copyarea;
53194 - info->fbops->fb_sync = nvidiafb_sync;
53195 + pax_open_kernel();
53196 + *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
53197 + *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
53198 + *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
53199 + *(void **)&info->fbops->fb_sync = nvidiafb_sync;
53200 + pax_close_kernel();
53201 info->pixmap.scan_align = 4;
53202 info->flags &= ~FBINFO_HWACCEL_DISABLED;
53203 info->flags |= FBINFO_READS_FAST;
53204 NVResetGraphics(info);
53205 } else {
53206 - info->fbops->fb_imageblit = cfb_imageblit;
53207 - info->fbops->fb_fillrect = cfb_fillrect;
53208 - info->fbops->fb_copyarea = cfb_copyarea;
53209 - info->fbops->fb_sync = NULL;
53210 + pax_open_kernel();
53211 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
53212 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
53213 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
53214 + *(void **)&info->fbops->fb_sync = NULL;
53215 + pax_close_kernel();
53216 info->pixmap.scan_align = 1;
53217 info->flags |= FBINFO_HWACCEL_DISABLED;
53218 info->flags &= ~FBINFO_READS_FAST;
53219 @@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
53220 info->pixmap.size = 8 * 1024;
53221 info->pixmap.flags = FB_PIXMAP_SYSTEM;
53222
53223 - if (!hwcur)
53224 - info->fbops->fb_cursor = NULL;
53225 + if (!hwcur) {
53226 + pax_open_kernel();
53227 + *(void **)&info->fbops->fb_cursor = NULL;
53228 + pax_close_kernel();
53229 + }
53230
53231 info->var.accel_flags = (!noaccel);
53232
53233 diff --git a/drivers/video/fbdev/omap2/dss/display.c b/drivers/video/fbdev/omap2/dss/display.c
53234 index 2412a0d..294215b 100644
53235 --- a/drivers/video/fbdev/omap2/dss/display.c
53236 +++ b/drivers/video/fbdev/omap2/dss/display.c
53237 @@ -161,12 +161,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
53238 if (dssdev->name == NULL)
53239 dssdev->name = dssdev->alias;
53240
53241 + pax_open_kernel();
53242 if (drv && drv->get_resolution == NULL)
53243 - drv->get_resolution = omapdss_default_get_resolution;
53244 + *(void **)&drv->get_resolution = omapdss_default_get_resolution;
53245 if (drv && drv->get_recommended_bpp == NULL)
53246 - drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
53247 + *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
53248 if (drv && drv->get_timings == NULL)
53249 - drv->get_timings = omapdss_default_get_timings;
53250 + *(void **)&drv->get_timings = omapdss_default_get_timings;
53251 + pax_close_kernel();
53252
53253 mutex_lock(&panel_list_mutex);
53254 list_add_tail(&dssdev->panel_list, &panel_list);
53255 diff --git a/drivers/video/fbdev/s1d13xxxfb.c b/drivers/video/fbdev/s1d13xxxfb.c
53256 index 83433cb..71e9b98 100644
53257 --- a/drivers/video/fbdev/s1d13xxxfb.c
53258 +++ b/drivers/video/fbdev/s1d13xxxfb.c
53259 @@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
53260
53261 switch(prod_id) {
53262 case S1D13506_PROD_ID: /* activate acceleration */
53263 - s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
53264 - s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
53265 + pax_open_kernel();
53266 + *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
53267 + *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
53268 + pax_close_kernel();
53269 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
53270 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
53271 break;
53272 diff --git a/drivers/video/fbdev/sh_mobile_lcdcfb.c b/drivers/video/fbdev/sh_mobile_lcdcfb.c
53273 index 2bcc84a..29dd1ea 100644
53274 --- a/drivers/video/fbdev/sh_mobile_lcdcfb.c
53275 +++ b/drivers/video/fbdev/sh_mobile_lcdcfb.c
53276 @@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
53277 }
53278
53279 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
53280 - lcdc_sys_write_index,
53281 - lcdc_sys_write_data,
53282 - lcdc_sys_read_data,
53283 + .write_index = lcdc_sys_write_index,
53284 + .write_data = lcdc_sys_write_data,
53285 + .read_data = lcdc_sys_read_data,
53286 };
53287
53288 static int sh_mobile_lcdc_sginit(struct fb_info *info,
53289 diff --git a/drivers/video/fbdev/smscufx.c b/drivers/video/fbdev/smscufx.c
53290 index d513ed6..90b0de9 100644
53291 --- a/drivers/video/fbdev/smscufx.c
53292 +++ b/drivers/video/fbdev/smscufx.c
53293 @@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
53294 fb_deferred_io_cleanup(info);
53295 kfree(info->fbdefio);
53296 info->fbdefio = NULL;
53297 - info->fbops->fb_mmap = ufx_ops_mmap;
53298 + pax_open_kernel();
53299 + *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
53300 + pax_close_kernel();
53301 }
53302
53303 pr_debug("released /dev/fb%d user=%d count=%d",
53304 diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c
53305 index 77b890e..458e666 100644
53306 --- a/drivers/video/fbdev/udlfb.c
53307 +++ b/drivers/video/fbdev/udlfb.c
53308 @@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
53309 dlfb_urb_completion(urb);
53310
53311 error:
53312 - atomic_add(bytes_sent, &dev->bytes_sent);
53313 - atomic_add(bytes_identical, &dev->bytes_identical);
53314 - atomic_add(width*height*2, &dev->bytes_rendered);
53315 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
53316 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
53317 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
53318 end_cycles = get_cycles();
53319 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
53320 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
53321 >> 10)), /* Kcycles */
53322 &dev->cpu_kcycles_used);
53323
53324 @@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
53325 dlfb_urb_completion(urb);
53326
53327 error:
53328 - atomic_add(bytes_sent, &dev->bytes_sent);
53329 - atomic_add(bytes_identical, &dev->bytes_identical);
53330 - atomic_add(bytes_rendered, &dev->bytes_rendered);
53331 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
53332 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
53333 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
53334 end_cycles = get_cycles();
53335 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
53336 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
53337 >> 10)), /* Kcycles */
53338 &dev->cpu_kcycles_used);
53339 }
53340 @@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
53341 fb_deferred_io_cleanup(info);
53342 kfree(info->fbdefio);
53343 info->fbdefio = NULL;
53344 - info->fbops->fb_mmap = dlfb_ops_mmap;
53345 + pax_open_kernel();
53346 + *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
53347 + pax_close_kernel();
53348 }
53349
53350 pr_warn("released /dev/fb%d user=%d count=%d\n",
53351 @@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
53352 struct fb_info *fb_info = dev_get_drvdata(fbdev);
53353 struct dlfb_data *dev = fb_info->par;
53354 return snprintf(buf, PAGE_SIZE, "%u\n",
53355 - atomic_read(&dev->bytes_rendered));
53356 + atomic_read_unchecked(&dev->bytes_rendered));
53357 }
53358
53359 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
53360 @@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
53361 struct fb_info *fb_info = dev_get_drvdata(fbdev);
53362 struct dlfb_data *dev = fb_info->par;
53363 return snprintf(buf, PAGE_SIZE, "%u\n",
53364 - atomic_read(&dev->bytes_identical));
53365 + atomic_read_unchecked(&dev->bytes_identical));
53366 }
53367
53368 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
53369 @@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
53370 struct fb_info *fb_info = dev_get_drvdata(fbdev);
53371 struct dlfb_data *dev = fb_info->par;
53372 return snprintf(buf, PAGE_SIZE, "%u\n",
53373 - atomic_read(&dev->bytes_sent));
53374 + atomic_read_unchecked(&dev->bytes_sent));
53375 }
53376
53377 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
53378 @@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
53379 struct fb_info *fb_info = dev_get_drvdata(fbdev);
53380 struct dlfb_data *dev = fb_info->par;
53381 return snprintf(buf, PAGE_SIZE, "%u\n",
53382 - atomic_read(&dev->cpu_kcycles_used));
53383 + atomic_read_unchecked(&dev->cpu_kcycles_used));
53384 }
53385
53386 static ssize_t edid_show(
53387 @@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
53388 struct fb_info *fb_info = dev_get_drvdata(fbdev);
53389 struct dlfb_data *dev = fb_info->par;
53390
53391 - atomic_set(&dev->bytes_rendered, 0);
53392 - atomic_set(&dev->bytes_identical, 0);
53393 - atomic_set(&dev->bytes_sent, 0);
53394 - atomic_set(&dev->cpu_kcycles_used, 0);
53395 + atomic_set_unchecked(&dev->bytes_rendered, 0);
53396 + atomic_set_unchecked(&dev->bytes_identical, 0);
53397 + atomic_set_unchecked(&dev->bytes_sent, 0);
53398 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
53399
53400 return count;
53401 }
53402 diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c
53403 index 509d452..7c9d2de 100644
53404 --- a/drivers/video/fbdev/uvesafb.c
53405 +++ b/drivers/video/fbdev/uvesafb.c
53406 @@ -19,6 +19,7 @@
53407 #include <linux/io.h>
53408 #include <linux/mutex.h>
53409 #include <linux/slab.h>
53410 +#include <linux/moduleloader.h>
53411 #include <video/edid.h>
53412 #include <video/uvesafb.h>
53413 #ifdef CONFIG_X86
53414 @@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
53415 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
53416 par->pmi_setpal = par->ypan = 0;
53417 } else {
53418 +
53419 +#ifdef CONFIG_PAX_KERNEXEC
53420 +#ifdef CONFIG_MODULES
53421 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
53422 +#endif
53423 + if (!par->pmi_code) {
53424 + par->pmi_setpal = par->ypan = 0;
53425 + return 0;
53426 + }
53427 +#endif
53428 +
53429 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
53430 + task->t.regs.edi);
53431 +
53432 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53433 + pax_open_kernel();
53434 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
53435 + pax_close_kernel();
53436 +
53437 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
53438 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
53439 +#else
53440 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
53441 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
53442 +#endif
53443 +
53444 printk(KERN_INFO "uvesafb: protected mode interface info at "
53445 "%04x:%04x\n",
53446 (u16)task->t.regs.es, (u16)task->t.regs.edi);
53447 @@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
53448 par->ypan = ypan;
53449
53450 if (par->pmi_setpal || par->ypan) {
53451 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
53452 if (__supported_pte_mask & _PAGE_NX) {
53453 par->pmi_setpal = par->ypan = 0;
53454 printk(KERN_WARNING "uvesafb: NX protection is active, "
53455 "better not use the PMI.\n");
53456 - } else {
53457 + } else
53458 +#endif
53459 uvesafb_vbe_getpmi(task, par);
53460 - }
53461 }
53462 #else
53463 /* The protected mode interface is not available on non-x86. */
53464 @@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
53465 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
53466
53467 /* Disable blanking if the user requested so. */
53468 - if (!blank)
53469 - info->fbops->fb_blank = NULL;
53470 + if (!blank) {
53471 + pax_open_kernel();
53472 + *(void **)&info->fbops->fb_blank = NULL;
53473 + pax_close_kernel();
53474 + }
53475
53476 /*
53477 * Find out how much IO memory is required for the mode with
53478 @@ -1525,8 +1552,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
53479 info->flags = FBINFO_FLAG_DEFAULT |
53480 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
53481
53482 - if (!par->ypan)
53483 - info->fbops->fb_pan_display = NULL;
53484 + if (!par->ypan) {
53485 + pax_open_kernel();
53486 + *(void **)&info->fbops->fb_pan_display = NULL;
53487 + pax_close_kernel();
53488 + }
53489 }
53490
53491 static void uvesafb_init_mtrr(struct fb_info *info)
53492 @@ -1787,6 +1817,11 @@ out_mode:
53493 out:
53494 kfree(par->vbe_modes);
53495
53496 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53497 + if (par->pmi_code)
53498 + module_free_exec(NULL, par->pmi_code);
53499 +#endif
53500 +
53501 framebuffer_release(info);
53502 return err;
53503 }
53504 @@ -1811,6 +1846,11 @@ static int uvesafb_remove(struct platform_device *dev)
53505 kfree(par->vbe_state_orig);
53506 kfree(par->vbe_state_saved);
53507
53508 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53509 + if (par->pmi_code)
53510 + module_free_exec(NULL, par->pmi_code);
53511 +#endif
53512 +
53513 framebuffer_release(info);
53514 }
53515 return 0;
53516 diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
53517 index 6170e7f..dd63031 100644
53518 --- a/drivers/video/fbdev/vesafb.c
53519 +++ b/drivers/video/fbdev/vesafb.c
53520 @@ -9,6 +9,7 @@
53521 */
53522
53523 #include <linux/module.h>
53524 +#include <linux/moduleloader.h>
53525 #include <linux/kernel.h>
53526 #include <linux/errno.h>
53527 #include <linux/string.h>
53528 @@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
53529 static int vram_total; /* Set total amount of memory */
53530 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
53531 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
53532 -static void (*pmi_start)(void) __read_mostly;
53533 -static void (*pmi_pal) (void) __read_mostly;
53534 +static void (*pmi_start)(void) __read_only;
53535 +static void (*pmi_pal) (void) __read_only;
53536 static int depth __read_mostly;
53537 static int vga_compat __read_mostly;
53538 /* --------------------------------------------------------------------- */
53539 @@ -233,6 +234,7 @@ static int vesafb_probe(struct platform_device *dev)
53540 unsigned int size_remap;
53541 unsigned int size_total;
53542 char *option = NULL;
53543 + void *pmi_code = NULL;
53544
53545 /* ignore error return of fb_get_options */
53546 fb_get_options("vesafb", &option);
53547 @@ -279,10 +281,6 @@ static int vesafb_probe(struct platform_device *dev)
53548 size_remap = size_total;
53549 vesafb_fix.smem_len = size_remap;
53550
53551 -#ifndef __i386__
53552 - screen_info.vesapm_seg = 0;
53553 -#endif
53554 -
53555 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
53556 printk(KERN_WARNING
53557 "vesafb: cannot reserve video memory at 0x%lx\n",
53558 @@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
53559 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
53560 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
53561
53562 +#ifdef __i386__
53563 +
53564 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53565 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
53566 + if (!pmi_code)
53567 +#elif !defined(CONFIG_PAX_KERNEXEC)
53568 + if (0)
53569 +#endif
53570 +
53571 +#endif
53572 + screen_info.vesapm_seg = 0;
53573 +
53574 if (screen_info.vesapm_seg) {
53575 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
53576 - screen_info.vesapm_seg,screen_info.vesapm_off);
53577 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
53578 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
53579 }
53580
53581 if (screen_info.vesapm_seg < 0xc000)
53582 @@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
53583
53584 if (ypan || pmi_setpal) {
53585 unsigned short *pmi_base;
53586 +
53587 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
53588 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
53589 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
53590 +
53591 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53592 + pax_open_kernel();
53593 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
53594 +#else
53595 + pmi_code = pmi_base;
53596 +#endif
53597 +
53598 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
53599 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
53600 +
53601 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53602 + pmi_start = ktva_ktla(pmi_start);
53603 + pmi_pal = ktva_ktla(pmi_pal);
53604 + pax_close_kernel();
53605 +#endif
53606 +
53607 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
53608 if (pmi_base[3]) {
53609 printk(KERN_INFO "vesafb: pmi: ports = ");
53610 @@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
53611 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
53612 (ypan ? FBINFO_HWACCEL_YPAN : 0);
53613
53614 - if (!ypan)
53615 - info->fbops->fb_pan_display = NULL;
53616 + if (!ypan) {
53617 + pax_open_kernel();
53618 + *(void **)&info->fbops->fb_pan_display = NULL;
53619 + pax_close_kernel();
53620 + }
53621
53622 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
53623 err = -ENOMEM;
53624 @@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
53625 fb_info(info, "%s frame buffer device\n", info->fix.id);
53626 return 0;
53627 err:
53628 +
53629 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53630 + module_free_exec(NULL, pmi_code);
53631 +#endif
53632 +
53633 if (info->screen_base)
53634 iounmap(info->screen_base);
53635 framebuffer_release(info);
53636 diff --git a/drivers/video/fbdev/via/via_clock.h b/drivers/video/fbdev/via/via_clock.h
53637 index 88714ae..16c2e11 100644
53638 --- a/drivers/video/fbdev/via/via_clock.h
53639 +++ b/drivers/video/fbdev/via/via_clock.h
53640 @@ -56,7 +56,7 @@ struct via_clock {
53641
53642 void (*set_engine_pll_state)(u8 state);
53643 void (*set_engine_pll)(struct via_pll_config config);
53644 -};
53645 +} __no_const;
53646
53647
53648 static inline u32 get_pll_internal_frequency(u32 ref_freq,
53649 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
53650 index 3c14e43..2630570 100644
53651 --- a/drivers/video/logo/logo_linux_clut224.ppm
53652 +++ b/drivers/video/logo/logo_linux_clut224.ppm
53653 @@ -2,1603 +2,1123 @@ P3
53654 # Standard 224-color Linux logo
53655 80 80
53656 255
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 0 0 0 0 0 0 0 0 0 0
53665 - 0 0 0 0 0 0 0 0 0 0 0 0
53666 - 6 6 6 6 6 6 10 10 10 10 10 10
53667 - 10 10 10 6 6 6 6 6 6 6 6 6
53668 - 0 0 0 0 0 0 0 0 0 0 0 0
53669 - 0 0 0 0 0 0 0 0 0 0 0 0
53670 - 0 0 0 0 0 0 0 0 0 0 0 0
53671 - 0 0 0 0 0 0 0 0 0 0 0 0
53672 - 0 0 0 0 0 0 0 0 0 0 0 0
53673 - 0 0 0 0 0 0 0 0 0 0 0 0
53674 - 0 0 0 0 0 0 0 0 0 0 0 0
53675 - 0 0 0 0 0 0 0 0 0 0 0 0
53676 - 0 0 0 0 0 0 0 0 0 0 0 0
53677 - 0 0 0 0 0 0 0 0 0 0 0 0
53678 - 0 0 0 0 0 0 0 0 0 0 0 0
53679 - 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0
53685 - 0 0 0 6 6 6 10 10 10 14 14 14
53686 - 22 22 22 26 26 26 30 30 30 34 34 34
53687 - 30 30 30 30 30 30 26 26 26 18 18 18
53688 - 14 14 14 10 10 10 6 6 6 0 0 0
53689 - 0 0 0 0 0 0 0 0 0 0 0 0
53690 - 0 0 0 0 0 0 0 0 0 0 0 0
53691 - 0 0 0 0 0 0 0 0 0 0 0 0
53692 - 0 0 0 0 0 0 0 0 0 0 0 0
53693 - 0 0 0 0 0 0 0 0 0 0 0 0
53694 - 0 0 0 0 0 0 0 0 0 0 0 0
53695 - 0 0 0 0 0 0 0 0 0 0 0 0
53696 - 0 0 0 0 0 0 0 0 0 0 0 0
53697 - 0 0 0 0 0 0 0 0 0 0 0 0
53698 - 0 0 0 0 0 1 0 0 1 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 0 0 0 0 0 0 0 0 0 0
53705 - 6 6 6 14 14 14 26 26 26 42 42 42
53706 - 54 54 54 66 66 66 78 78 78 78 78 78
53707 - 78 78 78 74 74 74 66 66 66 54 54 54
53708 - 42 42 42 26 26 26 18 18 18 10 10 10
53709 - 6 6 6 0 0 0 0 0 0 0 0 0
53710 - 0 0 0 0 0 0 0 0 0 0 0 0
53711 - 0 0 0 0 0 0 0 0 0 0 0 0
53712 - 0 0 0 0 0 0 0 0 0 0 0 0
53713 - 0 0 0 0 0 0 0 0 0 0 0 0
53714 - 0 0 0 0 0 0 0 0 0 0 0 0
53715 - 0 0 0 0 0 0 0 0 0 0 0 0
53716 - 0 0 0 0 0 0 0 0 0 0 0 0
53717 - 0 0 0 0 0 0 0 0 0 0 0 0
53718 - 0 0 1 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 10 10 10
53725 - 22 22 22 42 42 42 66 66 66 86 86 86
53726 - 66 66 66 38 38 38 38 38 38 22 22 22
53727 - 26 26 26 34 34 34 54 54 54 66 66 66
53728 - 86 86 86 70 70 70 46 46 46 26 26 26
53729 - 14 14 14 6 6 6 0 0 0 0 0 0
53730 - 0 0 0 0 0 0 0 0 0 0 0 0
53731 - 0 0 0 0 0 0 0 0 0 0 0 0
53732 - 0 0 0 0 0 0 0 0 0 0 0 0
53733 - 0 0 0 0 0 0 0 0 0 0 0 0
53734 - 0 0 0 0 0 0 0 0 0 0 0 0
53735 - 0 0 0 0 0 0 0 0 0 0 0 0
53736 - 0 0 0 0 0 0 0 0 0 0 0 0
53737 - 0 0 0 0 0 0 0 0 0 0 0 0
53738 - 0 0 1 0 0 1 0 0 1 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 0 10 10 10 26 26 26
53745 - 50 50 50 82 82 82 58 58 58 6 6 6
53746 - 2 2 6 2 2 6 2 2 6 2 2 6
53747 - 2 2 6 2 2 6 2 2 6 2 2 6
53748 - 6 6 6 54 54 54 86 86 86 66 66 66
53749 - 38 38 38 18 18 18 6 6 6 0 0 0
53750 - 0 0 0 0 0 0 0 0 0 0 0 0
53751 - 0 0 0 0 0 0 0 0 0 0 0 0
53752 - 0 0 0 0 0 0 0 0 0 0 0 0
53753 - 0 0 0 0 0 0 0 0 0 0 0 0
53754 - 0 0 0 0 0 0 0 0 0 0 0 0
53755 - 0 0 0 0 0 0 0 0 0 0 0 0
53756 - 0 0 0 0 0 0 0 0 0 0 0 0
53757 - 0 0 0 0 0 0 0 0 0 0 0 0
53758 - 0 0 0 0 0 0 0 0 0 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 0 6 6 6 22 22 22 50 50 50
53765 - 78 78 78 34 34 34 2 2 6 2 2 6
53766 - 2 2 6 2 2 6 2 2 6 2 2 6
53767 - 2 2 6 2 2 6 2 2 6 2 2 6
53768 - 2 2 6 2 2 6 6 6 6 70 70 70
53769 - 78 78 78 46 46 46 22 22 22 6 6 6
53770 - 0 0 0 0 0 0 0 0 0 0 0 0
53771 - 0 0 0 0 0 0 0 0 0 0 0 0
53772 - 0 0 0 0 0 0 0 0 0 0 0 0
53773 - 0 0 0 0 0 0 0 0 0 0 0 0
53774 - 0 0 0 0 0 0 0 0 0 0 0 0
53775 - 0 0 0 0 0 0 0 0 0 0 0 0
53776 - 0 0 0 0 0 0 0 0 0 0 0 0
53777 - 0 0 0 0 0 0 0 0 0 0 0 0
53778 - 0 0 1 0 0 1 0 0 1 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 - 6 6 6 18 18 18 42 42 42 82 82 82
53785 - 26 26 26 2 2 6 2 2 6 2 2 6
53786 - 2 2 6 2 2 6 2 2 6 2 2 6
53787 - 2 2 6 2 2 6 2 2 6 14 14 14
53788 - 46 46 46 34 34 34 6 6 6 2 2 6
53789 - 42 42 42 78 78 78 42 42 42 18 18 18
53790 - 6 6 6 0 0 0 0 0 0 0 0 0
53791 - 0 0 0 0 0 0 0 0 0 0 0 0
53792 - 0 0 0 0 0 0 0 0 0 0 0 0
53793 - 0 0 0 0 0 0 0 0 0 0 0 0
53794 - 0 0 0 0 0 0 0 0 0 0 0 0
53795 - 0 0 0 0 0 0 0 0 0 0 0 0
53796 - 0 0 0 0 0 0 0 0 0 0 0 0
53797 - 0 0 0 0 0 0 0 0 0 0 0 0
53798 - 0 0 1 0 0 0 0 0 1 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 - 10 10 10 30 30 30 66 66 66 58 58 58
53805 - 2 2 6 2 2 6 2 2 6 2 2 6
53806 - 2 2 6 2 2 6 2 2 6 2 2 6
53807 - 2 2 6 2 2 6 2 2 6 26 26 26
53808 - 86 86 86 101 101 101 46 46 46 10 10 10
53809 - 2 2 6 58 58 58 70 70 70 34 34 34
53810 - 10 10 10 0 0 0 0 0 0 0 0 0
53811 - 0 0 0 0 0 0 0 0 0 0 0 0
53812 - 0 0 0 0 0 0 0 0 0 0 0 0
53813 - 0 0 0 0 0 0 0 0 0 0 0 0
53814 - 0 0 0 0 0 0 0 0 0 0 0 0
53815 - 0 0 0 0 0 0 0 0 0 0 0 0
53816 - 0 0 0 0 0 0 0 0 0 0 0 0
53817 - 0 0 0 0 0 0 0 0 0 0 0 0
53818 - 0 0 1 0 0 1 0 0 1 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 - 14 14 14 42 42 42 86 86 86 10 10 10
53825 - 2 2 6 2 2 6 2 2 6 2 2 6
53826 - 2 2 6 2 2 6 2 2 6 2 2 6
53827 - 2 2 6 2 2 6 2 2 6 30 30 30
53828 - 94 94 94 94 94 94 58 58 58 26 26 26
53829 - 2 2 6 6 6 6 78 78 78 54 54 54
53830 - 22 22 22 6 6 6 0 0 0 0 0 0
53831 - 0 0 0 0 0 0 0 0 0 0 0 0
53832 - 0 0 0 0 0 0 0 0 0 0 0 0
53833 - 0 0 0 0 0 0 0 0 0 0 0 0
53834 - 0 0 0 0 0 0 0 0 0 0 0 0
53835 - 0 0 0 0 0 0 0 0 0 0 0 0
53836 - 0 0 0 0 0 0 0 0 0 0 0 0
53837 - 0 0 0 0 0 0 0 0 0 0 0 0
53838 - 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 6 6 6
53844 - 22 22 22 62 62 62 62 62 62 2 2 6
53845 - 2 2 6 2 2 6 2 2 6 2 2 6
53846 - 2 2 6 2 2 6 2 2 6 2 2 6
53847 - 2 2 6 2 2 6 2 2 6 26 26 26
53848 - 54 54 54 38 38 38 18 18 18 10 10 10
53849 - 2 2 6 2 2 6 34 34 34 82 82 82
53850 - 38 38 38 14 14 14 0 0 0 0 0 0
53851 - 0 0 0 0 0 0 0 0 0 0 0 0
53852 - 0 0 0 0 0 0 0 0 0 0 0 0
53853 - 0 0 0 0 0 0 0 0 0 0 0 0
53854 - 0 0 0 0 0 0 0 0 0 0 0 0
53855 - 0 0 0 0 0 0 0 0 0 0 0 0
53856 - 0 0 0 0 0 0 0 0 0 0 0 0
53857 - 0 0 0 0 0 0 0 0 0 0 0 0
53858 - 0 0 0 0 0 1 0 0 1 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 0 6 6 6
53864 - 30 30 30 78 78 78 30 30 30 2 2 6
53865 - 2 2 6 2 2 6 2 2 6 2 2 6
53866 - 2 2 6 2 2 6 2 2 6 2 2 6
53867 - 2 2 6 2 2 6 2 2 6 10 10 10
53868 - 10 10 10 2 2 6 2 2 6 2 2 6
53869 - 2 2 6 2 2 6 2 2 6 78 78 78
53870 - 50 50 50 18 18 18 6 6 6 0 0 0
53871 - 0 0 0 0 0 0 0 0 0 0 0 0
53872 - 0 0 0 0 0 0 0 0 0 0 0 0
53873 - 0 0 0 0 0 0 0 0 0 0 0 0
53874 - 0 0 0 0 0 0 0 0 0 0 0 0
53875 - 0 0 0 0 0 0 0 0 0 0 0 0
53876 - 0 0 0 0 0 0 0 0 0 0 0 0
53877 - 0 0 0 0 0 0 0 0 0 0 0 0
53878 - 0 0 1 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 10 10 10
53884 - 38 38 38 86 86 86 14 14 14 2 2 6
53885 - 2 2 6 2 2 6 2 2 6 2 2 6
53886 - 2 2 6 2 2 6 2 2 6 2 2 6
53887 - 2 2 6 2 2 6 2 2 6 2 2 6
53888 - 2 2 6 2 2 6 2 2 6 2 2 6
53889 - 2 2 6 2 2 6 2 2 6 54 54 54
53890 - 66 66 66 26 26 26 6 6 6 0 0 0
53891 - 0 0 0 0 0 0 0 0 0 0 0 0
53892 - 0 0 0 0 0 0 0 0 0 0 0 0
53893 - 0 0 0 0 0 0 0 0 0 0 0 0
53894 - 0 0 0 0 0 0 0 0 0 0 0 0
53895 - 0 0 0 0 0 0 0 0 0 0 0 0
53896 - 0 0 0 0 0 0 0 0 0 0 0 0
53897 - 0 0 0 0 0 0 0 0 0 0 0 0
53898 - 0 0 0 0 0 1 0 0 1 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 0 14 14 14
53904 - 42 42 42 82 82 82 2 2 6 2 2 6
53905 - 2 2 6 6 6 6 10 10 10 2 2 6
53906 - 2 2 6 2 2 6 2 2 6 2 2 6
53907 - 2 2 6 2 2 6 2 2 6 6 6 6
53908 - 14 14 14 10 10 10 2 2 6 2 2 6
53909 - 2 2 6 2 2 6 2 2 6 18 18 18
53910 - 82 82 82 34 34 34 10 10 10 0 0 0
53911 - 0 0 0 0 0 0 0 0 0 0 0 0
53912 - 0 0 0 0 0 0 0 0 0 0 0 0
53913 - 0 0 0 0 0 0 0 0 0 0 0 0
53914 - 0 0 0 0 0 0 0 0 0 0 0 0
53915 - 0 0 0 0 0 0 0 0 0 0 0 0
53916 - 0 0 0 0 0 0 0 0 0 0 0 0
53917 - 0 0 0 0 0 0 0 0 0 0 0 0
53918 - 0 0 1 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 0 14 14 14
53924 - 46 46 46 86 86 86 2 2 6 2 2 6
53925 - 6 6 6 6 6 6 22 22 22 34 34 34
53926 - 6 6 6 2 2 6 2 2 6 2 2 6
53927 - 2 2 6 2 2 6 18 18 18 34 34 34
53928 - 10 10 10 50 50 50 22 22 22 2 2 6
53929 - 2 2 6 2 2 6 2 2 6 10 10 10
53930 - 86 86 86 42 42 42 14 14 14 0 0 0
53931 - 0 0 0 0 0 0 0 0 0 0 0 0
53932 - 0 0 0 0 0 0 0 0 0 0 0 0
53933 - 0 0 0 0 0 0 0 0 0 0 0 0
53934 - 0 0 0 0 0 0 0 0 0 0 0 0
53935 - 0 0 0 0 0 0 0 0 0 0 0 0
53936 - 0 0 0 0 0 0 0 0 0 0 0 0
53937 - 0 0 0 0 0 0 0 0 0 0 0 0
53938 - 0 0 1 0 0 1 0 0 1 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 0 14 14 14
53944 - 46 46 46 86 86 86 2 2 6 2 2 6
53945 - 38 38 38 116 116 116 94 94 94 22 22 22
53946 - 22 22 22 2 2 6 2 2 6 2 2 6
53947 - 14 14 14 86 86 86 138 138 138 162 162 162
53948 -154 154 154 38 38 38 26 26 26 6 6 6
53949 - 2 2 6 2 2 6 2 2 6 2 2 6
53950 - 86 86 86 46 46 46 14 14 14 0 0 0
53951 - 0 0 0 0 0 0 0 0 0 0 0 0
53952 - 0 0 0 0 0 0 0 0 0 0 0 0
53953 - 0 0 0 0 0 0 0 0 0 0 0 0
53954 - 0 0 0 0 0 0 0 0 0 0 0 0
53955 - 0 0 0 0 0 0 0 0 0 0 0 0
53956 - 0 0 0 0 0 0 0 0 0 0 0 0
53957 - 0 0 0 0 0 0 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 14 14 14
53964 - 46 46 46 86 86 86 2 2 6 14 14 14
53965 -134 134 134 198 198 198 195 195 195 116 116 116
53966 - 10 10 10 2 2 6 2 2 6 6 6 6
53967 -101 98 89 187 187 187 210 210 210 218 218 218
53968 -214 214 214 134 134 134 14 14 14 6 6 6
53969 - 2 2 6 2 2 6 2 2 6 2 2 6
53970 - 86 86 86 50 50 50 18 18 18 6 6 6
53971 - 0 0 0 0 0 0 0 0 0 0 0 0
53972 - 0 0 0 0 0 0 0 0 0 0 0 0
53973 - 0 0 0 0 0 0 0 0 0 0 0 0
53974 - 0 0 0 0 0 0 0 0 0 0 0 0
53975 - 0 0 0 0 0 0 0 0 0 0 0 0
53976 - 0 0 0 0 0 0 0 0 0 0 0 0
53977 - 0 0 0 0 0 0 0 0 1 0 0 0
53978 - 0 0 1 0 0 1 0 0 1 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 14 14 14
53984 - 46 46 46 86 86 86 2 2 6 54 54 54
53985 -218 218 218 195 195 195 226 226 226 246 246 246
53986 - 58 58 58 2 2 6 2 2 6 30 30 30
53987 -210 210 210 253 253 253 174 174 174 123 123 123
53988 -221 221 221 234 234 234 74 74 74 2 2 6
53989 - 2 2 6 2 2 6 2 2 6 2 2 6
53990 - 70 70 70 58 58 58 22 22 22 6 6 6
53991 - 0 0 0 0 0 0 0 0 0 0 0 0
53992 - 0 0 0 0 0 0 0 0 0 0 0 0
53993 - 0 0 0 0 0 0 0 0 0 0 0 0
53994 - 0 0 0 0 0 0 0 0 0 0 0 0
53995 - 0 0 0 0 0 0 0 0 0 0 0 0
53996 - 0 0 0 0 0 0 0 0 0 0 0 0
53997 - 0 0 0 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 14 14 14
54004 - 46 46 46 82 82 82 2 2 6 106 106 106
54005 -170 170 170 26 26 26 86 86 86 226 226 226
54006 -123 123 123 10 10 10 14 14 14 46 46 46
54007 -231 231 231 190 190 190 6 6 6 70 70 70
54008 - 90 90 90 238 238 238 158 158 158 2 2 6
54009 - 2 2 6 2 2 6 2 2 6 2 2 6
54010 - 70 70 70 58 58 58 22 22 22 6 6 6
54011 - 0 0 0 0 0 0 0 0 0 0 0 0
54012 - 0 0 0 0 0 0 0 0 0 0 0 0
54013 - 0 0 0 0 0 0 0 0 0 0 0 0
54014 - 0 0 0 0 0 0 0 0 0 0 0 0
54015 - 0 0 0 0 0 0 0 0 0 0 0 0
54016 - 0 0 0 0 0 0 0 0 0 0 0 0
54017 - 0 0 0 0 0 0 0 0 1 0 0 0
54018 - 0 0 1 0 0 1 0 0 1 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 14 14 14
54024 - 42 42 42 86 86 86 6 6 6 116 116 116
54025 -106 106 106 6 6 6 70 70 70 149 149 149
54026 -128 128 128 18 18 18 38 38 38 54 54 54
54027 -221 221 221 106 106 106 2 2 6 14 14 14
54028 - 46 46 46 190 190 190 198 198 198 2 2 6
54029 - 2 2 6 2 2 6 2 2 6 2 2 6
54030 - 74 74 74 62 62 62 22 22 22 6 6 6
54031 - 0 0 0 0 0 0 0 0 0 0 0 0
54032 - 0 0 0 0 0 0 0 0 0 0 0 0
54033 - 0 0 0 0 0 0 0 0 0 0 0 0
54034 - 0 0 0 0 0 0 0 0 0 0 0 0
54035 - 0 0 0 0 0 0 0 0 0 0 0 0
54036 - 0 0 0 0 0 0 0 0 0 0 0 0
54037 - 0 0 0 0 0 0 0 0 1 0 0 0
54038 - 0 0 1 0 0 0 0 0 1 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 14 14 14
54044 - 42 42 42 94 94 94 14 14 14 101 101 101
54045 -128 128 128 2 2 6 18 18 18 116 116 116
54046 -118 98 46 121 92 8 121 92 8 98 78 10
54047 -162 162 162 106 106 106 2 2 6 2 2 6
54048 - 2 2 6 195 195 195 195 195 195 6 6 6
54049 - 2 2 6 2 2 6 2 2 6 2 2 6
54050 - 74 74 74 62 62 62 22 22 22 6 6 6
54051 - 0 0 0 0 0 0 0 0 0 0 0 0
54052 - 0 0 0 0 0 0 0 0 0 0 0 0
54053 - 0 0 0 0 0 0 0 0 0 0 0 0
54054 - 0 0 0 0 0 0 0 0 0 0 0 0
54055 - 0 0 0 0 0 0 0 0 0 0 0 0
54056 - 0 0 0 0 0 0 0 0 0 0 0 0
54057 - 0 0 0 0 0 0 0 0 1 0 0 1
54058 - 0 0 1 0 0 0 0 0 1 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 10 10 10
54064 - 38 38 38 90 90 90 14 14 14 58 58 58
54065 -210 210 210 26 26 26 54 38 6 154 114 10
54066 -226 170 11 236 186 11 225 175 15 184 144 12
54067 -215 174 15 175 146 61 37 26 9 2 2 6
54068 - 70 70 70 246 246 246 138 138 138 2 2 6
54069 - 2 2 6 2 2 6 2 2 6 2 2 6
54070 - 70 70 70 66 66 66 26 26 26 6 6 6
54071 - 0 0 0 0 0 0 0 0 0 0 0 0
54072 - 0 0 0 0 0 0 0 0 0 0 0 0
54073 - 0 0 0 0 0 0 0 0 0 0 0 0
54074 - 0 0 0 0 0 0 0 0 0 0 0 0
54075 - 0 0 0 0 0 0 0 0 0 0 0 0
54076 - 0 0 0 0 0 0 0 0 0 0 0 0
54077 - 0 0 0 0 0 0 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 10 10 10
54084 - 38 38 38 86 86 86 14 14 14 10 10 10
54085 -195 195 195 188 164 115 192 133 9 225 175 15
54086 -239 182 13 234 190 10 232 195 16 232 200 30
54087 -245 207 45 241 208 19 232 195 16 184 144 12
54088 -218 194 134 211 206 186 42 42 42 2 2 6
54089 - 2 2 6 2 2 6 2 2 6 2 2 6
54090 - 50 50 50 74 74 74 30 30 30 6 6 6
54091 - 0 0 0 0 0 0 0 0 0 0 0 0
54092 - 0 0 0 0 0 0 0 0 0 0 0 0
54093 - 0 0 0 0 0 0 0 0 0 0 0 0
54094 - 0 0 0 0 0 0 0 0 0 0 0 0
54095 - 0 0 0 0 0 0 0 0 0 0 0 0
54096 - 0 0 0 0 0 0 0 0 0 0 0 0
54097 - 0 0 0 0 0 0 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 10 10 10
54104 - 34 34 34 86 86 86 14 14 14 2 2 6
54105 -121 87 25 192 133 9 219 162 10 239 182 13
54106 -236 186 11 232 195 16 241 208 19 244 214 54
54107 -246 218 60 246 218 38 246 215 20 241 208 19
54108 -241 208 19 226 184 13 121 87 25 2 2 6
54109 - 2 2 6 2 2 6 2 2 6 2 2 6
54110 - 50 50 50 82 82 82 34 34 34 10 10 10
54111 - 0 0 0 0 0 0 0 0 0 0 0 0
54112 - 0 0 0 0 0 0 0 0 0 0 0 0
54113 - 0 0 0 0 0 0 0 0 0 0 0 0
54114 - 0 0 0 0 0 0 0 0 0 0 0 0
54115 - 0 0 0 0 0 0 0 0 0 0 0 0
54116 - 0 0 0 0 0 0 0 0 0 0 0 0
54117 - 0 0 0 0 0 0 0 0 0 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 10 10 10
54124 - 34 34 34 82 82 82 30 30 30 61 42 6
54125 -180 123 7 206 145 10 230 174 11 239 182 13
54126 -234 190 10 238 202 15 241 208 19 246 218 74
54127 -246 218 38 246 215 20 246 215 20 246 215 20
54128 -226 184 13 215 174 15 184 144 12 6 6 6
54129 - 2 2 6 2 2 6 2 2 6 2 2 6
54130 - 26 26 26 94 94 94 42 42 42 14 14 14
54131 - 0 0 0 0 0 0 0 0 0 0 0 0
54132 - 0 0 0 0 0 0 0 0 0 0 0 0
54133 - 0 0 0 0 0 0 0 0 0 0 0 0
54134 - 0 0 0 0 0 0 0 0 0 0 0 0
54135 - 0 0 0 0 0 0 0 0 0 0 0 0
54136 - 0 0 0 0 0 0 0 0 0 0 0 0
54137 - 0 0 0 0 0 0 0 0 0 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 10 10 10
54144 - 30 30 30 78 78 78 50 50 50 104 69 6
54145 -192 133 9 216 158 10 236 178 12 236 186 11
54146 -232 195 16 241 208 19 244 214 54 245 215 43
54147 -246 215 20 246 215 20 241 208 19 198 155 10
54148 -200 144 11 216 158 10 156 118 10 2 2 6
54149 - 2 2 6 2 2 6 2 2 6 2 2 6
54150 - 6 6 6 90 90 90 54 54 54 18 18 18
54151 - 6 6 6 0 0 0 0 0 0 0 0 0
54152 - 0 0 0 0 0 0 0 0 0 0 0 0
54153 - 0 0 0 0 0 0 0 0 0 0 0 0
54154 - 0 0 0 0 0 0 0 0 0 0 0 0
54155 - 0 0 0 0 0 0 0 0 0 0 0 0
54156 - 0 0 0 0 0 0 0 0 0 0 0 0
54157 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
54164 - 30 30 30 78 78 78 46 46 46 22 22 22
54165 -137 92 6 210 162 10 239 182 13 238 190 10
54166 -238 202 15 241 208 19 246 215 20 246 215 20
54167 -241 208 19 203 166 17 185 133 11 210 150 10
54168 -216 158 10 210 150 10 102 78 10 2 2 6
54169 - 6 6 6 54 54 54 14 14 14 2 2 6
54170 - 2 2 6 62 62 62 74 74 74 30 30 30
54171 - 10 10 10 0 0 0 0 0 0 0 0 0
54172 - 0 0 0 0 0 0 0 0 0 0 0 0
54173 - 0 0 0 0 0 0 0 0 0 0 0 0
54174 - 0 0 0 0 0 0 0 0 0 0 0 0
54175 - 0 0 0 0 0 0 0 0 0 0 0 0
54176 - 0 0 0 0 0 0 0 0 0 0 0 0
54177 - 0 0 0 0 0 0 0 0 0 0 0 0
54178 - 0 0 0 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 10 10 10
54184 - 34 34 34 78 78 78 50 50 50 6 6 6
54185 - 94 70 30 139 102 15 190 146 13 226 184 13
54186 -232 200 30 232 195 16 215 174 15 190 146 13
54187 -168 122 10 192 133 9 210 150 10 213 154 11
54188 -202 150 34 182 157 106 101 98 89 2 2 6
54189 - 2 2 6 78 78 78 116 116 116 58 58 58
54190 - 2 2 6 22 22 22 90 90 90 46 46 46
54191 - 18 18 18 6 6 6 0 0 0 0 0 0
54192 - 0 0 0 0 0 0 0 0 0 0 0 0
54193 - 0 0 0 0 0 0 0 0 0 0 0 0
54194 - 0 0 0 0 0 0 0 0 0 0 0 0
54195 - 0 0 0 0 0 0 0 0 0 0 0 0
54196 - 0 0 0 0 0 0 0 0 0 0 0 0
54197 - 0 0 0 0 0 0 0 0 0 0 0 0
54198 - 0 0 0 0 0 0 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 10 10 10
54204 - 38 38 38 86 86 86 50 50 50 6 6 6
54205 -128 128 128 174 154 114 156 107 11 168 122 10
54206 -198 155 10 184 144 12 197 138 11 200 144 11
54207 -206 145 10 206 145 10 197 138 11 188 164 115
54208 -195 195 195 198 198 198 174 174 174 14 14 14
54209 - 2 2 6 22 22 22 116 116 116 116 116 116
54210 - 22 22 22 2 2 6 74 74 74 70 70 70
54211 - 30 30 30 10 10 10 0 0 0 0 0 0
54212 - 0 0 0 0 0 0 0 0 0 0 0 0
54213 - 0 0 0 0 0 0 0 0 0 0 0 0
54214 - 0 0 0 0 0 0 0 0 0 0 0 0
54215 - 0 0 0 0 0 0 0 0 0 0 0 0
54216 - 0 0 0 0 0 0 0 0 0 0 0 0
54217 - 0 0 0 0 0 0 0 0 0 0 0 0
54218 - 0 0 0 0 0 0 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 6 6 6 18 18 18
54224 - 50 50 50 101 101 101 26 26 26 10 10 10
54225 -138 138 138 190 190 190 174 154 114 156 107 11
54226 -197 138 11 200 144 11 197 138 11 192 133 9
54227 -180 123 7 190 142 34 190 178 144 187 187 187
54228 -202 202 202 221 221 221 214 214 214 66 66 66
54229 - 2 2 6 2 2 6 50 50 50 62 62 62
54230 - 6 6 6 2 2 6 10 10 10 90 90 90
54231 - 50 50 50 18 18 18 6 6 6 0 0 0
54232 - 0 0 0 0 0 0 0 0 0 0 0 0
54233 - 0 0 0 0 0 0 0 0 0 0 0 0
54234 - 0 0 0 0 0 0 0 0 0 0 0 0
54235 - 0 0 0 0 0 0 0 0 0 0 0 0
54236 - 0 0 0 0 0 0 0 0 0 0 0 0
54237 - 0 0 0 0 0 0 0 0 0 0 0 0
54238 - 0 0 0 0 0 0 0 0 0 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 10 10 10 34 34 34
54244 - 74 74 74 74 74 74 2 2 6 6 6 6
54245 -144 144 144 198 198 198 190 190 190 178 166 146
54246 -154 121 60 156 107 11 156 107 11 168 124 44
54247 -174 154 114 187 187 187 190 190 190 210 210 210
54248 -246 246 246 253 253 253 253 253 253 182 182 182
54249 - 6 6 6 2 2 6 2 2 6 2 2 6
54250 - 2 2 6 2 2 6 2 2 6 62 62 62
54251 - 74 74 74 34 34 34 14 14 14 0 0 0
54252 - 0 0 0 0 0 0 0 0 0 0 0 0
54253 - 0 0 0 0 0 0 0 0 0 0 0 0
54254 - 0 0 0 0 0 0 0 0 0 0 0 0
54255 - 0 0 0 0 0 0 0 0 0 0 0 0
54256 - 0 0 0 0 0 0 0 0 0 0 0 0
54257 - 0 0 0 0 0 0 0 0 0 0 0 0
54258 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10 22 22 22 54 54 54
54264 - 94 94 94 18 18 18 2 2 6 46 46 46
54265 -234 234 234 221 221 221 190 190 190 190 190 190
54266 -190 190 190 187 187 187 187 187 187 190 190 190
54267 -190 190 190 195 195 195 214 214 214 242 242 242
54268 -253 253 253 253 253 253 253 253 253 253 253 253
54269 - 82 82 82 2 2 6 2 2 6 2 2 6
54270 - 2 2 6 2 2 6 2 2 6 14 14 14
54271 - 86 86 86 54 54 54 22 22 22 6 6 6
54272 - 0 0 0 0 0 0 0 0 0 0 0 0
54273 - 0 0 0 0 0 0 0 0 0 0 0 0
54274 - 0 0 0 0 0 0 0 0 0 0 0 0
54275 - 0 0 0 0 0 0 0 0 0 0 0 0
54276 - 0 0 0 0 0 0 0 0 0 0 0 0
54277 - 0 0 0 0 0 0 0 0 0 0 0 0
54278 - 0 0 0 0 0 0 0 0 0 0 0 0
54279 - 0 0 0 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 - 6 6 6 18 18 18 46 46 46 90 90 90
54284 - 46 46 46 18 18 18 6 6 6 182 182 182
54285 -253 253 253 246 246 246 206 206 206 190 190 190
54286 -190 190 190 190 190 190 190 190 190 190 190 190
54287 -206 206 206 231 231 231 250 250 250 253 253 253
54288 -253 253 253 253 253 253 253 253 253 253 253 253
54289 -202 202 202 14 14 14 2 2 6 2 2 6
54290 - 2 2 6 2 2 6 2 2 6 2 2 6
54291 - 42 42 42 86 86 86 42 42 42 18 18 18
54292 - 6 6 6 0 0 0 0 0 0 0 0 0
54293 - 0 0 0 0 0 0 0 0 0 0 0 0
54294 - 0 0 0 0 0 0 0 0 0 0 0 0
54295 - 0 0 0 0 0 0 0 0 0 0 0 0
54296 - 0 0 0 0 0 0 0 0 0 0 0 0
54297 - 0 0 0 0 0 0 0 0 0 0 0 0
54298 - 0 0 0 0 0 0 0 0 0 0 0 0
54299 - 0 0 0 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 6 6 6
54303 - 14 14 14 38 38 38 74 74 74 66 66 66
54304 - 2 2 6 6 6 6 90 90 90 250 250 250
54305 -253 253 253 253 253 253 238 238 238 198 198 198
54306 -190 190 190 190 190 190 195 195 195 221 221 221
54307 -246 246 246 253 253 253 253 253 253 253 253 253
54308 -253 253 253 253 253 253 253 253 253 253 253 253
54309 -253 253 253 82 82 82 2 2 6 2 2 6
54310 - 2 2 6 2 2 6 2 2 6 2 2 6
54311 - 2 2 6 78 78 78 70 70 70 34 34 34
54312 - 14 14 14 6 6 6 0 0 0 0 0 0
54313 - 0 0 0 0 0 0 0 0 0 0 0 0
54314 - 0 0 0 0 0 0 0 0 0 0 0 0
54315 - 0 0 0 0 0 0 0 0 0 0 0 0
54316 - 0 0 0 0 0 0 0 0 0 0 0 0
54317 - 0 0 0 0 0 0 0 0 0 0 0 0
54318 - 0 0 0 0 0 0 0 0 0 0 0 0
54319 - 0 0 0 0 0 0 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 14 14 14
54323 - 34 34 34 66 66 66 78 78 78 6 6 6
54324 - 2 2 6 18 18 18 218 218 218 253 253 253
54325 -253 253 253 253 253 253 253 253 253 246 246 246
54326 -226 226 226 231 231 231 246 246 246 253 253 253
54327 -253 253 253 253 253 253 253 253 253 253 253 253
54328 -253 253 253 253 253 253 253 253 253 253 253 253
54329 -253 253 253 178 178 178 2 2 6 2 2 6
54330 - 2 2 6 2 2 6 2 2 6 2 2 6
54331 - 2 2 6 18 18 18 90 90 90 62 62 62
54332 - 30 30 30 10 10 10 0 0 0 0 0 0
54333 - 0 0 0 0 0 0 0 0 0 0 0 0
54334 - 0 0 0 0 0 0 0 0 0 0 0 0
54335 - 0 0 0 0 0 0 0 0 0 0 0 0
54336 - 0 0 0 0 0 0 0 0 0 0 0 0
54337 - 0 0 0 0 0 0 0 0 0 0 0 0
54338 - 0 0 0 0 0 0 0 0 0 0 0 0
54339 - 0 0 0 0 0 0 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 10 10 10 26 26 26
54343 - 58 58 58 90 90 90 18 18 18 2 2 6
54344 - 2 2 6 110 110 110 253 253 253 253 253 253
54345 -253 253 253 253 253 253 253 253 253 253 253 253
54346 -250 250 250 253 253 253 253 253 253 253 253 253
54347 -253 253 253 253 253 253 253 253 253 253 253 253
54348 -253 253 253 253 253 253 253 253 253 253 253 253
54349 -253 253 253 231 231 231 18 18 18 2 2 6
54350 - 2 2 6 2 2 6 2 2 6 2 2 6
54351 - 2 2 6 2 2 6 18 18 18 94 94 94
54352 - 54 54 54 26 26 26 10 10 10 0 0 0
54353 - 0 0 0 0 0 0 0 0 0 0 0 0
54354 - 0 0 0 0 0 0 0 0 0 0 0 0
54355 - 0 0 0 0 0 0 0 0 0 0 0 0
54356 - 0 0 0 0 0 0 0 0 0 0 0 0
54357 - 0 0 0 0 0 0 0 0 0 0 0 0
54358 - 0 0 0 0 0 0 0 0 0 0 0 0
54359 - 0 0 0 0 0 0 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 6 6 6 22 22 22 50 50 50
54363 - 90 90 90 26 26 26 2 2 6 2 2 6
54364 - 14 14 14 195 195 195 250 250 250 253 253 253
54365 -253 253 253 253 253 253 253 253 253 253 253 253
54366 -253 253 253 253 253 253 253 253 253 253 253 253
54367 -253 253 253 253 253 253 253 253 253 253 253 253
54368 -253 253 253 253 253 253 253 253 253 253 253 253
54369 -250 250 250 242 242 242 54 54 54 2 2 6
54370 - 2 2 6 2 2 6 2 2 6 2 2 6
54371 - 2 2 6 2 2 6 2 2 6 38 38 38
54372 - 86 86 86 50 50 50 22 22 22 6 6 6
54373 - 0 0 0 0 0 0 0 0 0 0 0 0
54374 - 0 0 0 0 0 0 0 0 0 0 0 0
54375 - 0 0 0 0 0 0 0 0 0 0 0 0
54376 - 0 0 0 0 0 0 0 0 0 0 0 0
54377 - 0 0 0 0 0 0 0 0 0 0 0 0
54378 - 0 0 0 0 0 0 0 0 0 0 0 0
54379 - 0 0 0 0 0 0 0 0 0 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 - 6 6 6 14 14 14 38 38 38 82 82 82
54383 - 34 34 34 2 2 6 2 2 6 2 2 6
54384 - 42 42 42 195 195 195 246 246 246 253 253 253
54385 -253 253 253 253 253 253 253 253 253 250 250 250
54386 -242 242 242 242 242 242 250 250 250 253 253 253
54387 -253 253 253 253 253 253 253 253 253 253 253 253
54388 -253 253 253 250 250 250 246 246 246 238 238 238
54389 -226 226 226 231 231 231 101 101 101 6 6 6
54390 - 2 2 6 2 2 6 2 2 6 2 2 6
54391 - 2 2 6 2 2 6 2 2 6 2 2 6
54392 - 38 38 38 82 82 82 42 42 42 14 14 14
54393 - 6 6 6 0 0 0 0 0 0 0 0 0
54394 - 0 0 0 0 0 0 0 0 0 0 0 0
54395 - 0 0 0 0 0 0 0 0 0 0 0 0
54396 - 0 0 0 0 0 0 0 0 0 0 0 0
54397 - 0 0 0 0 0 0 0 0 0 0 0 0
54398 - 0 0 0 0 0 0 0 0 0 0 0 0
54399 - 0 0 0 0 0 0 0 0 0 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 - 10 10 10 26 26 26 62 62 62 66 66 66
54403 - 2 2 6 2 2 6 2 2 6 6 6 6
54404 - 70 70 70 170 170 170 206 206 206 234 234 234
54405 -246 246 246 250 250 250 250 250 250 238 238 238
54406 -226 226 226 231 231 231 238 238 238 250 250 250
54407 -250 250 250 250 250 250 246 246 246 231 231 231
54408 -214 214 214 206 206 206 202 202 202 202 202 202
54409 -198 198 198 202 202 202 182 182 182 18 18 18
54410 - 2 2 6 2 2 6 2 2 6 2 2 6
54411 - 2 2 6 2 2 6 2 2 6 2 2 6
54412 - 2 2 6 62 62 62 66 66 66 30 30 30
54413 - 10 10 10 0 0 0 0 0 0 0 0 0
54414 - 0 0 0 0 0 0 0 0 0 0 0 0
54415 - 0 0 0 0 0 0 0 0 0 0 0 0
54416 - 0 0 0 0 0 0 0 0 0 0 0 0
54417 - 0 0 0 0 0 0 0 0 0 0 0 0
54418 - 0 0 0 0 0 0 0 0 0 0 0 0
54419 - 0 0 0 0 0 0 0 0 0 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 - 14 14 14 42 42 42 82 82 82 18 18 18
54423 - 2 2 6 2 2 6 2 2 6 10 10 10
54424 - 94 94 94 182 182 182 218 218 218 242 242 242
54425 -250 250 250 253 253 253 253 253 253 250 250 250
54426 -234 234 234 253 253 253 253 253 253 253 253 253
54427 -253 253 253 253 253 253 253 253 253 246 246 246
54428 -238 238 238 226 226 226 210 210 210 202 202 202
54429 -195 195 195 195 195 195 210 210 210 158 158 158
54430 - 6 6 6 14 14 14 50 50 50 14 14 14
54431 - 2 2 6 2 2 6 2 2 6 2 2 6
54432 - 2 2 6 6 6 6 86 86 86 46 46 46
54433 - 18 18 18 6 6 6 0 0 0 0 0 0
54434 - 0 0 0 0 0 0 0 0 0 0 0 0
54435 - 0 0 0 0 0 0 0 0 0 0 0 0
54436 - 0 0 0 0 0 0 0 0 0 0 0 0
54437 - 0 0 0 0 0 0 0 0 0 0 0 0
54438 - 0 0 0 0 0 0 0 0 0 0 0 0
54439 - 0 0 0 0 0 0 0 0 0 0 0 0
54440 - 0 0 0 0 0 0 0 0 0 0 0 0
54441 - 0 0 0 0 0 0 0 0 0 6 6 6
54442 - 22 22 22 54 54 54 70 70 70 2 2 6
54443 - 2 2 6 10 10 10 2 2 6 22 22 22
54444 -166 166 166 231 231 231 250 250 250 253 253 253
54445 -253 253 253 253 253 253 253 253 253 250 250 250
54446 -242 242 242 253 253 253 253 253 253 253 253 253
54447 -253 253 253 253 253 253 253 253 253 253 253 253
54448 -253 253 253 253 253 253 253 253 253 246 246 246
54449 -231 231 231 206 206 206 198 198 198 226 226 226
54450 - 94 94 94 2 2 6 6 6 6 38 38 38
54451 - 30 30 30 2 2 6 2 2 6 2 2 6
54452 - 2 2 6 2 2 6 62 62 62 66 66 66
54453 - 26 26 26 10 10 10 0 0 0 0 0 0
54454 - 0 0 0 0 0 0 0 0 0 0 0 0
54455 - 0 0 0 0 0 0 0 0 0 0 0 0
54456 - 0 0 0 0 0 0 0 0 0 0 0 0
54457 - 0 0 0 0 0 0 0 0 0 0 0 0
54458 - 0 0 0 0 0 0 0 0 0 0 0 0
54459 - 0 0 0 0 0 0 0 0 0 0 0 0
54460 - 0 0 0 0 0 0 0 0 0 0 0 0
54461 - 0 0 0 0 0 0 0 0 0 10 10 10
54462 - 30 30 30 74 74 74 50 50 50 2 2 6
54463 - 26 26 26 26 26 26 2 2 6 106 106 106
54464 -238 238 238 253 253 253 253 253 253 253 253 253
54465 -253 253 253 253 253 253 253 253 253 253 253 253
54466 -253 253 253 253 253 253 253 253 253 253 253 253
54467 -253 253 253 253 253 253 253 253 253 253 253 253
54468 -253 253 253 253 253 253 253 253 253 253 253 253
54469 -253 253 253 246 246 246 218 218 218 202 202 202
54470 -210 210 210 14 14 14 2 2 6 2 2 6
54471 - 30 30 30 22 22 22 2 2 6 2 2 6
54472 - 2 2 6 2 2 6 18 18 18 86 86 86
54473 - 42 42 42 14 14 14 0 0 0 0 0 0
54474 - 0 0 0 0 0 0 0 0 0 0 0 0
54475 - 0 0 0 0 0 0 0 0 0 0 0 0
54476 - 0 0 0 0 0 0 0 0 0 0 0 0
54477 - 0 0 0 0 0 0 0 0 0 0 0 0
54478 - 0 0 0 0 0 0 0 0 0 0 0 0
54479 - 0 0 0 0 0 0 0 0 0 0 0 0
54480 - 0 0 0 0 0 0 0 0 0 0 0 0
54481 - 0 0 0 0 0 0 0 0 0 14 14 14
54482 - 42 42 42 90 90 90 22 22 22 2 2 6
54483 - 42 42 42 2 2 6 18 18 18 218 218 218
54484 -253 253 253 253 253 253 253 253 253 253 253 253
54485 -253 253 253 253 253 253 253 253 253 253 253 253
54486 -253 253 253 253 253 253 253 253 253 253 253 253
54487 -253 253 253 253 253 253 253 253 253 253 253 253
54488 -253 253 253 253 253 253 253 253 253 253 253 253
54489 -253 253 253 253 253 253 250 250 250 221 221 221
54490 -218 218 218 101 101 101 2 2 6 14 14 14
54491 - 18 18 18 38 38 38 10 10 10 2 2 6
54492 - 2 2 6 2 2 6 2 2 6 78 78 78
54493 - 58 58 58 22 22 22 6 6 6 0 0 0
54494 - 0 0 0 0 0 0 0 0 0 0 0 0
54495 - 0 0 0 0 0 0 0 0 0 0 0 0
54496 - 0 0 0 0 0 0 0 0 0 0 0 0
54497 - 0 0 0 0 0 0 0 0 0 0 0 0
54498 - 0 0 0 0 0 0 0 0 0 0 0 0
54499 - 0 0 0 0 0 0 0 0 0 0 0 0
54500 - 0 0 0 0 0 0 0 0 0 0 0 0
54501 - 0 0 0 0 0 0 6 6 6 18 18 18
54502 - 54 54 54 82 82 82 2 2 6 26 26 26
54503 - 22 22 22 2 2 6 123 123 123 253 253 253
54504 -253 253 253 253 253 253 253 253 253 253 253 253
54505 -253 253 253 253 253 253 253 253 253 253 253 253
54506 -253 253 253 253 253 253 253 253 253 253 253 253
54507 -253 253 253 253 253 253 253 253 253 253 253 253
54508 -253 253 253 253 253 253 253 253 253 253 253 253
54509 -253 253 253 253 253 253 253 253 253 250 250 250
54510 -238 238 238 198 198 198 6 6 6 38 38 38
54511 - 58 58 58 26 26 26 38 38 38 2 2 6
54512 - 2 2 6 2 2 6 2 2 6 46 46 46
54513 - 78 78 78 30 30 30 10 10 10 0 0 0
54514 - 0 0 0 0 0 0 0 0 0 0 0 0
54515 - 0 0 0 0 0 0 0 0 0 0 0 0
54516 - 0 0 0 0 0 0 0 0 0 0 0 0
54517 - 0 0 0 0 0 0 0 0 0 0 0 0
54518 - 0 0 0 0 0 0 0 0 0 0 0 0
54519 - 0 0 0 0 0 0 0 0 0 0 0 0
54520 - 0 0 0 0 0 0 0 0 0 0 0 0
54521 - 0 0 0 0 0 0 10 10 10 30 30 30
54522 - 74 74 74 58 58 58 2 2 6 42 42 42
54523 - 2 2 6 22 22 22 231 231 231 253 253 253
54524 -253 253 253 253 253 253 253 253 253 253 253 253
54525 -253 253 253 253 253 253 253 253 253 250 250 250
54526 -253 253 253 253 253 253 253 253 253 253 253 253
54527 -253 253 253 253 253 253 253 253 253 253 253 253
54528 -253 253 253 253 253 253 253 253 253 253 253 253
54529 -253 253 253 253 253 253 253 253 253 253 253 253
54530 -253 253 253 246 246 246 46 46 46 38 38 38
54531 - 42 42 42 14 14 14 38 38 38 14 14 14
54532 - 2 2 6 2 2 6 2 2 6 6 6 6
54533 - 86 86 86 46 46 46 14 14 14 0 0 0
54534 - 0 0 0 0 0 0 0 0 0 0 0 0
54535 - 0 0 0 0 0 0 0 0 0 0 0 0
54536 - 0 0 0 0 0 0 0 0 0 0 0 0
54537 - 0 0 0 0 0 0 0 0 0 0 0 0
54538 - 0 0 0 0 0 0 0 0 0 0 0 0
54539 - 0 0 0 0 0 0 0 0 0 0 0 0
54540 - 0 0 0 0 0 0 0 0 0 0 0 0
54541 - 0 0 0 6 6 6 14 14 14 42 42 42
54542 - 90 90 90 18 18 18 18 18 18 26 26 26
54543 - 2 2 6 116 116 116 253 253 253 253 253 253
54544 -253 253 253 253 253 253 253 253 253 253 253 253
54545 -253 253 253 253 253 253 250 250 250 238 238 238
54546 -253 253 253 253 253 253 253 253 253 253 253 253
54547 -253 253 253 253 253 253 253 253 253 253 253 253
54548 -253 253 253 253 253 253 253 253 253 253 253 253
54549 -253 253 253 253 253 253 253 253 253 253 253 253
54550 -253 253 253 253 253 253 94 94 94 6 6 6
54551 - 2 2 6 2 2 6 10 10 10 34 34 34
54552 - 2 2 6 2 2 6 2 2 6 2 2 6
54553 - 74 74 74 58 58 58 22 22 22 6 6 6
54554 - 0 0 0 0 0 0 0 0 0 0 0 0
54555 - 0 0 0 0 0 0 0 0 0 0 0 0
54556 - 0 0 0 0 0 0 0 0 0 0 0 0
54557 - 0 0 0 0 0 0 0 0 0 0 0 0
54558 - 0 0 0 0 0 0 0 0 0 0 0 0
54559 - 0 0 0 0 0 0 0 0 0 0 0 0
54560 - 0 0 0 0 0 0 0 0 0 0 0 0
54561 - 0 0 0 10 10 10 26 26 26 66 66 66
54562 - 82 82 82 2 2 6 38 38 38 6 6 6
54563 - 14 14 14 210 210 210 253 253 253 253 253 253
54564 -253 253 253 253 253 253 253 253 253 253 253 253
54565 -253 253 253 253 253 253 246 246 246 242 242 242
54566 -253 253 253 253 253 253 253 253 253 253 253 253
54567 -253 253 253 253 253 253 253 253 253 253 253 253
54568 -253 253 253 253 253 253 253 253 253 253 253 253
54569 -253 253 253 253 253 253 253 253 253 253 253 253
54570 -253 253 253 253 253 253 144 144 144 2 2 6
54571 - 2 2 6 2 2 6 2 2 6 46 46 46
54572 - 2 2 6 2 2 6 2 2 6 2 2 6
54573 - 42 42 42 74 74 74 30 30 30 10 10 10
54574 - 0 0 0 0 0 0 0 0 0 0 0 0
54575 - 0 0 0 0 0 0 0 0 0 0 0 0
54576 - 0 0 0 0 0 0 0 0 0 0 0 0
54577 - 0 0 0 0 0 0 0 0 0 0 0 0
54578 - 0 0 0 0 0 0 0 0 0 0 0 0
54579 - 0 0 0 0 0 0 0 0 0 0 0 0
54580 - 0 0 0 0 0 0 0 0 0 0 0 0
54581 - 6 6 6 14 14 14 42 42 42 90 90 90
54582 - 26 26 26 6 6 6 42 42 42 2 2 6
54583 - 74 74 74 250 250 250 253 253 253 253 253 253
54584 -253 253 253 253 253 253 253 253 253 253 253 253
54585 -253 253 253 253 253 253 242 242 242 242 242 242
54586 -253 253 253 253 253 253 253 253 253 253 253 253
54587 -253 253 253 253 253 253 253 253 253 253 253 253
54588 -253 253 253 253 253 253 253 253 253 253 253 253
54589 -253 253 253 253 253 253 253 253 253 253 253 253
54590 -253 253 253 253 253 253 182 182 182 2 2 6
54591 - 2 2 6 2 2 6 2 2 6 46 46 46
54592 - 2 2 6 2 2 6 2 2 6 2 2 6
54593 - 10 10 10 86 86 86 38 38 38 10 10 10
54594 - 0 0 0 0 0 0 0 0 0 0 0 0
54595 - 0 0 0 0 0 0 0 0 0 0 0 0
54596 - 0 0 0 0 0 0 0 0 0 0 0 0
54597 - 0 0 0 0 0 0 0 0 0 0 0 0
54598 - 0 0 0 0 0 0 0 0 0 0 0 0
54599 - 0 0 0 0 0 0 0 0 0 0 0 0
54600 - 0 0 0 0 0 0 0 0 0 0 0 0
54601 - 10 10 10 26 26 26 66 66 66 82 82 82
54602 - 2 2 6 22 22 22 18 18 18 2 2 6
54603 -149 149 149 253 253 253 253 253 253 253 253 253
54604 -253 253 253 253 253 253 253 253 253 253 253 253
54605 -253 253 253 253 253 253 234 234 234 242 242 242
54606 -253 253 253 253 253 253 253 253 253 253 253 253
54607 -253 253 253 253 253 253 253 253 253 253 253 253
54608 -253 253 253 253 253 253 253 253 253 253 253 253
54609 -253 253 253 253 253 253 253 253 253 253 253 253
54610 -253 253 253 253 253 253 206 206 206 2 2 6
54611 - 2 2 6 2 2 6 2 2 6 38 38 38
54612 - 2 2 6 2 2 6 2 2 6 2 2 6
54613 - 6 6 6 86 86 86 46 46 46 14 14 14
54614 - 0 0 0 0 0 0 0 0 0 0 0 0
54615 - 0 0 0 0 0 0 0 0 0 0 0 0
54616 - 0 0 0 0 0 0 0 0 0 0 0 0
54617 - 0 0 0 0 0 0 0 0 0 0 0 0
54618 - 0 0 0 0 0 0 0 0 0 0 0 0
54619 - 0 0 0 0 0 0 0 0 0 0 0 0
54620 - 0 0 0 0 0 0 0 0 0 6 6 6
54621 - 18 18 18 46 46 46 86 86 86 18 18 18
54622 - 2 2 6 34 34 34 10 10 10 6 6 6
54623 -210 210 210 253 253 253 253 253 253 253 253 253
54624 -253 253 253 253 253 253 253 253 253 253 253 253
54625 -253 253 253 253 253 253 234 234 234 242 242 242
54626 -253 253 253 253 253 253 253 253 253 253 253 253
54627 -253 253 253 253 253 253 253 253 253 253 253 253
54628 -253 253 253 253 253 253 253 253 253 253 253 253
54629 -253 253 253 253 253 253 253 253 253 253 253 253
54630 -253 253 253 253 253 253 221 221 221 6 6 6
54631 - 2 2 6 2 2 6 6 6 6 30 30 30
54632 - 2 2 6 2 2 6 2 2 6 2 2 6
54633 - 2 2 6 82 82 82 54 54 54 18 18 18
54634 - 6 6 6 0 0 0 0 0 0 0 0 0
54635 - 0 0 0 0 0 0 0 0 0 0 0 0
54636 - 0 0 0 0 0 0 0 0 0 0 0 0
54637 - 0 0 0 0 0 0 0 0 0 0 0 0
54638 - 0 0 0 0 0 0 0 0 0 0 0 0
54639 - 0 0 0 0 0 0 0 0 0 0 0 0
54640 - 0 0 0 0 0 0 0 0 0 10 10 10
54641 - 26 26 26 66 66 66 62 62 62 2 2 6
54642 - 2 2 6 38 38 38 10 10 10 26 26 26
54643 -238 238 238 253 253 253 253 253 253 253 253 253
54644 -253 253 253 253 253 253 253 253 253 253 253 253
54645 -253 253 253 253 253 253 231 231 231 238 238 238
54646 -253 253 253 253 253 253 253 253 253 253 253 253
54647 -253 253 253 253 253 253 253 253 253 253 253 253
54648 -253 253 253 253 253 253 253 253 253 253 253 253
54649 -253 253 253 253 253 253 253 253 253 253 253 253
54650 -253 253 253 253 253 253 231 231 231 6 6 6
54651 - 2 2 6 2 2 6 10 10 10 30 30 30
54652 - 2 2 6 2 2 6 2 2 6 2 2 6
54653 - 2 2 6 66 66 66 58 58 58 22 22 22
54654 - 6 6 6 0 0 0 0 0 0 0 0 0
54655 - 0 0 0 0 0 0 0 0 0 0 0 0
54656 - 0 0 0 0 0 0 0 0 0 0 0 0
54657 - 0 0 0 0 0 0 0 0 0 0 0 0
54658 - 0 0 0 0 0 0 0 0 0 0 0 0
54659 - 0 0 0 0 0 0 0 0 0 0 0 0
54660 - 0 0 0 0 0 0 0 0 0 10 10 10
54661 - 38 38 38 78 78 78 6 6 6 2 2 6
54662 - 2 2 6 46 46 46 14 14 14 42 42 42
54663 -246 246 246 253 253 253 253 253 253 253 253 253
54664 -253 253 253 253 253 253 253 253 253 253 253 253
54665 -253 253 253 253 253 253 231 231 231 242 242 242
54666 -253 253 253 253 253 253 253 253 253 253 253 253
54667 -253 253 253 253 253 253 253 253 253 253 253 253
54668 -253 253 253 253 253 253 253 253 253 253 253 253
54669 -253 253 253 253 253 253 253 253 253 253 253 253
54670 -253 253 253 253 253 253 234 234 234 10 10 10
54671 - 2 2 6 2 2 6 22 22 22 14 14 14
54672 - 2 2 6 2 2 6 2 2 6 2 2 6
54673 - 2 2 6 66 66 66 62 62 62 22 22 22
54674 - 6 6 6 0 0 0 0 0 0 0 0 0
54675 - 0 0 0 0 0 0 0 0 0 0 0 0
54676 - 0 0 0 0 0 0 0 0 0 0 0 0
54677 - 0 0 0 0 0 0 0 0 0 0 0 0
54678 - 0 0 0 0 0 0 0 0 0 0 0 0
54679 - 0 0 0 0 0 0 0 0 0 0 0 0
54680 - 0 0 0 0 0 0 6 6 6 18 18 18
54681 - 50 50 50 74 74 74 2 2 6 2 2 6
54682 - 14 14 14 70 70 70 34 34 34 62 62 62
54683 -250 250 250 253 253 253 253 253 253 253 253 253
54684 -253 253 253 253 253 253 253 253 253 253 253 253
54685 -253 253 253 253 253 253 231 231 231 246 246 246
54686 -253 253 253 253 253 253 253 253 253 253 253 253
54687 -253 253 253 253 253 253 253 253 253 253 253 253
54688 -253 253 253 253 253 253 253 253 253 253 253 253
54689 -253 253 253 253 253 253 253 253 253 253 253 253
54690 -253 253 253 253 253 253 234 234 234 14 14 14
54691 - 2 2 6 2 2 6 30 30 30 2 2 6
54692 - 2 2 6 2 2 6 2 2 6 2 2 6
54693 - 2 2 6 66 66 66 62 62 62 22 22 22
54694 - 6 6 6 0 0 0 0 0 0 0 0 0
54695 - 0 0 0 0 0 0 0 0 0 0 0 0
54696 - 0 0 0 0 0 0 0 0 0 0 0 0
54697 - 0 0 0 0 0 0 0 0 0 0 0 0
54698 - 0 0 0 0 0 0 0 0 0 0 0 0
54699 - 0 0 0 0 0 0 0 0 0 0 0 0
54700 - 0 0 0 0 0 0 6 6 6 18 18 18
54701 - 54 54 54 62 62 62 2 2 6 2 2 6
54702 - 2 2 6 30 30 30 46 46 46 70 70 70
54703 -250 250 250 253 253 253 253 253 253 253 253 253
54704 -253 253 253 253 253 253 253 253 253 253 253 253
54705 -253 253 253 253 253 253 231 231 231 246 246 246
54706 -253 253 253 253 253 253 253 253 253 253 253 253
54707 -253 253 253 253 253 253 253 253 253 253 253 253
54708 -253 253 253 253 253 253 253 253 253 253 253 253
54709 -253 253 253 253 253 253 253 253 253 253 253 253
54710 -253 253 253 253 253 253 226 226 226 10 10 10
54711 - 2 2 6 6 6 6 30 30 30 2 2 6
54712 - 2 2 6 2 2 6 2 2 6 2 2 6
54713 - 2 2 6 66 66 66 58 58 58 22 22 22
54714 - 6 6 6 0 0 0 0 0 0 0 0 0
54715 - 0 0 0 0 0 0 0 0 0 0 0 0
54716 - 0 0 0 0 0 0 0 0 0 0 0 0
54717 - 0 0 0 0 0 0 0 0 0 0 0 0
54718 - 0 0 0 0 0 0 0 0 0 0 0 0
54719 - 0 0 0 0 0 0 0 0 0 0 0 0
54720 - 0 0 0 0 0 0 6 6 6 22 22 22
54721 - 58 58 58 62 62 62 2 2 6 2 2 6
54722 - 2 2 6 2 2 6 30 30 30 78 78 78
54723 -250 250 250 253 253 253 253 253 253 253 253 253
54724 -253 253 253 253 253 253 253 253 253 253 253 253
54725 -253 253 253 253 253 253 231 231 231 246 246 246
54726 -253 253 253 253 253 253 253 253 253 253 253 253
54727 -253 253 253 253 253 253 253 253 253 253 253 253
54728 -253 253 253 253 253 253 253 253 253 253 253 253
54729 -253 253 253 253 253 253 253 253 253 253 253 253
54730 -253 253 253 253 253 253 206 206 206 2 2 6
54731 - 22 22 22 34 34 34 18 14 6 22 22 22
54732 - 26 26 26 18 18 18 6 6 6 2 2 6
54733 - 2 2 6 82 82 82 54 54 54 18 18 18
54734 - 6 6 6 0 0 0 0 0 0 0 0 0
54735 - 0 0 0 0 0 0 0 0 0 0 0 0
54736 - 0 0 0 0 0 0 0 0 0 0 0 0
54737 - 0 0 0 0 0 0 0 0 0 0 0 0
54738 - 0 0 0 0 0 0 0 0 0 0 0 0
54739 - 0 0 0 0 0 0 0 0 0 0 0 0
54740 - 0 0 0 0 0 0 6 6 6 26 26 26
54741 - 62 62 62 106 106 106 74 54 14 185 133 11
54742 -210 162 10 121 92 8 6 6 6 62 62 62
54743 -238 238 238 253 253 253 253 253 253 253 253 253
54744 -253 253 253 253 253 253 253 253 253 253 253 253
54745 -253 253 253 253 253 253 231 231 231 246 246 246
54746 -253 253 253 253 253 253 253 253 253 253 253 253
54747 -253 253 253 253 253 253 253 253 253 253 253 253
54748 -253 253 253 253 253 253 253 253 253 253 253 253
54749 -253 253 253 253 253 253 253 253 253 253 253 253
54750 -253 253 253 253 253 253 158 158 158 18 18 18
54751 - 14 14 14 2 2 6 2 2 6 2 2 6
54752 - 6 6 6 18 18 18 66 66 66 38 38 38
54753 - 6 6 6 94 94 94 50 50 50 18 18 18
54754 - 6 6 6 0 0 0 0 0 0 0 0 0
54755 - 0 0 0 0 0 0 0 0 0 0 0 0
54756 - 0 0 0 0 0 0 0 0 0 0 0 0
54757 - 0 0 0 0 0 0 0 0 0 0 0 0
54758 - 0 0 0 0 0 0 0 0 0 0 0 0
54759 - 0 0 0 0 0 0 0 0 0 6 6 6
54760 - 10 10 10 10 10 10 18 18 18 38 38 38
54761 - 78 78 78 142 134 106 216 158 10 242 186 14
54762 -246 190 14 246 190 14 156 118 10 10 10 10
54763 - 90 90 90 238 238 238 253 253 253 253 253 253
54764 -253 253 253 253 253 253 253 253 253 253 253 253
54765 -253 253 253 253 253 253 231 231 231 250 250 250
54766 -253 253 253 253 253 253 253 253 253 253 253 253
54767 -253 253 253 253 253 253 253 253 253 253 253 253
54768 -253 253 253 253 253 253 253 253 253 253 253 253
54769 -253 253 253 253 253 253 253 253 253 246 230 190
54770 -238 204 91 238 204 91 181 142 44 37 26 9
54771 - 2 2 6 2 2 6 2 2 6 2 2 6
54772 - 2 2 6 2 2 6 38 38 38 46 46 46
54773 - 26 26 26 106 106 106 54 54 54 18 18 18
54774 - 6 6 6 0 0 0 0 0 0 0 0 0
54775 - 0 0 0 0 0 0 0 0 0 0 0 0
54776 - 0 0 0 0 0 0 0 0 0 0 0 0
54777 - 0 0 0 0 0 0 0 0 0 0 0 0
54778 - 0 0 0 0 0 0 0 0 0 0 0 0
54779 - 0 0 0 6 6 6 14 14 14 22 22 22
54780 - 30 30 30 38 38 38 50 50 50 70 70 70
54781 -106 106 106 190 142 34 226 170 11 242 186 14
54782 -246 190 14 246 190 14 246 190 14 154 114 10
54783 - 6 6 6 74 74 74 226 226 226 253 253 253
54784 -253 253 253 253 253 253 253 253 253 253 253 253
54785 -253 253 253 253 253 253 231 231 231 250 250 250
54786 -253 253 253 253 253 253 253 253 253 253 253 253
54787 -253 253 253 253 253 253 253 253 253 253 253 253
54788 -253 253 253 253 253 253 253 253 253 253 253 253
54789 -253 253 253 253 253 253 253 253 253 228 184 62
54790 -241 196 14 241 208 19 232 195 16 38 30 10
54791 - 2 2 6 2 2 6 2 2 6 2 2 6
54792 - 2 2 6 6 6 6 30 30 30 26 26 26
54793 -203 166 17 154 142 90 66 66 66 26 26 26
54794 - 6 6 6 0 0 0 0 0 0 0 0 0
54795 - 0 0 0 0 0 0 0 0 0 0 0 0
54796 - 0 0 0 0 0 0 0 0 0 0 0 0
54797 - 0 0 0 0 0 0 0 0 0 0 0 0
54798 - 0 0 0 0 0 0 0 0 0 0 0 0
54799 - 6 6 6 18 18 18 38 38 38 58 58 58
54800 - 78 78 78 86 86 86 101 101 101 123 123 123
54801 -175 146 61 210 150 10 234 174 13 246 186 14
54802 -246 190 14 246 190 14 246 190 14 238 190 10
54803 -102 78 10 2 2 6 46 46 46 198 198 198
54804 -253 253 253 253 253 253 253 253 253 253 253 253
54805 -253 253 253 253 253 253 234 234 234 242 242 242
54806 -253 253 253 253 253 253 253 253 253 253 253 253
54807 -253 253 253 253 253 253 253 253 253 253 253 253
54808 -253 253 253 253 253 253 253 253 253 253 253 253
54809 -253 253 253 253 253 253 253 253 253 224 178 62
54810 -242 186 14 241 196 14 210 166 10 22 18 6
54811 - 2 2 6 2 2 6 2 2 6 2 2 6
54812 - 2 2 6 2 2 6 6 6 6 121 92 8
54813 -238 202 15 232 195 16 82 82 82 34 34 34
54814 - 10 10 10 0 0 0 0 0 0 0 0 0
54815 - 0 0 0 0 0 0 0 0 0 0 0 0
54816 - 0 0 0 0 0 0 0 0 0 0 0 0
54817 - 0 0 0 0 0 0 0 0 0 0 0 0
54818 - 0 0 0 0 0 0 0 0 0 0 0 0
54819 - 14 14 14 38 38 38 70 70 70 154 122 46
54820 -190 142 34 200 144 11 197 138 11 197 138 11
54821 -213 154 11 226 170 11 242 186 14 246 190 14
54822 -246 190 14 246 190 14 246 190 14 246 190 14
54823 -225 175 15 46 32 6 2 2 6 22 22 22
54824 -158 158 158 250 250 250 253 253 253 253 253 253
54825 -253 253 253 253 253 253 253 253 253 253 253 253
54826 -253 253 253 253 253 253 253 253 253 253 253 253
54827 -253 253 253 253 253 253 253 253 253 253 253 253
54828 -253 253 253 253 253 253 253 253 253 253 253 253
54829 -253 253 253 250 250 250 242 242 242 224 178 62
54830 -239 182 13 236 186 11 213 154 11 46 32 6
54831 - 2 2 6 2 2 6 2 2 6 2 2 6
54832 - 2 2 6 2 2 6 61 42 6 225 175 15
54833 -238 190 10 236 186 11 112 100 78 42 42 42
54834 - 14 14 14 0 0 0 0 0 0 0 0 0
54835 - 0 0 0 0 0 0 0 0 0 0 0 0
54836 - 0 0 0 0 0 0 0 0 0 0 0 0
54837 - 0 0 0 0 0 0 0 0 0 0 0 0
54838 - 0 0 0 0 0 0 0 0 0 6 6 6
54839 - 22 22 22 54 54 54 154 122 46 213 154 11
54840 -226 170 11 230 174 11 226 170 11 226 170 11
54841 -236 178 12 242 186 14 246 190 14 246 190 14
54842 -246 190 14 246 190 14 246 190 14 246 190 14
54843 -241 196 14 184 144 12 10 10 10 2 2 6
54844 - 6 6 6 116 116 116 242 242 242 253 253 253
54845 -253 253 253 253 253 253 253 253 253 253 253 253
54846 -253 253 253 253 253 253 253 253 253 253 253 253
54847 -253 253 253 253 253 253 253 253 253 253 253 253
54848 -253 253 253 253 253 253 253 253 253 253 253 253
54849 -253 253 253 231 231 231 198 198 198 214 170 54
54850 -236 178 12 236 178 12 210 150 10 137 92 6
54851 - 18 14 6 2 2 6 2 2 6 2 2 6
54852 - 6 6 6 70 47 6 200 144 11 236 178 12
54853 -239 182 13 239 182 13 124 112 88 58 58 58
54854 - 22 22 22 6 6 6 0 0 0 0 0 0
54855 - 0 0 0 0 0 0 0 0 0 0 0 0
54856 - 0 0 0 0 0 0 0 0 0 0 0 0
54857 - 0 0 0 0 0 0 0 0 0 0 0 0
54858 - 0 0 0 0 0 0 0 0 0 10 10 10
54859 - 30 30 30 70 70 70 180 133 36 226 170 11
54860 -239 182 13 242 186 14 242 186 14 246 186 14
54861 -246 190 14 246 190 14 246 190 14 246 190 14
54862 -246 190 14 246 190 14 246 190 14 246 190 14
54863 -246 190 14 232 195 16 98 70 6 2 2 6
54864 - 2 2 6 2 2 6 66 66 66 221 221 221
54865 -253 253 253 253 253 253 253 253 253 253 253 253
54866 -253 253 253 253 253 253 253 253 253 253 253 253
54867 -253 253 253 253 253 253 253 253 253 253 253 253
54868 -253 253 253 253 253 253 253 253 253 253 253 253
54869 -253 253 253 206 206 206 198 198 198 214 166 58
54870 -230 174 11 230 174 11 216 158 10 192 133 9
54871 -163 110 8 116 81 8 102 78 10 116 81 8
54872 -167 114 7 197 138 11 226 170 11 239 182 13
54873 -242 186 14 242 186 14 162 146 94 78 78 78
54874 - 34 34 34 14 14 14 6 6 6 0 0 0
54875 - 0 0 0 0 0 0 0 0 0 0 0 0
54876 - 0 0 0 0 0 0 0 0 0 0 0 0
54877 - 0 0 0 0 0 0 0 0 0 0 0 0
54878 - 0 0 0 0 0 0 0 0 0 6 6 6
54879 - 30 30 30 78 78 78 190 142 34 226 170 11
54880 -239 182 13 246 190 14 246 190 14 246 190 14
54881 -246 190 14 246 190 14 246 190 14 246 190 14
54882 -246 190 14 246 190 14 246 190 14 246 190 14
54883 -246 190 14 241 196 14 203 166 17 22 18 6
54884 - 2 2 6 2 2 6 2 2 6 38 38 38
54885 -218 218 218 253 253 253 253 253 253 253 253 253
54886 -253 253 253 253 253 253 253 253 253 253 253 253
54887 -253 253 253 253 253 253 253 253 253 253 253 253
54888 -253 253 253 253 253 253 253 253 253 253 253 253
54889 -250 250 250 206 206 206 198 198 198 202 162 69
54890 -226 170 11 236 178 12 224 166 10 210 150 10
54891 -200 144 11 197 138 11 192 133 9 197 138 11
54892 -210 150 10 226 170 11 242 186 14 246 190 14
54893 -246 190 14 246 186 14 225 175 15 124 112 88
54894 - 62 62 62 30 30 30 14 14 14 6 6 6
54895 - 0 0 0 0 0 0 0 0 0 0 0 0
54896 - 0 0 0 0 0 0 0 0 0 0 0 0
54897 - 0 0 0 0 0 0 0 0 0 0 0 0
54898 - 0 0 0 0 0 0 0 0 0 10 10 10
54899 - 30 30 30 78 78 78 174 135 50 224 166 10
54900 -239 182 13 246 190 14 246 190 14 246 190 14
54901 -246 190 14 246 190 14 246 190 14 246 190 14
54902 -246 190 14 246 190 14 246 190 14 246 190 14
54903 -246 190 14 246 190 14 241 196 14 139 102 15
54904 - 2 2 6 2 2 6 2 2 6 2 2 6
54905 - 78 78 78 250 250 250 253 253 253 253 253 253
54906 -253 253 253 253 253 253 253 253 253 253 253 253
54907 -253 253 253 253 253 253 253 253 253 253 253 253
54908 -253 253 253 253 253 253 253 253 253 253 253 253
54909 -250 250 250 214 214 214 198 198 198 190 150 46
54910 -219 162 10 236 178 12 234 174 13 224 166 10
54911 -216 158 10 213 154 11 213 154 11 216 158 10
54912 -226 170 11 239 182 13 246 190 14 246 190 14
54913 -246 190 14 246 190 14 242 186 14 206 162 42
54914 -101 101 101 58 58 58 30 30 30 14 14 14
54915 - 6 6 6 0 0 0 0 0 0 0 0 0
54916 - 0 0 0 0 0 0 0 0 0 0 0 0
54917 - 0 0 0 0 0 0 0 0 0 0 0 0
54918 - 0 0 0 0 0 0 0 0 0 10 10 10
54919 - 30 30 30 74 74 74 174 135 50 216 158 10
54920 -236 178 12 246 190 14 246 190 14 246 190 14
54921 -246 190 14 246 190 14 246 190 14 246 190 14
54922 -246 190 14 246 190 14 246 190 14 246 190 14
54923 -246 190 14 246 190 14 241 196 14 226 184 13
54924 - 61 42 6 2 2 6 2 2 6 2 2 6
54925 - 22 22 22 238 238 238 253 253 253 253 253 253
54926 -253 253 253 253 253 253 253 253 253 253 253 253
54927 -253 253 253 253 253 253 253 253 253 253 253 253
54928 -253 253 253 253 253 253 253 253 253 253 253 253
54929 -253 253 253 226 226 226 187 187 187 180 133 36
54930 -216 158 10 236 178 12 239 182 13 236 178 12
54931 -230 174 11 226 170 11 226 170 11 230 174 11
54932 -236 178 12 242 186 14 246 190 14 246 190 14
54933 -246 190 14 246 190 14 246 186 14 239 182 13
54934 -206 162 42 106 106 106 66 66 66 34 34 34
54935 - 14 14 14 6 6 6 0 0 0 0 0 0
54936 - 0 0 0 0 0 0 0 0 0 0 0 0
54937 - 0 0 0 0 0 0 0 0 0 0 0 0
54938 - 0 0 0 0 0 0 0 0 0 6 6 6
54939 - 26 26 26 70 70 70 163 133 67 213 154 11
54940 -236 178 12 246 190 14 246 190 14 246 190 14
54941 -246 190 14 246 190 14 246 190 14 246 190 14
54942 -246 190 14 246 190 14 246 190 14 246 190 14
54943 -246 190 14 246 190 14 246 190 14 241 196 14
54944 -190 146 13 18 14 6 2 2 6 2 2 6
54945 - 46 46 46 246 246 246 253 253 253 253 253 253
54946 -253 253 253 253 253 253 253 253 253 253 253 253
54947 -253 253 253 253 253 253 253 253 253 253 253 253
54948 -253 253 253 253 253 253 253 253 253 253 253 253
54949 -253 253 253 221 221 221 86 86 86 156 107 11
54950 -216 158 10 236 178 12 242 186 14 246 186 14
54951 -242 186 14 239 182 13 239 182 13 242 186 14
54952 -242 186 14 246 186 14 246 190 14 246 190 14
54953 -246 190 14 246 190 14 246 190 14 246 190 14
54954 -242 186 14 225 175 15 142 122 72 66 66 66
54955 - 30 30 30 10 10 10 0 0 0 0 0 0
54956 - 0 0 0 0 0 0 0 0 0 0 0 0
54957 - 0 0 0 0 0 0 0 0 0 0 0 0
54958 - 0 0 0 0 0 0 0 0 0 6 6 6
54959 - 26 26 26 70 70 70 163 133 67 210 150 10
54960 -236 178 12 246 190 14 246 190 14 246 190 14
54961 -246 190 14 246 190 14 246 190 14 246 190 14
54962 -246 190 14 246 190 14 246 190 14 246 190 14
54963 -246 190 14 246 190 14 246 190 14 246 190 14
54964 -232 195 16 121 92 8 34 34 34 106 106 106
54965 -221 221 221 253 253 253 253 253 253 253 253 253
54966 -253 253 253 253 253 253 253 253 253 253 253 253
54967 -253 253 253 253 253 253 253 253 253 253 253 253
54968 -253 253 253 253 253 253 253 253 253 253 253 253
54969 -242 242 242 82 82 82 18 14 6 163 110 8
54970 -216 158 10 236 178 12 242 186 14 246 190 14
54971 -246 190 14 246 190 14 246 190 14 246 190 14
54972 -246 190 14 246 190 14 246 190 14 246 190 14
54973 -246 190 14 246 190 14 246 190 14 246 190 14
54974 -246 190 14 246 190 14 242 186 14 163 133 67
54975 - 46 46 46 18 18 18 6 6 6 0 0 0
54976 - 0 0 0 0 0 0 0 0 0 0 0 0
54977 - 0 0 0 0 0 0 0 0 0 0 0 0
54978 - 0 0 0 0 0 0 0 0 0 10 10 10
54979 - 30 30 30 78 78 78 163 133 67 210 150 10
54980 -236 178 12 246 186 14 246 190 14 246 190 14
54981 -246 190 14 246 190 14 246 190 14 246 190 14
54982 -246 190 14 246 190 14 246 190 14 246 190 14
54983 -246 190 14 246 190 14 246 190 14 246 190 14
54984 -241 196 14 215 174 15 190 178 144 253 253 253
54985 -253 253 253 253 253 253 253 253 253 253 253 253
54986 -253 253 253 253 253 253 253 253 253 253 253 253
54987 -253 253 253 253 253 253 253 253 253 253 253 253
54988 -253 253 253 253 253 253 253 253 253 218 218 218
54989 - 58 58 58 2 2 6 22 18 6 167 114 7
54990 -216 158 10 236 178 12 246 186 14 246 190 14
54991 -246 190 14 246 190 14 246 190 14 246 190 14
54992 -246 190 14 246 190 14 246 190 14 246 190 14
54993 -246 190 14 246 190 14 246 190 14 246 190 14
54994 -246 190 14 246 186 14 242 186 14 190 150 46
54995 - 54 54 54 22 22 22 6 6 6 0 0 0
54996 - 0 0 0 0 0 0 0 0 0 0 0 0
54997 - 0 0 0 0 0 0 0 0 0 0 0 0
54998 - 0 0 0 0 0 0 0 0 0 14 14 14
54999 - 38 38 38 86 86 86 180 133 36 213 154 11
55000 -236 178 12 246 186 14 246 190 14 246 190 14
55001 -246 190 14 246 190 14 246 190 14 246 190 14
55002 -246 190 14 246 190 14 246 190 14 246 190 14
55003 -246 190 14 246 190 14 246 190 14 246 190 14
55004 -246 190 14 232 195 16 190 146 13 214 214 214
55005 -253 253 253 253 253 253 253 253 253 253 253 253
55006 -253 253 253 253 253 253 253 253 253 253 253 253
55007 -253 253 253 253 253 253 253 253 253 253 253 253
55008 -253 253 253 250 250 250 170 170 170 26 26 26
55009 - 2 2 6 2 2 6 37 26 9 163 110 8
55010 -219 162 10 239 182 13 246 186 14 246 190 14
55011 -246 190 14 246 190 14 246 190 14 246 190 14
55012 -246 190 14 246 190 14 246 190 14 246 190 14
55013 -246 190 14 246 190 14 246 190 14 246 190 14
55014 -246 186 14 236 178 12 224 166 10 142 122 72
55015 - 46 46 46 18 18 18 6 6 6 0 0 0
55016 - 0 0 0 0 0 0 0 0 0 0 0 0
55017 - 0 0 0 0 0 0 0 0 0 0 0 0
55018 - 0 0 0 0 0 0 6 6 6 18 18 18
55019 - 50 50 50 109 106 95 192 133 9 224 166 10
55020 -242 186 14 246 190 14 246 190 14 246 190 14
55021 -246 190 14 246 190 14 246 190 14 246 190 14
55022 -246 190 14 246 190 14 246 190 14 246 190 14
55023 -246 190 14 246 190 14 246 190 14 246 190 14
55024 -242 186 14 226 184 13 210 162 10 142 110 46
55025 -226 226 226 253 253 253 253 253 253 253 253 253
55026 -253 253 253 253 253 253 253 253 253 253 253 253
55027 -253 253 253 253 253 253 253 253 253 253 253 253
55028 -198 198 198 66 66 66 2 2 6 2 2 6
55029 - 2 2 6 2 2 6 50 34 6 156 107 11
55030 -219 162 10 239 182 13 246 186 14 246 190 14
55031 -246 190 14 246 190 14 246 190 14 246 190 14
55032 -246 190 14 246 190 14 246 190 14 246 190 14
55033 -246 190 14 246 190 14 246 190 14 242 186 14
55034 -234 174 13 213 154 11 154 122 46 66 66 66
55035 - 30 30 30 10 10 10 0 0 0 0 0 0
55036 - 0 0 0 0 0 0 0 0 0 0 0 0
55037 - 0 0 0 0 0 0 0 0 0 0 0 0
55038 - 0 0 0 0 0 0 6 6 6 22 22 22
55039 - 58 58 58 154 121 60 206 145 10 234 174 13
55040 -242 186 14 246 186 14 246 190 14 246 190 14
55041 -246 190 14 246 190 14 246 190 14 246 190 14
55042 -246 190 14 246 190 14 246 190 14 246 190 14
55043 -246 190 14 246 190 14 246 190 14 246 190 14
55044 -246 186 14 236 178 12 210 162 10 163 110 8
55045 - 61 42 6 138 138 138 218 218 218 250 250 250
55046 -253 253 253 253 253 253 253 253 253 250 250 250
55047 -242 242 242 210 210 210 144 144 144 66 66 66
55048 - 6 6 6 2 2 6 2 2 6 2 2 6
55049 - 2 2 6 2 2 6 61 42 6 163 110 8
55050 -216 158 10 236 178 12 246 190 14 246 190 14
55051 -246 190 14 246 190 14 246 190 14 246 190 14
55052 -246 190 14 246 190 14 246 190 14 246 190 14
55053 -246 190 14 239 182 13 230 174 11 216 158 10
55054 -190 142 34 124 112 88 70 70 70 38 38 38
55055 - 18 18 18 6 6 6 0 0 0 0 0 0
55056 - 0 0 0 0 0 0 0 0 0 0 0 0
55057 - 0 0 0 0 0 0 0 0 0 0 0 0
55058 - 0 0 0 0 0 0 6 6 6 22 22 22
55059 - 62 62 62 168 124 44 206 145 10 224 166 10
55060 -236 178 12 239 182 13 242 186 14 242 186 14
55061 -246 186 14 246 190 14 246 190 14 246 190 14
55062 -246 190 14 246 190 14 246 190 14 246 190 14
55063 -246 190 14 246 190 14 246 190 14 246 190 14
55064 -246 190 14 236 178 12 216 158 10 175 118 6
55065 - 80 54 7 2 2 6 6 6 6 30 30 30
55066 - 54 54 54 62 62 62 50 50 50 38 38 38
55067 - 14 14 14 2 2 6 2 2 6 2 2 6
55068 - 2 2 6 2 2 6 2 2 6 2 2 6
55069 - 2 2 6 6 6 6 80 54 7 167 114 7
55070 -213 154 11 236 178 12 246 190 14 246 190 14
55071 -246 190 14 246 190 14 246 190 14 246 190 14
55072 -246 190 14 242 186 14 239 182 13 239 182 13
55073 -230 174 11 210 150 10 174 135 50 124 112 88
55074 - 82 82 82 54 54 54 34 34 34 18 18 18
55075 - 6 6 6 0 0 0 0 0 0 0 0 0
55076 - 0 0 0 0 0 0 0 0 0 0 0 0
55077 - 0 0 0 0 0 0 0 0 0 0 0 0
55078 - 0 0 0 0 0 0 6 6 6 18 18 18
55079 - 50 50 50 158 118 36 192 133 9 200 144 11
55080 -216 158 10 219 162 10 224 166 10 226 170 11
55081 -230 174 11 236 178 12 239 182 13 239 182 13
55082 -242 186 14 246 186 14 246 190 14 246 190 14
55083 -246 190 14 246 190 14 246 190 14 246 190 14
55084 -246 186 14 230 174 11 210 150 10 163 110 8
55085 -104 69 6 10 10 10 2 2 6 2 2 6
55086 - 2 2 6 2 2 6 2 2 6 2 2 6
55087 - 2 2 6 2 2 6 2 2 6 2 2 6
55088 - 2 2 6 2 2 6 2 2 6 2 2 6
55089 - 2 2 6 6 6 6 91 60 6 167 114 7
55090 -206 145 10 230 174 11 242 186 14 246 190 14
55091 -246 190 14 246 190 14 246 186 14 242 186 14
55092 -239 182 13 230 174 11 224 166 10 213 154 11
55093 -180 133 36 124 112 88 86 86 86 58 58 58
55094 - 38 38 38 22 22 22 10 10 10 6 6 6
55095 - 0 0 0 0 0 0 0 0 0 0 0 0
55096 - 0 0 0 0 0 0 0 0 0 0 0 0
55097 - 0 0 0 0 0 0 0 0 0 0 0 0
55098 - 0 0 0 0 0 0 0 0 0 14 14 14
55099 - 34 34 34 70 70 70 138 110 50 158 118 36
55100 -167 114 7 180 123 7 192 133 9 197 138 11
55101 -200 144 11 206 145 10 213 154 11 219 162 10
55102 -224 166 10 230 174 11 239 182 13 242 186 14
55103 -246 186 14 246 186 14 246 186 14 246 186 14
55104 -239 182 13 216 158 10 185 133 11 152 99 6
55105 -104 69 6 18 14 6 2 2 6 2 2 6
55106 - 2 2 6 2 2 6 2 2 6 2 2 6
55107 - 2 2 6 2 2 6 2 2 6 2 2 6
55108 - 2 2 6 2 2 6 2 2 6 2 2 6
55109 - 2 2 6 6 6 6 80 54 7 152 99 6
55110 -192 133 9 219 162 10 236 178 12 239 182 13
55111 -246 186 14 242 186 14 239 182 13 236 178 12
55112 -224 166 10 206 145 10 192 133 9 154 121 60
55113 - 94 94 94 62 62 62 42 42 42 22 22 22
55114 - 14 14 14 6 6 6 0 0 0 0 0 0
55115 - 0 0 0 0 0 0 0 0 0 0 0 0
55116 - 0 0 0 0 0 0 0 0 0 0 0 0
55117 - 0 0 0 0 0 0 0 0 0 0 0 0
55118 - 0 0 0 0 0 0 0 0 0 6 6 6
55119 - 18 18 18 34 34 34 58 58 58 78 78 78
55120 -101 98 89 124 112 88 142 110 46 156 107 11
55121 -163 110 8 167 114 7 175 118 6 180 123 7
55122 -185 133 11 197 138 11 210 150 10 219 162 10
55123 -226 170 11 236 178 12 236 178 12 234 174 13
55124 -219 162 10 197 138 11 163 110 8 130 83 6
55125 - 91 60 6 10 10 10 2 2 6 2 2 6
55126 - 18 18 18 38 38 38 38 38 38 38 38 38
55127 - 38 38 38 38 38 38 38 38 38 38 38 38
55128 - 38 38 38 38 38 38 26 26 26 2 2 6
55129 - 2 2 6 6 6 6 70 47 6 137 92 6
55130 -175 118 6 200 144 11 219 162 10 230 174 11
55131 -234 174 13 230 174 11 219 162 10 210 150 10
55132 -192 133 9 163 110 8 124 112 88 82 82 82
55133 - 50 50 50 30 30 30 14 14 14 6 6 6
55134 - 0 0 0 0 0 0 0 0 0 0 0 0
55135 - 0 0 0 0 0 0 0 0 0 0 0 0
55136 - 0 0 0 0 0 0 0 0 0 0 0 0
55137 - 0 0 0 0 0 0 0 0 0 0 0 0
55138 - 0 0 0 0 0 0 0 0 0 0 0 0
55139 - 6 6 6 14 14 14 22 22 22 34 34 34
55140 - 42 42 42 58 58 58 74 74 74 86 86 86
55141 -101 98 89 122 102 70 130 98 46 121 87 25
55142 -137 92 6 152 99 6 163 110 8 180 123 7
55143 -185 133 11 197 138 11 206 145 10 200 144 11
55144 -180 123 7 156 107 11 130 83 6 104 69 6
55145 - 50 34 6 54 54 54 110 110 110 101 98 89
55146 - 86 86 86 82 82 82 78 78 78 78 78 78
55147 - 78 78 78 78 78 78 78 78 78 78 78 78
55148 - 78 78 78 82 82 82 86 86 86 94 94 94
55149 -106 106 106 101 101 101 86 66 34 124 80 6
55150 -156 107 11 180 123 7 192 133 9 200 144 11
55151 -206 145 10 200 144 11 192 133 9 175 118 6
55152 -139 102 15 109 106 95 70 70 70 42 42 42
55153 - 22 22 22 10 10 10 0 0 0 0 0 0
55154 - 0 0 0 0 0 0 0 0 0 0 0 0
55155 - 0 0 0 0 0 0 0 0 0 0 0 0
55156 - 0 0 0 0 0 0 0 0 0 0 0 0
55157 - 0 0 0 0 0 0 0 0 0 0 0 0
55158 - 0 0 0 0 0 0 0 0 0 0 0 0
55159 - 0 0 0 0 0 0 6 6 6 10 10 10
55160 - 14 14 14 22 22 22 30 30 30 38 38 38
55161 - 50 50 50 62 62 62 74 74 74 90 90 90
55162 -101 98 89 112 100 78 121 87 25 124 80 6
55163 -137 92 6 152 99 6 152 99 6 152 99 6
55164 -138 86 6 124 80 6 98 70 6 86 66 30
55165 -101 98 89 82 82 82 58 58 58 46 46 46
55166 - 38 38 38 34 34 34 34 34 34 34 34 34
55167 - 34 34 34 34 34 34 34 34 34 34 34 34
55168 - 34 34 34 34 34 34 38 38 38 42 42 42
55169 - 54 54 54 82 82 82 94 86 76 91 60 6
55170 -134 86 6 156 107 11 167 114 7 175 118 6
55171 -175 118 6 167 114 7 152 99 6 121 87 25
55172 -101 98 89 62 62 62 34 34 34 18 18 18
55173 - 6 6 6 0 0 0 0 0 0 0 0 0
55174 - 0 0 0 0 0 0 0 0 0 0 0 0
55175 - 0 0 0 0 0 0 0 0 0 0 0 0
55176 - 0 0 0 0 0 0 0 0 0 0 0 0
55177 - 0 0 0 0 0 0 0 0 0 0 0 0
55178 - 0 0 0 0 0 0 0 0 0 0 0 0
55179 - 0 0 0 0 0 0 0 0 0 0 0 0
55180 - 0 0 0 6 6 6 6 6 6 10 10 10
55181 - 18 18 18 22 22 22 30 30 30 42 42 42
55182 - 50 50 50 66 66 66 86 86 86 101 98 89
55183 -106 86 58 98 70 6 104 69 6 104 69 6
55184 -104 69 6 91 60 6 82 62 34 90 90 90
55185 - 62 62 62 38 38 38 22 22 22 14 14 14
55186 - 10 10 10 10 10 10 10 10 10 10 10 10
55187 - 10 10 10 10 10 10 6 6 6 10 10 10
55188 - 10 10 10 10 10 10 10 10 10 14 14 14
55189 - 22 22 22 42 42 42 70 70 70 89 81 66
55190 - 80 54 7 104 69 6 124 80 6 137 92 6
55191 -134 86 6 116 81 8 100 82 52 86 86 86
55192 - 58 58 58 30 30 30 14 14 14 6 6 6
55193 - 0 0 0 0 0 0 0 0 0 0 0 0
55194 - 0 0 0 0 0 0 0 0 0 0 0 0
55195 - 0 0 0 0 0 0 0 0 0 0 0 0
55196 - 0 0 0 0 0 0 0 0 0 0 0 0
55197 - 0 0 0 0 0 0 0 0 0 0 0 0
55198 - 0 0 0 0 0 0 0 0 0 0 0 0
55199 - 0 0 0 0 0 0 0 0 0 0 0 0
55200 - 0 0 0 0 0 0 0 0 0 0 0 0
55201 - 0 0 0 6 6 6 10 10 10 14 14 14
55202 - 18 18 18 26 26 26 38 38 38 54 54 54
55203 - 70 70 70 86 86 86 94 86 76 89 81 66
55204 - 89 81 66 86 86 86 74 74 74 50 50 50
55205 - 30 30 30 14 14 14 6 6 6 0 0 0
55206 - 0 0 0 0 0 0 0 0 0 0 0 0
55207 - 0 0 0 0 0 0 0 0 0 0 0 0
55208 - 0 0 0 0 0 0 0 0 0 0 0 0
55209 - 6 6 6 18 18 18 34 34 34 58 58 58
55210 - 82 82 82 89 81 66 89 81 66 89 81 66
55211 - 94 86 66 94 86 76 74 74 74 50 50 50
55212 - 26 26 26 14 14 14 6 6 6 0 0 0
55213 - 0 0 0 0 0 0 0 0 0 0 0 0
55214 - 0 0 0 0 0 0 0 0 0 0 0 0
55215 - 0 0 0 0 0 0 0 0 0 0 0 0
55216 - 0 0 0 0 0 0 0 0 0 0 0 0
55217 - 0 0 0 0 0 0 0 0 0 0 0 0
55218 - 0 0 0 0 0 0 0 0 0 0 0 0
55219 - 0 0 0 0 0 0 0 0 0 0 0 0
55220 - 0 0 0 0 0 0 0 0 0 0 0 0
55221 - 0 0 0 0 0 0 0 0 0 0 0 0
55222 - 6 6 6 6 6 6 14 14 14 18 18 18
55223 - 30 30 30 38 38 38 46 46 46 54 54 54
55224 - 50 50 50 42 42 42 30 30 30 18 18 18
55225 - 10 10 10 0 0 0 0 0 0 0 0 0
55226 - 0 0 0 0 0 0 0 0 0 0 0 0
55227 - 0 0 0 0 0 0 0 0 0 0 0 0
55228 - 0 0 0 0 0 0 0 0 0 0 0 0
55229 - 0 0 0 6 6 6 14 14 14 26 26 26
55230 - 38 38 38 50 50 50 58 58 58 58 58 58
55231 - 54 54 54 42 42 42 30 30 30 18 18 18
55232 - 10 10 10 0 0 0 0 0 0 0 0 0
55233 - 0 0 0 0 0 0 0 0 0 0 0 0
55234 - 0 0 0 0 0 0 0 0 0 0 0 0
55235 - 0 0 0 0 0 0 0 0 0 0 0 0
55236 - 0 0 0 0 0 0 0 0 0 0 0 0
55237 - 0 0 0 0 0 0 0 0 0 0 0 0
55238 - 0 0 0 0 0 0 0 0 0 0 0 0
55239 - 0 0 0 0 0 0 0 0 0 0 0 0
55240 - 0 0 0 0 0 0 0 0 0 0 0 0
55241 - 0 0 0 0 0 0 0 0 0 0 0 0
55242 - 0 0 0 0 0 0 0 0 0 6 6 6
55243 - 6 6 6 10 10 10 14 14 14 18 18 18
55244 - 18 18 18 14 14 14 10 10 10 6 6 6
55245 - 0 0 0 0 0 0 0 0 0 0 0 0
55246 - 0 0 0 0 0 0 0 0 0 0 0 0
55247 - 0 0 0 0 0 0 0 0 0 0 0 0
55248 - 0 0 0 0 0 0 0 0 0 0 0 0
55249 - 0 0 0 0 0 0 0 0 0 6 6 6
55250 - 14 14 14 18 18 18 22 22 22 22 22 22
55251 - 18 18 18 14 14 14 10 10 10 6 6 6
55252 - 0 0 0 0 0 0 0 0 0 0 0 0
55253 - 0 0 0 0 0 0 0 0 0 0 0 0
55254 - 0 0 0 0 0 0 0 0 0 0 0 0
55255 - 0 0 0 0 0 0 0 0 0 0 0 0
55256 - 0 0 0 0 0 0 0 0 0 0 0 0
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 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55260 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55261 +4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
55265 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55266 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55267 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55268 +4 4 4 4 4 4 4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
55273 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55274 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55275 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
55278 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55279 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55280 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55281 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55282 +4 4 4 4 4 4 4 4 4 4 4 4 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
55285 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55286 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55287 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55288 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55289 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55290 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55291 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55292 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55293 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55294 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55295 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55296 +4 4 4 4 4 4 4 4 4 4 4 4 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
55299 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55300 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55301 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55302 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55303 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55304 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55305 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55306 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55307 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55308 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55309 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55310 +4 4 4 4 4 4 4 4 4 4 4 4 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
55313 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55314 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55315 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55316 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55317 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55318 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55319 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55320 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55321 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55322 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55323 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55324 +4 4 4 4 4 4 4 4 4 4 4 4 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
55327 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55328 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55329 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55330 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55331 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55332 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55333 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55334 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55335 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55336 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55337 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55338 +4 4 4 4 4 4 4 4 4 4 4 4 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
55341 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55342 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55343 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55344 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55345 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
55346 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
55347 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55348 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55349 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55350 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
55351 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
55352 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
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
55355 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55356 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55357 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55358 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55359 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
55360 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
55361 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55362 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55363 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55364 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
55365 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
55366 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
55367 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55368 +4 4 4 4 4 4
55369 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55370 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55371 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55372 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55373 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
55374 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
55375 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
55376 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55377 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55378 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
55379 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
55380 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
55381 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
55382 +4 4 4 4 4 4
55383 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55384 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55385 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55386 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
55387 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
55388 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
55389 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
55390 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55391 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
55392 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
55393 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
55394 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
55395 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
55396 +4 4 4 4 4 4
55397 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55398 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55399 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55400 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
55401 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
55402 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
55403 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
55404 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55405 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
55406 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
55407 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
55408 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
55409 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
55410 +4 4 4 4 4 4
55411 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55412 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55413 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55414 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
55415 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
55416 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
55417 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
55418 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
55419 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
55420 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
55421 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
55422 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
55423 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
55424 +4 4 4 4 4 4
55425 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55426 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55427 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
55428 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
55429 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
55430 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
55431 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
55432 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
55433 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
55434 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
55435 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
55436 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
55437 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
55438 +4 4 4 4 4 4
55439 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55440 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55441 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
55442 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
55443 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
55444 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
55445 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
55446 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
55447 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
55448 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
55449 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
55450 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
55451 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
55452 +4 4 4 4 4 4
55453 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55454 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55455 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
55456 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
55457 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
55458 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
55459 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
55460 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
55461 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
55462 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
55463 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
55464 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
55465 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
55466 +4 4 4 4 4 4
55467 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55468 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55469 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
55470 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
55471 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
55472 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
55473 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
55474 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
55475 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
55476 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
55477 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
55478 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
55479 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
55480 +4 4 4 4 4 4
55481 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55482 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
55483 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
55484 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
55485 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
55486 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
55487 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
55488 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
55489 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
55490 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
55491 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
55492 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
55493 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
55494 +4 4 4 4 4 4
55495 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55496 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
55497 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
55498 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
55499 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
55500 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
55501 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
55502 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
55503 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
55504 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
55505 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
55506 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
55507 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
55508 +0 0 0 4 4 4
55509 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
55510 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
55511 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
55512 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
55513 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
55514 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
55515 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
55516 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
55517 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
55518 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
55519 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
55520 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
55521 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
55522 +2 0 0 0 0 0
55523 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
55524 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
55525 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
55526 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
55527 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
55528 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
55529 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
55530 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
55531 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
55532 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
55533 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
55534 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
55535 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
55536 +37 38 37 0 0 0
55537 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
55538 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
55539 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
55540 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
55541 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
55542 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
55543 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
55544 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
55545 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
55546 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
55547 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
55548 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
55549 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
55550 +85 115 134 4 0 0
55551 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
55552 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
55553 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
55554 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
55555 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
55556 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
55557 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
55558 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
55559 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
55560 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
55561 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
55562 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
55563 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
55564 +60 73 81 4 0 0
55565 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
55566 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
55567 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
55568 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
55569 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
55570 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
55571 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
55572 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
55573 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
55574 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
55575 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
55576 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
55577 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
55578 +16 19 21 4 0 0
55579 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
55580 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
55581 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
55582 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
55583 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
55584 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
55585 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
55586 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
55587 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
55588 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
55589 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
55590 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
55591 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
55592 +4 0 0 4 3 3
55593 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
55594 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
55595 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
55596 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
55597 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
55598 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
55599 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
55600 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
55601 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
55602 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
55603 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
55604 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
55605 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
55606 +3 2 2 4 4 4
55607 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
55608 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
55609 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
55610 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
55611 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
55612 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
55613 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
55614 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
55615 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
55616 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
55617 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
55618 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
55619 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
55620 +4 4 4 4 4 4
55621 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
55622 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
55623 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
55624 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
55625 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
55626 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
55627 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
55628 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
55629 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
55630 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
55631 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
55632 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
55633 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
55634 +4 4 4 4 4 4
55635 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
55636 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
55637 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
55638 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
55639 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
55640 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
55641 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
55642 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
55643 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
55644 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
55645 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
55646 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
55647 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
55648 +5 5 5 5 5 5
55649 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
55650 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
55651 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
55652 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
55653 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
55654 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55655 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
55656 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
55657 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
55658 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
55659 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
55660 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
55661 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
55662 +5 5 5 4 4 4
55663 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
55664 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
55665 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
55666 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
55667 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55668 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
55669 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
55670 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
55671 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
55672 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
55673 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
55674 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
55675 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55676 +4 4 4 4 4 4
55677 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
55678 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
55679 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
55680 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
55681 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
55682 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55683 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55684 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
55685 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
55686 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
55687 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
55688 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
55689 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55690 +4 4 4 4 4 4
55691 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
55692 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
55693 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
55694 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
55695 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55696 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
55697 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
55698 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
55699 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
55700 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
55701 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
55702 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55703 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55704 +4 4 4 4 4 4
55705 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
55706 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
55707 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
55708 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
55709 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55710 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55711 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55712 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
55713 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
55714 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
55715 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
55716 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55717 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55718 +4 4 4 4 4 4
55719 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
55720 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
55721 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
55722 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
55723 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55724 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
55725 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
55726 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
55727 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
55728 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
55729 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55730 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55731 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55732 +4 4 4 4 4 4
55733 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
55734 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
55735 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
55736 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
55737 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55738 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
55739 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
55740 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
55741 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
55742 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
55743 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
55744 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55745 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55746 +4 4 4 4 4 4
55747 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
55748 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
55749 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
55750 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
55751 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55752 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
55753 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
55754 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
55755 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
55756 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
55757 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
55758 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55759 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55760 +4 4 4 4 4 4
55761 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
55762 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
55763 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
55764 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
55765 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
55766 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
55767 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
55768 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
55769 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
55770 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
55771 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55772 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55773 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55774 +4 4 4 4 4 4
55775 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
55776 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
55777 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
55778 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
55779 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55780 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
55781 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
55782 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
55783 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
55784 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
55785 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55786 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55787 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55788 +4 4 4 4 4 4
55789 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
55790 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
55791 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
55792 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
55793 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55794 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
55795 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
55796 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
55797 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
55798 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
55799 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55800 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55801 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55802 +4 4 4 4 4 4
55803 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
55804 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
55805 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
55806 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
55807 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55808 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
55809 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
55810 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
55811 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
55812 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55813 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55814 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55815 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55816 +4 4 4 4 4 4
55817 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
55818 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
55819 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
55820 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
55821 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
55822 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
55823 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
55824 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
55825 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55826 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55827 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55828 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55829 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55830 +4 4 4 4 4 4
55831 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
55832 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
55833 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
55834 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
55835 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55836 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
55837 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
55838 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
55839 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55840 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55841 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55842 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55843 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55844 +4 4 4 4 4 4
55845 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
55846 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
55847 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
55848 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
55849 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
55850 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
55851 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
55852 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
55853 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55854 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55855 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55856 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55857 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55858 +4 4 4 4 4 4
55859 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
55860 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
55861 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55862 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
55863 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
55864 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
55865 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
55866 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
55867 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
55868 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55869 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55870 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55871 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55872 +4 4 4 4 4 4
55873 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
55874 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
55875 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
55876 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
55877 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
55878 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
55879 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
55880 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
55881 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55882 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55883 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55884 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55885 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55886 +4 4 4 4 4 4
55887 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
55888 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
55889 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55890 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
55891 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
55892 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
55893 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
55894 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
55895 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
55896 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55897 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55898 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55899 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55900 +4 4 4 4 4 4
55901 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
55902 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
55903 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
55904 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
55905 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
55906 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
55907 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
55908 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
55909 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55910 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55911 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55912 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55913 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55914 +4 4 4 4 4 4
55915 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55916 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
55917 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55918 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
55919 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
55920 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
55921 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
55922 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
55923 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55924 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55925 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55926 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55927 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55928 +4 4 4 4 4 4
55929 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
55930 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
55931 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
55932 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
55933 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
55934 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
55935 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55936 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
55937 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55938 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55939 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55940 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55941 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55942 +4 4 4 4 4 4
55943 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55944 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
55945 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
55946 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
55947 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
55948 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
55949 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55950 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
55951 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55952 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55953 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55954 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55955 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55956 +4 4 4 4 4 4
55957 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
55958 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
55959 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
55960 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
55961 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
55962 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
55963 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
55964 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
55965 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
55966 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55967 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55968 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55969 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55970 +4 4 4 4 4 4
55971 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55972 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
55973 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
55974 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
55975 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
55976 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
55977 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
55978 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
55979 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
55980 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55981 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55982 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55983 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55984 +4 4 4 4 4 4
55985 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
55986 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
55987 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
55988 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
55989 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
55990 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
55991 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
55992 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
55993 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
55994 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55995 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55996 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55997 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55998 +4 4 4 4 4 4
55999 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
56000 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
56001 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
56002 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
56003 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
56004 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
56005 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
56006 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
56007 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
56008 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
56009 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
56010 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56011 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56012 +4 4 4 4 4 4
56013 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
56014 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
56015 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
56016 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
56017 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
56018 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
56019 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
56020 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
56021 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
56022 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
56023 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
56024 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56025 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56026 +4 4 4 4 4 4
56027 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
56028 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
56029 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
56030 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
56031 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
56032 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
56033 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
56034 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
56035 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
56036 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
56037 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56038 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56039 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56040 +4 4 4 4 4 4
56041 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
56042 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
56043 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
56044 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
56045 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
56046 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
56047 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56048 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
56049 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
56050 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
56051 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
56052 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56053 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56054 +4 4 4 4 4 4
56055 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
56056 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
56057 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
56058 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
56059 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
56060 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
56061 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
56062 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
56063 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
56064 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
56065 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56066 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56067 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56068 +4 4 4 4 4 4
56069 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
56070 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
56071 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
56072 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
56073 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
56074 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
56075 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
56076 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
56077 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
56078 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
56081 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56082 +4 4 4 4 4 4
56083 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
56084 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
56085 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
56086 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
56087 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
56088 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
56089 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
56090 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
56091 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
56092 +13 16 17 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
56095 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56096 +4 4 4 4 4 4
56097 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
56098 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
56099 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
56100 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
56101 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
56102 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
56103 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
56104 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
56105 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
56106 +4 0 0 4 0 0 5 5 5 5 5 5 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 4 4 4 4 4 4 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
56111 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
56112 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
56113 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
56114 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
56115 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
56116 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
56117 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
56118 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
56119 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
56120 +4 3 3 5 5 5 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 4 4 4 4 4 4 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
56125 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
56126 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
56127 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
56128 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
56129 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
56130 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
56131 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
56132 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
56133 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
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 4 4 4 4 4 4 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
56139 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
56140 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
56141 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
56142 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
56143 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
56144 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
56145 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
56146 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
56147 +4 0 0 4 0 0 4 0 0 6 6 6 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 4 4 4 4 4 4 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
56153 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
56154 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
56155 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
56156 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
56157 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
56158 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
56159 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
56160 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
56161 +4 0 0 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 4 4 4 4 4 4 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
56167 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
56168 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
56169 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
56170 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
56171 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
56172 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
56173 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
56174 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
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 4 4 4 4 4 4 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
56181 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
56182 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
56183 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
56184 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
56185 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
56186 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
56187 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
56188 +6 6 6 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 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
56195 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
56196 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
56197 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
56198 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
56199 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
56200 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
56201 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
56202 +4 0 0 4 3 3 6 6 6 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 4 4 4 4 4 4 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
56209 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56210 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
56211 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
56212 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
56213 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
56214 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
56215 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
56216 +6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 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
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 5 5 5 5 5 5 5 5 5
56225 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
56226 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
56227 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
56228 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
56229 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
56230 +5 5 5 5 5 5 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 4 4 4 4 4 4 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
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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
56240 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
56241 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
56242 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
56243 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
56244 +4 3 3 5 5 5 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 4 4 4 4 4 4 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
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 4 4 4 5 5 5
56254 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
56255 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
56256 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
56257 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
56263 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56264 +4 4 4 4 4 4
56265 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56266 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56267 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56268 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
56269 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
56270 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
56271 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
56272 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56273 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56274 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56275 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56276 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56277 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56278 +4 4 4 4 4 4
56279 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56280 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56281 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56282 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
56283 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
56284 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
56285 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
56286 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56287 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56288 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56289 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56290 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56291 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56292 +4 4 4 4 4 4
56293 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56294 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56295 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56296 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
56297 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
56298 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
56299 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
56300 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56301 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56302 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56303 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56304 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56305 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56306 +4 4 4 4 4 4
56307 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56308 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56309 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56310 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
56311 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
56312 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
56313 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
56314 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56315 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56316 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56317 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56318 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56319 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56320 +4 4 4 4 4 4
56321 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56322 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56323 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56324 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56325 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
56326 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
56327 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
56328 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56329 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56330 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56331 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56332 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56333 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56334 +4 4 4 4 4 4
56335 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56336 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56337 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56338 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56339 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
56340 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
56341 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56342 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56343 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56344 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56345 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56346 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56347 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56348 +4 4 4 4 4 4
56349 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56350 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56351 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56352 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56353 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
56354 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
56355 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56356 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56357 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56358 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56359 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56360 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56361 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56362 +4 4 4 4 4 4
56363 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56364 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56365 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56366 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56367 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
56368 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
56369 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56370 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56371 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56372 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56373 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56374 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56375 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56376 +4 4 4 4 4 4
56377 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
56378 index fef20db..d28b1ab 100644
56379 --- a/drivers/xen/xenfs/xenstored.c
56380 +++ b/drivers/xen/xenfs/xenstored.c
56381 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
56382 static int xsd_kva_open(struct inode *inode, struct file *file)
56383 {
56384 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
56385 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56386 + NULL);
56387 +#else
56388 xen_store_interface);
56389 +#endif
56390 +
56391 if (!file->private_data)
56392 return -ENOMEM;
56393 return 0;
56394 diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
56395 index c71e886..61d3d44b 100644
56396 --- a/fs/9p/vfs_addr.c
56397 +++ b/fs/9p/vfs_addr.c
56398 @@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
56399
56400 retval = v9fs_file_write_internal(inode,
56401 v9inode->writeback_fid,
56402 - (__force const char __user *)buffer,
56403 + (const char __force_user *)buffer,
56404 len, &offset, 0);
56405 if (retval > 0)
56406 retval = 0;
56407 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
56408 index 53161ec..e261d8a 100644
56409 --- a/fs/9p/vfs_inode.c
56410 +++ b/fs/9p/vfs_inode.c
56411 @@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
56412 void
56413 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
56414 {
56415 - char *s = nd_get_link(nd);
56416 + const char *s = nd_get_link(nd);
56417
56418 p9_debug(P9_DEBUG_VFS, " %s %s\n",
56419 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
56420 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
56421 index 370b24c..ff0be7b 100644
56422 --- a/fs/Kconfig.binfmt
56423 +++ b/fs/Kconfig.binfmt
56424 @@ -103,7 +103,7 @@ config HAVE_AOUT
56425
56426 config BINFMT_AOUT
56427 tristate "Kernel support for a.out and ECOFF binaries"
56428 - depends on HAVE_AOUT
56429 + depends on HAVE_AOUT && BROKEN
56430 ---help---
56431 A.out (Assembler.OUTput) is a set of formats for libraries and
56432 executables used in the earliest versions of UNIX. Linux used
56433 diff --git a/fs/afs/inode.c b/fs/afs/inode.c
56434 index 2946712..f737435 100644
56435 --- a/fs/afs/inode.c
56436 +++ b/fs/afs/inode.c
56437 @@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
56438 struct afs_vnode *vnode;
56439 struct super_block *sb;
56440 struct inode *inode;
56441 - static atomic_t afs_autocell_ino;
56442 + static atomic_unchecked_t afs_autocell_ino;
56443
56444 _enter("{%x:%u},%*.*s,",
56445 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
56446 @@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
56447 data.fid.unique = 0;
56448 data.fid.vnode = 0;
56449
56450 - inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
56451 + inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
56452 afs_iget5_autocell_test, afs_iget5_set,
56453 &data);
56454 if (!inode) {
56455 diff --git a/fs/aio.c b/fs/aio.c
56456 index 6d68e01..573d8dc 100644
56457 --- a/fs/aio.c
56458 +++ b/fs/aio.c
56459 @@ -380,7 +380,7 @@ static int aio_setup_ring(struct kioctx *ctx)
56460 size += sizeof(struct io_event) * nr_events;
56461
56462 nr_pages = PFN_UP(size);
56463 - if (nr_pages < 0)
56464 + if (nr_pages <= 0)
56465 return -EINVAL;
56466
56467 file = aio_private_file(ctx, nr_pages);
56468 diff --git a/fs/attr.c b/fs/attr.c
56469 index 6530ced..4a827e2 100644
56470 --- a/fs/attr.c
56471 +++ b/fs/attr.c
56472 @@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
56473 unsigned long limit;
56474
56475 limit = rlimit(RLIMIT_FSIZE);
56476 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
56477 if (limit != RLIM_INFINITY && offset > limit)
56478 goto out_sig;
56479 if (offset > inode->i_sb->s_maxbytes)
56480 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
56481 index 116fd38..c04182da 100644
56482 --- a/fs/autofs4/waitq.c
56483 +++ b/fs/autofs4/waitq.c
56484 @@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
56485 {
56486 unsigned long sigpipe, flags;
56487 mm_segment_t fs;
56488 - const char *data = (const char *)addr;
56489 + const char __user *data = (const char __force_user *)addr;
56490 ssize_t wr = 0;
56491
56492 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
56493 @@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
56494 return 1;
56495 }
56496
56497 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56498 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
56499 +#endif
56500 +
56501 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
56502 enum autofs_notify notify)
56503 {
56504 @@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
56505
56506 /* If this is a direct mount request create a dummy name */
56507 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
56508 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56509 + /* this name does get written to userland via autofs4_write() */
56510 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
56511 +#else
56512 qstr.len = sprintf(name, "%p", dentry);
56513 +#endif
56514 else {
56515 qstr.len = autofs4_getpath(sbi, dentry, &name);
56516 if (!qstr.len) {
56517 diff --git a/fs/befs/endian.h b/fs/befs/endian.h
56518 index 2722387..56059b5 100644
56519 --- a/fs/befs/endian.h
56520 +++ b/fs/befs/endian.h
56521 @@ -11,7 +11,7 @@
56522
56523 #include <asm/byteorder.h>
56524
56525 -static inline u64
56526 +static inline u64 __intentional_overflow(-1)
56527 fs64_to_cpu(const struct super_block *sb, fs64 n)
56528 {
56529 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56530 @@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
56531 return (__force fs64)cpu_to_be64(n);
56532 }
56533
56534 -static inline u32
56535 +static inline u32 __intentional_overflow(-1)
56536 fs32_to_cpu(const struct super_block *sb, fs32 n)
56537 {
56538 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56539 @@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
56540 return (__force fs32)cpu_to_be32(n);
56541 }
56542
56543 -static inline u16
56544 +static inline u16 __intentional_overflow(-1)
56545 fs16_to_cpu(const struct super_block *sb, fs16 n)
56546 {
56547 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56548 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
56549 index ca0ba15..0fa3257 100644
56550 --- a/fs/binfmt_aout.c
56551 +++ b/fs/binfmt_aout.c
56552 @@ -16,6 +16,7 @@
56553 #include <linux/string.h>
56554 #include <linux/fs.h>
56555 #include <linux/file.h>
56556 +#include <linux/security.h>
56557 #include <linux/stat.h>
56558 #include <linux/fcntl.h>
56559 #include <linux/ptrace.h>
56560 @@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
56561 #endif
56562 # define START_STACK(u) ((void __user *)u.start_stack)
56563
56564 + memset(&dump, 0, sizeof(dump));
56565 +
56566 fs = get_fs();
56567 set_fs(KERNEL_DS);
56568 has_dumped = 1;
56569 @@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
56570
56571 /* If the size of the dump file exceeds the rlimit, then see what would happen
56572 if we wrote the stack, but not the data area. */
56573 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
56574 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
56575 dump.u_dsize = 0;
56576
56577 /* Make sure we have enough room to write the stack and data areas. */
56578 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
56579 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
56580 dump.u_ssize = 0;
56581
56582 @@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
56583 rlim = rlimit(RLIMIT_DATA);
56584 if (rlim >= RLIM_INFINITY)
56585 rlim = ~0;
56586 +
56587 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
56588 if (ex.a_data + ex.a_bss > rlim)
56589 return -ENOMEM;
56590
56591 @@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
56592
56593 install_exec_creds(bprm);
56594
56595 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56596 + current->mm->pax_flags = 0UL;
56597 +#endif
56598 +
56599 +#ifdef CONFIG_PAX_PAGEEXEC
56600 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
56601 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
56602 +
56603 +#ifdef CONFIG_PAX_EMUTRAMP
56604 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
56605 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
56606 +#endif
56607 +
56608 +#ifdef CONFIG_PAX_MPROTECT
56609 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
56610 + current->mm->pax_flags |= MF_PAX_MPROTECT;
56611 +#endif
56612 +
56613 + }
56614 +#endif
56615 +
56616 if (N_MAGIC(ex) == OMAGIC) {
56617 unsigned long text_addr, map_size;
56618 loff_t pos;
56619 @@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
56620 }
56621
56622 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
56623 - PROT_READ | PROT_WRITE | PROT_EXEC,
56624 + PROT_READ | PROT_WRITE,
56625 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
56626 fd_offset + ex.a_text);
56627 if (error != N_DATADDR(ex)) {
56628 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
56629 index aa3cb62..bc53934 100644
56630 --- a/fs/binfmt_elf.c
56631 +++ b/fs/binfmt_elf.c
56632 @@ -34,6 +34,7 @@
56633 #include <linux/utsname.h>
56634 #include <linux/coredump.h>
56635 #include <linux/sched.h>
56636 +#include <linux/xattr.h>
56637 #include <asm/uaccess.h>
56638 #include <asm/param.h>
56639 #include <asm/page.h>
56640 @@ -47,7 +48,7 @@
56641
56642 static int load_elf_binary(struct linux_binprm *bprm);
56643 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
56644 - int, int, unsigned long);
56645 + int, int, unsigned long) __intentional_overflow(-1);
56646
56647 #ifdef CONFIG_USELIB
56648 static int load_elf_library(struct file *);
56649 @@ -65,6 +66,14 @@ static int elf_core_dump(struct coredump_params *cprm);
56650 #define elf_core_dump NULL
56651 #endif
56652
56653 +#ifdef CONFIG_PAX_MPROTECT
56654 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
56655 +#endif
56656 +
56657 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56658 +static void elf_handle_mmap(struct file *file);
56659 +#endif
56660 +
56661 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
56662 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
56663 #else
56664 @@ -84,6 +93,15 @@ static struct linux_binfmt elf_format = {
56665 .load_binary = load_elf_binary,
56666 .load_shlib = load_elf_library,
56667 .core_dump = elf_core_dump,
56668 +
56669 +#ifdef CONFIG_PAX_MPROTECT
56670 + .handle_mprotect= elf_handle_mprotect,
56671 +#endif
56672 +
56673 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56674 + .handle_mmap = elf_handle_mmap,
56675 +#endif
56676 +
56677 .min_coredump = ELF_EXEC_PAGESIZE,
56678 };
56679
56680 @@ -91,6 +109,8 @@ static struct linux_binfmt elf_format = {
56681
56682 static int set_brk(unsigned long start, unsigned long end)
56683 {
56684 + unsigned long e = end;
56685 +
56686 start = ELF_PAGEALIGN(start);
56687 end = ELF_PAGEALIGN(end);
56688 if (end > start) {
56689 @@ -99,7 +119,7 @@ static int set_brk(unsigned long start, unsigned long end)
56690 if (BAD_ADDR(addr))
56691 return addr;
56692 }
56693 - current->mm->start_brk = current->mm->brk = end;
56694 + current->mm->start_brk = current->mm->brk = e;
56695 return 0;
56696 }
56697
56698 @@ -160,12 +180,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56699 elf_addr_t __user *u_rand_bytes;
56700 const char *k_platform = ELF_PLATFORM;
56701 const char *k_base_platform = ELF_BASE_PLATFORM;
56702 - unsigned char k_rand_bytes[16];
56703 + u32 k_rand_bytes[4];
56704 int items;
56705 elf_addr_t *elf_info;
56706 int ei_index = 0;
56707 const struct cred *cred = current_cred();
56708 struct vm_area_struct *vma;
56709 + unsigned long saved_auxv[AT_VECTOR_SIZE];
56710
56711 /*
56712 * In some cases (e.g. Hyper-Threading), we want to avoid L1
56713 @@ -207,8 +228,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56714 * Generate 16 random bytes for userspace PRNG seeding.
56715 */
56716 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
56717 - u_rand_bytes = (elf_addr_t __user *)
56718 - STACK_ALLOC(p, sizeof(k_rand_bytes));
56719 + prandom_seed(k_rand_bytes[0] ^ prandom_u32());
56720 + prandom_seed(k_rand_bytes[1] ^ prandom_u32());
56721 + prandom_seed(k_rand_bytes[2] ^ prandom_u32());
56722 + prandom_seed(k_rand_bytes[3] ^ prandom_u32());
56723 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
56724 + u_rand_bytes = (elf_addr_t __user *) p;
56725 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
56726 return -EFAULT;
56727
56728 @@ -323,9 +348,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56729 return -EFAULT;
56730 current->mm->env_end = p;
56731
56732 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
56733 +
56734 /* Put the elf_info on the stack in the right place. */
56735 sp = (elf_addr_t __user *)envp + 1;
56736 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
56737 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
56738 return -EFAULT;
56739 return 0;
56740 }
56741 @@ -393,15 +420,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
56742 an ELF header */
56743
56744 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56745 - struct file *interpreter, unsigned long *interp_map_addr,
56746 - unsigned long no_base)
56747 + struct file *interpreter, unsigned long no_base)
56748 {
56749 struct elf_phdr *elf_phdata;
56750 struct elf_phdr *eppnt;
56751 - unsigned long load_addr = 0;
56752 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
56753 int load_addr_set = 0;
56754 unsigned long last_bss = 0, elf_bss = 0;
56755 - unsigned long error = ~0UL;
56756 + unsigned long error = -EINVAL;
56757 unsigned long total_size;
56758 int retval, i, size;
56759
56760 @@ -447,6 +473,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56761 goto out_close;
56762 }
56763
56764 +#ifdef CONFIG_PAX_SEGMEXEC
56765 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
56766 + pax_task_size = SEGMEXEC_TASK_SIZE;
56767 +#endif
56768 +
56769 eppnt = elf_phdata;
56770 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
56771 if (eppnt->p_type == PT_LOAD) {
56772 @@ -470,8 +501,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56773 map_addr = elf_map(interpreter, load_addr + vaddr,
56774 eppnt, elf_prot, elf_type, total_size);
56775 total_size = 0;
56776 - if (!*interp_map_addr)
56777 - *interp_map_addr = map_addr;
56778 error = map_addr;
56779 if (BAD_ADDR(map_addr))
56780 goto out_close;
56781 @@ -490,8 +519,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56782 k = load_addr + eppnt->p_vaddr;
56783 if (BAD_ADDR(k) ||
56784 eppnt->p_filesz > eppnt->p_memsz ||
56785 - eppnt->p_memsz > TASK_SIZE ||
56786 - TASK_SIZE - eppnt->p_memsz < k) {
56787 + eppnt->p_memsz > pax_task_size ||
56788 + pax_task_size - eppnt->p_memsz < k) {
56789 error = -ENOMEM;
56790 goto out_close;
56791 }
56792 @@ -530,9 +559,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56793 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
56794
56795 /* Map the last of the bss segment */
56796 - error = vm_brk(elf_bss, last_bss - elf_bss);
56797 - if (BAD_ADDR(error))
56798 - goto out_close;
56799 + if (last_bss > elf_bss) {
56800 + error = vm_brk(elf_bss, last_bss - elf_bss);
56801 + if (BAD_ADDR(error))
56802 + goto out_close;
56803 + }
56804 }
56805
56806 error = load_addr;
56807 @@ -543,6 +574,336 @@ out:
56808 return error;
56809 }
56810
56811 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
56812 +#ifdef CONFIG_PAX_SOFTMODE
56813 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
56814 +{
56815 + unsigned long pax_flags = 0UL;
56816 +
56817 +#ifdef CONFIG_PAX_PAGEEXEC
56818 + if (elf_phdata->p_flags & PF_PAGEEXEC)
56819 + pax_flags |= MF_PAX_PAGEEXEC;
56820 +#endif
56821 +
56822 +#ifdef CONFIG_PAX_SEGMEXEC
56823 + if (elf_phdata->p_flags & PF_SEGMEXEC)
56824 + pax_flags |= MF_PAX_SEGMEXEC;
56825 +#endif
56826 +
56827 +#ifdef CONFIG_PAX_EMUTRAMP
56828 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56829 + pax_flags |= MF_PAX_EMUTRAMP;
56830 +#endif
56831 +
56832 +#ifdef CONFIG_PAX_MPROTECT
56833 + if (elf_phdata->p_flags & PF_MPROTECT)
56834 + pax_flags |= MF_PAX_MPROTECT;
56835 +#endif
56836 +
56837 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56838 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
56839 + pax_flags |= MF_PAX_RANDMMAP;
56840 +#endif
56841 +
56842 + return pax_flags;
56843 +}
56844 +#endif
56845 +
56846 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
56847 +{
56848 + unsigned long pax_flags = 0UL;
56849 +
56850 +#ifdef CONFIG_PAX_PAGEEXEC
56851 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
56852 + pax_flags |= MF_PAX_PAGEEXEC;
56853 +#endif
56854 +
56855 +#ifdef CONFIG_PAX_SEGMEXEC
56856 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
56857 + pax_flags |= MF_PAX_SEGMEXEC;
56858 +#endif
56859 +
56860 +#ifdef CONFIG_PAX_EMUTRAMP
56861 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
56862 + pax_flags |= MF_PAX_EMUTRAMP;
56863 +#endif
56864 +
56865 +#ifdef CONFIG_PAX_MPROTECT
56866 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
56867 + pax_flags |= MF_PAX_MPROTECT;
56868 +#endif
56869 +
56870 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56871 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
56872 + pax_flags |= MF_PAX_RANDMMAP;
56873 +#endif
56874 +
56875 + return pax_flags;
56876 +}
56877 +#endif
56878 +
56879 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56880 +#ifdef CONFIG_PAX_SOFTMODE
56881 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
56882 +{
56883 + unsigned long pax_flags = 0UL;
56884 +
56885 +#ifdef CONFIG_PAX_PAGEEXEC
56886 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
56887 + pax_flags |= MF_PAX_PAGEEXEC;
56888 +#endif
56889 +
56890 +#ifdef CONFIG_PAX_SEGMEXEC
56891 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
56892 + pax_flags |= MF_PAX_SEGMEXEC;
56893 +#endif
56894 +
56895 +#ifdef CONFIG_PAX_EMUTRAMP
56896 + if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56897 + pax_flags |= MF_PAX_EMUTRAMP;
56898 +#endif
56899 +
56900 +#ifdef CONFIG_PAX_MPROTECT
56901 + if (pax_flags_softmode & MF_PAX_MPROTECT)
56902 + pax_flags |= MF_PAX_MPROTECT;
56903 +#endif
56904 +
56905 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56906 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
56907 + pax_flags |= MF_PAX_RANDMMAP;
56908 +#endif
56909 +
56910 + return pax_flags;
56911 +}
56912 +#endif
56913 +
56914 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
56915 +{
56916 + unsigned long pax_flags = 0UL;
56917 +
56918 +#ifdef CONFIG_PAX_PAGEEXEC
56919 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
56920 + pax_flags |= MF_PAX_PAGEEXEC;
56921 +#endif
56922 +
56923 +#ifdef CONFIG_PAX_SEGMEXEC
56924 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
56925 + pax_flags |= MF_PAX_SEGMEXEC;
56926 +#endif
56927 +
56928 +#ifdef CONFIG_PAX_EMUTRAMP
56929 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
56930 + pax_flags |= MF_PAX_EMUTRAMP;
56931 +#endif
56932 +
56933 +#ifdef CONFIG_PAX_MPROTECT
56934 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
56935 + pax_flags |= MF_PAX_MPROTECT;
56936 +#endif
56937 +
56938 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56939 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
56940 + pax_flags |= MF_PAX_RANDMMAP;
56941 +#endif
56942 +
56943 + return pax_flags;
56944 +}
56945 +#endif
56946 +
56947 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56948 +static unsigned long pax_parse_defaults(void)
56949 +{
56950 + unsigned long pax_flags = 0UL;
56951 +
56952 +#ifdef CONFIG_PAX_SOFTMODE
56953 + if (pax_softmode)
56954 + return pax_flags;
56955 +#endif
56956 +
56957 +#ifdef CONFIG_PAX_PAGEEXEC
56958 + pax_flags |= MF_PAX_PAGEEXEC;
56959 +#endif
56960 +
56961 +#ifdef CONFIG_PAX_SEGMEXEC
56962 + pax_flags |= MF_PAX_SEGMEXEC;
56963 +#endif
56964 +
56965 +#ifdef CONFIG_PAX_MPROTECT
56966 + pax_flags |= MF_PAX_MPROTECT;
56967 +#endif
56968 +
56969 +#ifdef CONFIG_PAX_RANDMMAP
56970 + if (randomize_va_space)
56971 + pax_flags |= MF_PAX_RANDMMAP;
56972 +#endif
56973 +
56974 + return pax_flags;
56975 +}
56976 +
56977 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
56978 +{
56979 + unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
56980 +
56981 +#ifdef CONFIG_PAX_EI_PAX
56982 +
56983 +#ifdef CONFIG_PAX_SOFTMODE
56984 + if (pax_softmode)
56985 + return pax_flags;
56986 +#endif
56987 +
56988 + pax_flags = 0UL;
56989 +
56990 +#ifdef CONFIG_PAX_PAGEEXEC
56991 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
56992 + pax_flags |= MF_PAX_PAGEEXEC;
56993 +#endif
56994 +
56995 +#ifdef CONFIG_PAX_SEGMEXEC
56996 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
56997 + pax_flags |= MF_PAX_SEGMEXEC;
56998 +#endif
56999 +
57000 +#ifdef CONFIG_PAX_EMUTRAMP
57001 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
57002 + pax_flags |= MF_PAX_EMUTRAMP;
57003 +#endif
57004 +
57005 +#ifdef CONFIG_PAX_MPROTECT
57006 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
57007 + pax_flags |= MF_PAX_MPROTECT;
57008 +#endif
57009 +
57010 +#ifdef CONFIG_PAX_ASLR
57011 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
57012 + pax_flags |= MF_PAX_RANDMMAP;
57013 +#endif
57014 +
57015 +#endif
57016 +
57017 + return pax_flags;
57018 +
57019 +}
57020 +
57021 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
57022 +{
57023 +
57024 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
57025 + unsigned long i;
57026 +
57027 + for (i = 0UL; i < elf_ex->e_phnum; i++)
57028 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
57029 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
57030 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
57031 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
57032 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
57033 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
57034 + return PAX_PARSE_FLAGS_FALLBACK;
57035 +
57036 +#ifdef CONFIG_PAX_SOFTMODE
57037 + if (pax_softmode)
57038 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
57039 + else
57040 +#endif
57041 +
57042 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
57043 + break;
57044 + }
57045 +#endif
57046 +
57047 + return PAX_PARSE_FLAGS_FALLBACK;
57048 +}
57049 +
57050 +static unsigned long pax_parse_xattr_pax(struct file * const file)
57051 +{
57052 +
57053 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
57054 + ssize_t xattr_size, i;
57055 + unsigned char xattr_value[sizeof("pemrs") - 1];
57056 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
57057 +
57058 + xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
57059 + if (xattr_size < 0 || xattr_size > sizeof xattr_value)
57060 + return PAX_PARSE_FLAGS_FALLBACK;
57061 +
57062 + for (i = 0; i < xattr_size; i++)
57063 + switch (xattr_value[i]) {
57064 + default:
57065 + return PAX_PARSE_FLAGS_FALLBACK;
57066 +
57067 +#define parse_flag(option1, option2, flag) \
57068 + case option1: \
57069 + if (pax_flags_hardmode & MF_PAX_##flag) \
57070 + return PAX_PARSE_FLAGS_FALLBACK;\
57071 + pax_flags_hardmode |= MF_PAX_##flag; \
57072 + break; \
57073 + case option2: \
57074 + if (pax_flags_softmode & MF_PAX_##flag) \
57075 + return PAX_PARSE_FLAGS_FALLBACK;\
57076 + pax_flags_softmode |= MF_PAX_##flag; \
57077 + break;
57078 +
57079 + parse_flag('p', 'P', PAGEEXEC);
57080 + parse_flag('e', 'E', EMUTRAMP);
57081 + parse_flag('m', 'M', MPROTECT);
57082 + parse_flag('r', 'R', RANDMMAP);
57083 + parse_flag('s', 'S', SEGMEXEC);
57084 +
57085 +#undef parse_flag
57086 + }
57087 +
57088 + if (pax_flags_hardmode & pax_flags_softmode)
57089 + return PAX_PARSE_FLAGS_FALLBACK;
57090 +
57091 +#ifdef CONFIG_PAX_SOFTMODE
57092 + if (pax_softmode)
57093 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
57094 + else
57095 +#endif
57096 +
57097 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
57098 +#else
57099 + return PAX_PARSE_FLAGS_FALLBACK;
57100 +#endif
57101 +
57102 +}
57103 +
57104 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
57105 +{
57106 + unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
57107 +
57108 + pax_flags = pax_parse_defaults();
57109 + ei_pax_flags = pax_parse_ei_pax(elf_ex);
57110 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
57111 + xattr_pax_flags = pax_parse_xattr_pax(file);
57112 +
57113 + if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
57114 + xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
57115 + pt_pax_flags != xattr_pax_flags)
57116 + return -EINVAL;
57117 + if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
57118 + pax_flags = xattr_pax_flags;
57119 + else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
57120 + pax_flags = pt_pax_flags;
57121 + else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
57122 + pax_flags = ei_pax_flags;
57123 +
57124 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
57125 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
57126 + if ((__supported_pte_mask & _PAGE_NX))
57127 + pax_flags &= ~MF_PAX_SEGMEXEC;
57128 + else
57129 + pax_flags &= ~MF_PAX_PAGEEXEC;
57130 + }
57131 +#endif
57132 +
57133 + if (0 > pax_check_flags(&pax_flags))
57134 + return -EINVAL;
57135 +
57136 + current->mm->pax_flags = pax_flags;
57137 + return 0;
57138 +}
57139 +#endif
57140 +
57141 /*
57142 * These are the functions used to load ELF style executables and shared
57143 * libraries. There is no binary dependent code anywhere else.
57144 @@ -556,6 +917,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
57145 {
57146 unsigned int random_variable = 0;
57147
57148 +#ifdef CONFIG_PAX_RANDUSTACK
57149 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
57150 + return stack_top - current->mm->delta_stack;
57151 +#endif
57152 +
57153 if ((current->flags & PF_RANDOMIZE) &&
57154 !(current->personality & ADDR_NO_RANDOMIZE)) {
57155 random_variable = get_random_int() & STACK_RND_MASK;
57156 @@ -574,7 +940,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
57157 unsigned long load_addr = 0, load_bias = 0;
57158 int load_addr_set = 0;
57159 char * elf_interpreter = NULL;
57160 - unsigned long error;
57161 + unsigned long error = 0;
57162 struct elf_phdr *elf_ppnt, *elf_phdata;
57163 unsigned long elf_bss, elf_brk;
57164 int retval, i;
57165 @@ -589,6 +955,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
57166 struct elfhdr elf_ex;
57167 struct elfhdr interp_elf_ex;
57168 } *loc;
57169 + unsigned long pax_task_size;
57170
57171 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
57172 if (!loc) {
57173 @@ -726,6 +1093,77 @@ static int load_elf_binary(struct linux_binprm *bprm)
57174 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
57175 may depend on the personality. */
57176 SET_PERSONALITY(loc->elf_ex);
57177 +
57178 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
57179 + current->mm->pax_flags = 0UL;
57180 +#endif
57181 +
57182 +#ifdef CONFIG_PAX_DLRESOLVE
57183 + current->mm->call_dl_resolve = 0UL;
57184 +#endif
57185 +
57186 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
57187 + current->mm->call_syscall = 0UL;
57188 +#endif
57189 +
57190 +#ifdef CONFIG_PAX_ASLR
57191 + current->mm->delta_mmap = 0UL;
57192 + current->mm->delta_stack = 0UL;
57193 +#endif
57194 +
57195 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
57196 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
57197 + send_sig(SIGKILL, current, 0);
57198 + goto out_free_dentry;
57199 + }
57200 +#endif
57201 +
57202 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57203 + pax_set_initial_flags(bprm);
57204 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
57205 + if (pax_set_initial_flags_func)
57206 + (pax_set_initial_flags_func)(bprm);
57207 +#endif
57208 +
57209 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
57210 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
57211 + current->mm->context.user_cs_limit = PAGE_SIZE;
57212 + current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
57213 + }
57214 +#endif
57215 +
57216 +#ifdef CONFIG_PAX_SEGMEXEC
57217 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
57218 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
57219 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
57220 + pax_task_size = SEGMEXEC_TASK_SIZE;
57221 + current->mm->def_flags |= VM_NOHUGEPAGE;
57222 + } else
57223 +#endif
57224 +
57225 + pax_task_size = TASK_SIZE;
57226 +
57227 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
57228 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
57229 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
57230 + put_cpu();
57231 + }
57232 +#endif
57233 +
57234 +#ifdef CONFIG_PAX_ASLR
57235 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
57236 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
57237 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
57238 + }
57239 +#endif
57240 +
57241 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
57242 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
57243 + executable_stack = EXSTACK_DISABLE_X;
57244 + current->personality &= ~READ_IMPLIES_EXEC;
57245 + } else
57246 +#endif
57247 +
57248 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
57249 current->personality |= READ_IMPLIES_EXEC;
57250
57251 @@ -815,6 +1253,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
57252 #else
57253 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
57254 #endif
57255 +
57256 +#ifdef CONFIG_PAX_RANDMMAP
57257 + /* PaX: randomize base address at the default exe base if requested */
57258 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
57259 +#ifdef CONFIG_SPARC64
57260 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
57261 +#else
57262 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
57263 +#endif
57264 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
57265 + elf_flags |= MAP_FIXED;
57266 + }
57267 +#endif
57268 +
57269 }
57270
57271 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
57272 @@ -847,9 +1299,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
57273 * allowed task size. Note that p_filesz must always be
57274 * <= p_memsz so it is only necessary to check p_memsz.
57275 */
57276 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
57277 - elf_ppnt->p_memsz > TASK_SIZE ||
57278 - TASK_SIZE - elf_ppnt->p_memsz < k) {
57279 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
57280 + elf_ppnt->p_memsz > pax_task_size ||
57281 + pax_task_size - elf_ppnt->p_memsz < k) {
57282 /* set_brk can never work. Avoid overflows. */
57283 send_sig(SIGKILL, current, 0);
57284 retval = -EINVAL;
57285 @@ -888,17 +1340,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
57286 goto out_free_dentry;
57287 }
57288 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
57289 - send_sig(SIGSEGV, current, 0);
57290 - retval = -EFAULT; /* Nobody gets to see this, but.. */
57291 - goto out_free_dentry;
57292 + /*
57293 + * This bss-zeroing can fail if the ELF
57294 + * file specifies odd protections. So
57295 + * we don't check the return value
57296 + */
57297 }
57298
57299 +#ifdef CONFIG_PAX_RANDMMAP
57300 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
57301 + unsigned long start, size, flags;
57302 + vm_flags_t vm_flags;
57303 +
57304 + start = ELF_PAGEALIGN(elf_brk);
57305 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
57306 + flags = MAP_FIXED | MAP_PRIVATE;
57307 + vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
57308 +
57309 + down_write(&current->mm->mmap_sem);
57310 + start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
57311 + retval = -ENOMEM;
57312 + if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
57313 +// if (current->personality & ADDR_NO_RANDOMIZE)
57314 +// vm_flags |= VM_READ | VM_MAYREAD;
57315 + start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
57316 + retval = IS_ERR_VALUE(start) ? start : 0;
57317 + }
57318 + up_write(&current->mm->mmap_sem);
57319 + if (retval == 0)
57320 + retval = set_brk(start + size, start + size + PAGE_SIZE);
57321 + if (retval < 0) {
57322 + send_sig(SIGKILL, current, 0);
57323 + goto out_free_dentry;
57324 + }
57325 + }
57326 +#endif
57327 +
57328 if (elf_interpreter) {
57329 - unsigned long interp_map_addr = 0;
57330 -
57331 elf_entry = load_elf_interp(&loc->interp_elf_ex,
57332 interpreter,
57333 - &interp_map_addr,
57334 load_bias);
57335 if (!IS_ERR((void *)elf_entry)) {
57336 /*
57337 @@ -1122,7 +1602,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
57338 * Decide what to dump of a segment, part, all or none.
57339 */
57340 static unsigned long vma_dump_size(struct vm_area_struct *vma,
57341 - unsigned long mm_flags)
57342 + unsigned long mm_flags, long signr)
57343 {
57344 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
57345
57346 @@ -1160,7 +1640,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
57347 if (vma->vm_file == NULL)
57348 return 0;
57349
57350 - if (FILTER(MAPPED_PRIVATE))
57351 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
57352 goto whole;
57353
57354 /*
57355 @@ -1367,9 +1847,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
57356 {
57357 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
57358 int i = 0;
57359 - do
57360 + do {
57361 i += 2;
57362 - while (auxv[i - 2] != AT_NULL);
57363 + } while (auxv[i - 2] != AT_NULL);
57364 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
57365 }
57366
57367 @@ -1378,7 +1858,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
57368 {
57369 mm_segment_t old_fs = get_fs();
57370 set_fs(KERNEL_DS);
57371 - copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
57372 + copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
57373 set_fs(old_fs);
57374 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
57375 }
57376 @@ -2002,14 +2482,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
57377 }
57378
57379 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
57380 - unsigned long mm_flags)
57381 + struct coredump_params *cprm)
57382 {
57383 struct vm_area_struct *vma;
57384 size_t size = 0;
57385
57386 for (vma = first_vma(current, gate_vma); vma != NULL;
57387 vma = next_vma(vma, gate_vma))
57388 - size += vma_dump_size(vma, mm_flags);
57389 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
57390 return size;
57391 }
57392
57393 @@ -2100,7 +2580,7 @@ static int elf_core_dump(struct coredump_params *cprm)
57394
57395 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
57396
57397 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
57398 + offset += elf_core_vma_data_size(gate_vma, cprm);
57399 offset += elf_core_extra_data_size();
57400 e_shoff = offset;
57401
57402 @@ -2128,7 +2608,7 @@ static int elf_core_dump(struct coredump_params *cprm)
57403 phdr.p_offset = offset;
57404 phdr.p_vaddr = vma->vm_start;
57405 phdr.p_paddr = 0;
57406 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
57407 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
57408 phdr.p_memsz = vma->vm_end - vma->vm_start;
57409 offset += phdr.p_filesz;
57410 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
57411 @@ -2161,7 +2641,7 @@ static int elf_core_dump(struct coredump_params *cprm)
57412 unsigned long addr;
57413 unsigned long end;
57414
57415 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
57416 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
57417
57418 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
57419 struct page *page;
57420 @@ -2202,6 +2682,167 @@ out:
57421
57422 #endif /* CONFIG_ELF_CORE */
57423
57424 +#ifdef CONFIG_PAX_MPROTECT
57425 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
57426 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
57427 + * we'll remove VM_MAYWRITE for good on RELRO segments.
57428 + *
57429 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
57430 + * basis because we want to allow the common case and not the special ones.
57431 + */
57432 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
57433 +{
57434 + struct elfhdr elf_h;
57435 + struct elf_phdr elf_p;
57436 + unsigned long i;
57437 + unsigned long oldflags;
57438 + bool is_textrel_rw, is_textrel_rx, is_relro;
57439 +
57440 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
57441 + return;
57442 +
57443 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
57444 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
57445 +
57446 +#ifdef CONFIG_PAX_ELFRELOCS
57447 + /* possible TEXTREL */
57448 + is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
57449 + is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
57450 +#else
57451 + is_textrel_rw = false;
57452 + is_textrel_rx = false;
57453 +#endif
57454 +
57455 + /* possible RELRO */
57456 + is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
57457 +
57458 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
57459 + return;
57460 +
57461 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
57462 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
57463 +
57464 +#ifdef CONFIG_PAX_ETEXECRELOCS
57465 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
57466 +#else
57467 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
57468 +#endif
57469 +
57470 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
57471 + !elf_check_arch(&elf_h) ||
57472 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
57473 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
57474 + return;
57475 +
57476 + for (i = 0UL; i < elf_h.e_phnum; i++) {
57477 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
57478 + return;
57479 + switch (elf_p.p_type) {
57480 + case PT_DYNAMIC:
57481 + if (!is_textrel_rw && !is_textrel_rx)
57482 + continue;
57483 + i = 0UL;
57484 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
57485 + elf_dyn dyn;
57486 +
57487 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
57488 + break;
57489 + if (dyn.d_tag == DT_NULL)
57490 + break;
57491 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
57492 + gr_log_textrel(vma);
57493 + if (is_textrel_rw)
57494 + vma->vm_flags |= VM_MAYWRITE;
57495 + else
57496 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
57497 + vma->vm_flags &= ~VM_MAYWRITE;
57498 + break;
57499 + }
57500 + i++;
57501 + }
57502 + is_textrel_rw = false;
57503 + is_textrel_rx = false;
57504 + continue;
57505 +
57506 + case PT_GNU_RELRO:
57507 + if (!is_relro)
57508 + continue;
57509 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
57510 + vma->vm_flags &= ~VM_MAYWRITE;
57511 + is_relro = false;
57512 + continue;
57513 +
57514 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
57515 + case PT_PAX_FLAGS: {
57516 + const char *msg_mprotect = "", *msg_emutramp = "";
57517 + char *buffer_lib, *buffer_exe;
57518 +
57519 + if (elf_p.p_flags & PF_NOMPROTECT)
57520 + msg_mprotect = "MPROTECT disabled";
57521 +
57522 +#ifdef CONFIG_PAX_EMUTRAMP
57523 + if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
57524 + msg_emutramp = "EMUTRAMP enabled";
57525 +#endif
57526 +
57527 + if (!msg_mprotect[0] && !msg_emutramp[0])
57528 + continue;
57529 +
57530 + if (!printk_ratelimit())
57531 + continue;
57532 +
57533 + buffer_lib = (char *)__get_free_page(GFP_KERNEL);
57534 + buffer_exe = (char *)__get_free_page(GFP_KERNEL);
57535 + if (buffer_lib && buffer_exe) {
57536 + char *path_lib, *path_exe;
57537 +
57538 + path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
57539 + path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
57540 +
57541 + pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
57542 + (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
57543 +
57544 + }
57545 + free_page((unsigned long)buffer_exe);
57546 + free_page((unsigned long)buffer_lib);
57547 + continue;
57548 + }
57549 +#endif
57550 +
57551 + }
57552 + }
57553 +}
57554 +#endif
57555 +
57556 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57557 +
57558 +extern int grsec_enable_log_rwxmaps;
57559 +
57560 +static void elf_handle_mmap(struct file *file)
57561 +{
57562 + struct elfhdr elf_h;
57563 + struct elf_phdr elf_p;
57564 + unsigned long i;
57565 +
57566 + if (!grsec_enable_log_rwxmaps)
57567 + return;
57568 +
57569 + if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
57570 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
57571 + (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
57572 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
57573 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
57574 + return;
57575 +
57576 + for (i = 0UL; i < elf_h.e_phnum; i++) {
57577 + if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
57578 + return;
57579 + if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
57580 + gr_log_ptgnustack(file);
57581 + }
57582 +}
57583 +#endif
57584 +
57585 static int __init init_elf_binfmt(void)
57586 {
57587 register_binfmt(&elf_format);
57588 diff --git a/fs/bio.c b/fs/bio.c
57589 index 6f0362b..26a7496 100644
57590 --- a/fs/bio.c
57591 +++ b/fs/bio.c
57592 @@ -1144,7 +1144,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
57593 /*
57594 * Overflow, abort
57595 */
57596 - if (end < start)
57597 + if (end < start || end - start > INT_MAX - nr_pages)
57598 return ERR_PTR(-EINVAL);
57599
57600 nr_pages += end - start;
57601 @@ -1278,7 +1278,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
57602 /*
57603 * Overflow, abort
57604 */
57605 - if (end < start)
57606 + if (end < start || end - start > INT_MAX - nr_pages)
57607 return ERR_PTR(-EINVAL);
57608
57609 nr_pages += end - start;
57610 @@ -1540,7 +1540,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
57611 const int read = bio_data_dir(bio) == READ;
57612 struct bio_map_data *bmd = bio->bi_private;
57613 int i;
57614 - char *p = bmd->sgvecs[0].iov_base;
57615 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
57616
57617 bio_for_each_segment_all(bvec, bio, i) {
57618 char *addr = page_address(bvec->bv_page);
57619 diff --git a/fs/block_dev.c b/fs/block_dev.c
57620 index 552a8d1..d51ccf3 100644
57621 --- a/fs/block_dev.c
57622 +++ b/fs/block_dev.c
57623 @@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
57624 else if (bdev->bd_contains == bdev)
57625 return true; /* is a whole device which isn't held */
57626
57627 - else if (whole->bd_holder == bd_may_claim)
57628 + else if (whole->bd_holder == (void *)bd_may_claim)
57629 return true; /* is a partition of a device that is being partitioned */
57630 else if (whole->bd_holder != NULL)
57631 return false; /* is a partition of a held device */
57632 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
57633 index 1bcfcdb..e942132 100644
57634 --- a/fs/btrfs/ctree.c
57635 +++ b/fs/btrfs/ctree.c
57636 @@ -1216,9 +1216,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
57637 free_extent_buffer(buf);
57638 add_root_to_dirty_list(root);
57639 } else {
57640 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
57641 - parent_start = parent->start;
57642 - else
57643 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
57644 + if (parent)
57645 + parent_start = parent->start;
57646 + else
57647 + parent_start = 0;
57648 + } else
57649 parent_start = 0;
57650
57651 WARN_ON(trans->transid != btrfs_header_generation(parent));
57652 diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
57653 index 33e561a..16df7ae 100644
57654 --- a/fs/btrfs/delayed-inode.c
57655 +++ b/fs/btrfs/delayed-inode.c
57656 @@ -459,7 +459,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
57657
57658 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
57659 {
57660 - int seq = atomic_inc_return(&delayed_root->items_seq);
57661 + int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
57662 if ((atomic_dec_return(&delayed_root->items) <
57663 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
57664 waitqueue_active(&delayed_root->wait))
57665 @@ -1409,7 +1409,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
57666
57667 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
57668 {
57669 - int val = atomic_read(&delayed_root->items_seq);
57670 + int val = atomic_read_unchecked(&delayed_root->items_seq);
57671
57672 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
57673 return 1;
57674 @@ -1433,7 +1433,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
57675 int seq;
57676 int ret;
57677
57678 - seq = atomic_read(&delayed_root->items_seq);
57679 + seq = atomic_read_unchecked(&delayed_root->items_seq);
57680
57681 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
57682 if (ret)
57683 diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
57684 index f70119f..ab5894d 100644
57685 --- a/fs/btrfs/delayed-inode.h
57686 +++ b/fs/btrfs/delayed-inode.h
57687 @@ -43,7 +43,7 @@ struct btrfs_delayed_root {
57688 */
57689 struct list_head prepare_list;
57690 atomic_t items; /* for delayed items */
57691 - atomic_t items_seq; /* for delayed items */
57692 + atomic_unchecked_t items_seq; /* for delayed items */
57693 int nodes; /* for delayed nodes */
57694 wait_queue_head_t wait;
57695 };
57696 @@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
57697 struct btrfs_delayed_root *delayed_root)
57698 {
57699 atomic_set(&delayed_root->items, 0);
57700 - atomic_set(&delayed_root->items_seq, 0);
57701 + atomic_set_unchecked(&delayed_root->items_seq, 0);
57702 delayed_root->nodes = 0;
57703 spin_lock_init(&delayed_root->lock);
57704 init_waitqueue_head(&delayed_root->wait);
57705 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
57706 index 2f6d7b1..f186382 100644
57707 --- a/fs/btrfs/ioctl.c
57708 +++ b/fs/btrfs/ioctl.c
57709 @@ -3575,9 +3575,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57710 for (i = 0; i < num_types; i++) {
57711 struct btrfs_space_info *tmp;
57712
57713 + /* Don't copy in more than we allocated */
57714 if (!slot_count)
57715 break;
57716
57717 + slot_count--;
57718 +
57719 info = NULL;
57720 rcu_read_lock();
57721 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
57722 @@ -3599,10 +3602,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57723 memcpy(dest, &space, sizeof(space));
57724 dest++;
57725 space_args.total_spaces++;
57726 - slot_count--;
57727 }
57728 - if (!slot_count)
57729 - break;
57730 }
57731 up_read(&info->groups_sem);
57732 }
57733 diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
57734 index 9601d25..2896d6c 100644
57735 --- a/fs/btrfs/super.c
57736 +++ b/fs/btrfs/super.c
57737 @@ -270,7 +270,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
57738 function, line, errstr);
57739 return;
57740 }
57741 - ACCESS_ONCE(trans->transaction->aborted) = errno;
57742 + ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
57743 /* Wake up anybody who may be waiting on this transaction */
57744 wake_up(&root->fs_info->transaction_wait);
57745 wake_up(&root->fs_info->transaction_blocked_wait);
57746 diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
57747 index 4825cd2..b2fe768 100644
57748 --- a/fs/btrfs/sysfs.c
57749 +++ b/fs/btrfs/sysfs.c
57750 @@ -438,7 +438,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
57751 for (set = 0; set < FEAT_MAX; set++) {
57752 int i;
57753 struct attribute *attrs[2];
57754 - struct attribute_group agroup = {
57755 + attribute_group_no_const agroup = {
57756 .name = "features",
57757 .attrs = attrs,
57758 };
57759 diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
57760 index e2f45fc..b036909 100644
57761 --- a/fs/btrfs/tree-log.c
57762 +++ b/fs/btrfs/tree-log.c
57763 @@ -2533,7 +2533,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57764 blk_finish_plug(&plug);
57765 btrfs_abort_transaction(trans, root, ret);
57766 btrfs_free_logged_extents(log, log_transid);
57767 - ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57768 + ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57769 trans->transid;
57770 mutex_unlock(&root->log_mutex);
57771 goto out;
57772 @@ -2577,7 +2577,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57773 list_del_init(&root_log_ctx.list);
57774
57775 blk_finish_plug(&plug);
57776 - ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57777 + ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57778 trans->transid;
57779 if (ret != -ENOSPC) {
57780 btrfs_abort_transaction(trans, root, ret);
57781 @@ -2622,7 +2622,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57782 * now that we've moved on to the tree of log tree roots,
57783 * check the full commit flag again
57784 */
57785 - if (ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) ==
57786 + if (ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) ==
57787 trans->transid) {
57788 blk_finish_plug(&plug);
57789 btrfs_wait_marked_extents(log, &log->dirty_log_pages, mark);
57790 @@ -2637,7 +2637,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57791 EXTENT_DIRTY | EXTENT_NEW);
57792 blk_finish_plug(&plug);
57793 if (ret) {
57794 - ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57795 + ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57796 trans->transid;
57797 btrfs_abort_transaction(trans, root, ret);
57798 btrfs_free_logged_extents(log, log_transid);
57799 @@ -2667,7 +2667,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57800 */
57801 ret = write_ctree_super(trans, root->fs_info->tree_root, 1);
57802 if (ret) {
57803 - ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57804 + ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57805 trans->transid;
57806 btrfs_abort_transaction(trans, root, ret);
57807 goto out_wake_log_root;
57808 diff --git a/fs/buffer.c b/fs/buffer.c
57809 index 9ddb9fc..7aa2487 100644
57810 --- a/fs/buffer.c
57811 +++ b/fs/buffer.c
57812 @@ -3428,7 +3428,7 @@ void __init buffer_init(void)
57813 bh_cachep = kmem_cache_create("buffer_head",
57814 sizeof(struct buffer_head), 0,
57815 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
57816 - SLAB_MEM_SPREAD),
57817 + SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
57818 NULL);
57819
57820 /*
57821 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
57822 index 5b99baf..47fffb5 100644
57823 --- a/fs/cachefiles/bind.c
57824 +++ b/fs/cachefiles/bind.c
57825 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
57826 args);
57827
57828 /* start by checking things over */
57829 - ASSERT(cache->fstop_percent >= 0 &&
57830 - cache->fstop_percent < cache->fcull_percent &&
57831 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
57832 cache->fcull_percent < cache->frun_percent &&
57833 cache->frun_percent < 100);
57834
57835 - ASSERT(cache->bstop_percent >= 0 &&
57836 - cache->bstop_percent < cache->bcull_percent &&
57837 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
57838 cache->bcull_percent < cache->brun_percent &&
57839 cache->brun_percent < 100);
57840
57841 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
57842 index 0a1467b..6a53245 100644
57843 --- a/fs/cachefiles/daemon.c
57844 +++ b/fs/cachefiles/daemon.c
57845 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
57846 if (n > buflen)
57847 return -EMSGSIZE;
57848
57849 - if (copy_to_user(_buffer, buffer, n) != 0)
57850 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
57851 return -EFAULT;
57852
57853 return n;
57854 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
57855 if (test_bit(CACHEFILES_DEAD, &cache->flags))
57856 return -EIO;
57857
57858 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
57859 + if (datalen > PAGE_SIZE - 1)
57860 return -EOPNOTSUPP;
57861
57862 /* drag the command string into the kernel so we can parse it */
57863 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
57864 if (args[0] != '%' || args[1] != '\0')
57865 return -EINVAL;
57866
57867 - if (fstop < 0 || fstop >= cache->fcull_percent)
57868 + if (fstop >= cache->fcull_percent)
57869 return cachefiles_daemon_range_error(cache, args);
57870
57871 cache->fstop_percent = fstop;
57872 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
57873 if (args[0] != '%' || args[1] != '\0')
57874 return -EINVAL;
57875
57876 - if (bstop < 0 || bstop >= cache->bcull_percent)
57877 + if (bstop >= cache->bcull_percent)
57878 return cachefiles_daemon_range_error(cache, args);
57879
57880 cache->bstop_percent = bstop;
57881 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
57882 index 5349473..d6c0b93 100644
57883 --- a/fs/cachefiles/internal.h
57884 +++ b/fs/cachefiles/internal.h
57885 @@ -59,7 +59,7 @@ struct cachefiles_cache {
57886 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
57887 struct rb_root active_nodes; /* active nodes (can't be culled) */
57888 rwlock_t active_lock; /* lock for active_nodes */
57889 - atomic_t gravecounter; /* graveyard uniquifier */
57890 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
57891 unsigned frun_percent; /* when to stop culling (% files) */
57892 unsigned fcull_percent; /* when to start culling (% files) */
57893 unsigned fstop_percent; /* when to stop allocating (% files) */
57894 @@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
57895 * proc.c
57896 */
57897 #ifdef CONFIG_CACHEFILES_HISTOGRAM
57898 -extern atomic_t cachefiles_lookup_histogram[HZ];
57899 -extern atomic_t cachefiles_mkdir_histogram[HZ];
57900 -extern atomic_t cachefiles_create_histogram[HZ];
57901 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57902 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57903 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
57904
57905 extern int __init cachefiles_proc_init(void);
57906 extern void cachefiles_proc_cleanup(void);
57907 static inline
57908 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
57909 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
57910 {
57911 unsigned long jif = jiffies - start_jif;
57912 if (jif >= HZ)
57913 jif = HZ - 1;
57914 - atomic_inc(&histogram[jif]);
57915 + atomic_inc_unchecked(&histogram[jif]);
57916 }
57917
57918 #else
57919 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
57920 index c0a6817..ea811166 100644
57921 --- a/fs/cachefiles/namei.c
57922 +++ b/fs/cachefiles/namei.c
57923 @@ -317,7 +317,7 @@ try_again:
57924 /* first step is to make up a grave dentry in the graveyard */
57925 sprintf(nbuffer, "%08x%08x",
57926 (uint32_t) get_seconds(),
57927 - (uint32_t) atomic_inc_return(&cache->gravecounter));
57928 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
57929
57930 /* do the multiway lock magic */
57931 trap = lock_rename(cache->graveyard, dir);
57932 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
57933 index eccd339..4c1d995 100644
57934 --- a/fs/cachefiles/proc.c
57935 +++ b/fs/cachefiles/proc.c
57936 @@ -14,9 +14,9 @@
57937 #include <linux/seq_file.h>
57938 #include "internal.h"
57939
57940 -atomic_t cachefiles_lookup_histogram[HZ];
57941 -atomic_t cachefiles_mkdir_histogram[HZ];
57942 -atomic_t cachefiles_create_histogram[HZ];
57943 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57944 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57945 +atomic_unchecked_t cachefiles_create_histogram[HZ];
57946
57947 /*
57948 * display the latency histogram
57949 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
57950 return 0;
57951 default:
57952 index = (unsigned long) v - 3;
57953 - x = atomic_read(&cachefiles_lookup_histogram[index]);
57954 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
57955 - z = atomic_read(&cachefiles_create_histogram[index]);
57956 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
57957 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
57958 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
57959 if (x == 0 && y == 0 && z == 0)
57960 return 0;
57961
57962 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
57963 index 4b1fb5c..0d2a699 100644
57964 --- a/fs/cachefiles/rdwr.c
57965 +++ b/fs/cachefiles/rdwr.c
57966 @@ -943,7 +943,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
57967 old_fs = get_fs();
57968 set_fs(KERNEL_DS);
57969 ret = file->f_op->write(
57970 - file, (const void __user *) data, len, &pos);
57971 + file, (const void __force_user *) data, len, &pos);
57972 set_fs(old_fs);
57973 kunmap(page);
57974 file_end_write(file);
57975 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
57976 index c29d6ae..a56c4ae 100644
57977 --- a/fs/ceph/dir.c
57978 +++ b/fs/ceph/dir.c
57979 @@ -250,7 +250,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
57980 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
57981 struct ceph_mds_client *mdsc = fsc->mdsc;
57982 unsigned frag = fpos_frag(ctx->pos);
57983 - int off = fpos_off(ctx->pos);
57984 + unsigned int off = fpos_off(ctx->pos);
57985 int err;
57986 u32 ftype;
57987 struct ceph_mds_reply_info_parsed *rinfo;
57988 diff --git a/fs/ceph/super.c b/fs/ceph/super.c
57989 index 06150fd..192061b 100644
57990 --- a/fs/ceph/super.c
57991 +++ b/fs/ceph/super.c
57992 @@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
57993 /*
57994 * construct our own bdi so we can control readahead, etc.
57995 */
57996 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
57997 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
57998
57999 static int ceph_register_bdi(struct super_block *sb,
58000 struct ceph_fs_client *fsc)
58001 @@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
58002 default_backing_dev_info.ra_pages;
58003
58004 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
58005 - atomic_long_inc_return(&bdi_seq));
58006 + atomic_long_inc_return_unchecked(&bdi_seq));
58007 if (!err)
58008 sb->s_bdi = &fsc->backing_dev_info;
58009 return err;
58010 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
58011 index f3ac415..3d2420c 100644
58012 --- a/fs/cifs/cifs_debug.c
58013 +++ b/fs/cifs/cifs_debug.c
58014 @@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
58015
58016 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
58017 #ifdef CONFIG_CIFS_STATS2
58018 - atomic_set(&totBufAllocCount, 0);
58019 - atomic_set(&totSmBufAllocCount, 0);
58020 + atomic_set_unchecked(&totBufAllocCount, 0);
58021 + atomic_set_unchecked(&totSmBufAllocCount, 0);
58022 #endif /* CONFIG_CIFS_STATS2 */
58023 spin_lock(&cifs_tcp_ses_lock);
58024 list_for_each(tmp1, &cifs_tcp_ses_list) {
58025 @@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
58026 tcon = list_entry(tmp3,
58027 struct cifs_tcon,
58028 tcon_list);
58029 - atomic_set(&tcon->num_smbs_sent, 0);
58030 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
58031 if (server->ops->clear_stats)
58032 server->ops->clear_stats(tcon);
58033 }
58034 @@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
58035 smBufAllocCount.counter, cifs_min_small);
58036 #ifdef CONFIG_CIFS_STATS2
58037 seq_printf(m, "Total Large %d Small %d Allocations\n",
58038 - atomic_read(&totBufAllocCount),
58039 - atomic_read(&totSmBufAllocCount));
58040 + atomic_read_unchecked(&totBufAllocCount),
58041 + atomic_read_unchecked(&totSmBufAllocCount));
58042 #endif /* CONFIG_CIFS_STATS2 */
58043
58044 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
58045 @@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
58046 if (tcon->need_reconnect)
58047 seq_puts(m, "\tDISCONNECTED ");
58048 seq_printf(m, "\nSMBs: %d",
58049 - atomic_read(&tcon->num_smbs_sent));
58050 + atomic_read_unchecked(&tcon->num_smbs_sent));
58051 if (server->ops->print_stats)
58052 server->ops->print_stats(m, tcon);
58053 }
58054 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
58055 index 5be1f997..fa1015a1 100644
58056 --- a/fs/cifs/cifsfs.c
58057 +++ b/fs/cifs/cifsfs.c
58058 @@ -1068,7 +1068,7 @@ cifs_init_request_bufs(void)
58059 */
58060 cifs_req_cachep = kmem_cache_create("cifs_request",
58061 CIFSMaxBufSize + max_hdr_size, 0,
58062 - SLAB_HWCACHE_ALIGN, NULL);
58063 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
58064 if (cifs_req_cachep == NULL)
58065 return -ENOMEM;
58066
58067 @@ -1095,7 +1095,7 @@ cifs_init_request_bufs(void)
58068 efficient to alloc 1 per page off the slab compared to 17K (5page)
58069 alloc of large cifs buffers even when page debugging is on */
58070 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
58071 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
58072 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
58073 NULL);
58074 if (cifs_sm_req_cachep == NULL) {
58075 mempool_destroy(cifs_req_poolp);
58076 @@ -1180,8 +1180,8 @@ init_cifs(void)
58077 atomic_set(&bufAllocCount, 0);
58078 atomic_set(&smBufAllocCount, 0);
58079 #ifdef CONFIG_CIFS_STATS2
58080 - atomic_set(&totBufAllocCount, 0);
58081 - atomic_set(&totSmBufAllocCount, 0);
58082 + atomic_set_unchecked(&totBufAllocCount, 0);
58083 + atomic_set_unchecked(&totSmBufAllocCount, 0);
58084 #endif /* CONFIG_CIFS_STATS2 */
58085
58086 atomic_set(&midCount, 0);
58087 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
58088 index 30f6e92..e915ba5 100644
58089 --- a/fs/cifs/cifsglob.h
58090 +++ b/fs/cifs/cifsglob.h
58091 @@ -806,35 +806,35 @@ struct cifs_tcon {
58092 __u16 Flags; /* optional support bits */
58093 enum statusEnum tidStatus;
58094 #ifdef CONFIG_CIFS_STATS
58095 - atomic_t num_smbs_sent;
58096 + atomic_unchecked_t num_smbs_sent;
58097 union {
58098 struct {
58099 - atomic_t num_writes;
58100 - atomic_t num_reads;
58101 - atomic_t num_flushes;
58102 - atomic_t num_oplock_brks;
58103 - atomic_t num_opens;
58104 - atomic_t num_closes;
58105 - atomic_t num_deletes;
58106 - atomic_t num_mkdirs;
58107 - atomic_t num_posixopens;
58108 - atomic_t num_posixmkdirs;
58109 - atomic_t num_rmdirs;
58110 - atomic_t num_renames;
58111 - atomic_t num_t2renames;
58112 - atomic_t num_ffirst;
58113 - atomic_t num_fnext;
58114 - atomic_t num_fclose;
58115 - atomic_t num_hardlinks;
58116 - atomic_t num_symlinks;
58117 - atomic_t num_locks;
58118 - atomic_t num_acl_get;
58119 - atomic_t num_acl_set;
58120 + atomic_unchecked_t num_writes;
58121 + atomic_unchecked_t num_reads;
58122 + atomic_unchecked_t num_flushes;
58123 + atomic_unchecked_t num_oplock_brks;
58124 + atomic_unchecked_t num_opens;
58125 + atomic_unchecked_t num_closes;
58126 + atomic_unchecked_t num_deletes;
58127 + atomic_unchecked_t num_mkdirs;
58128 + atomic_unchecked_t num_posixopens;
58129 + atomic_unchecked_t num_posixmkdirs;
58130 + atomic_unchecked_t num_rmdirs;
58131 + atomic_unchecked_t num_renames;
58132 + atomic_unchecked_t num_t2renames;
58133 + atomic_unchecked_t num_ffirst;
58134 + atomic_unchecked_t num_fnext;
58135 + atomic_unchecked_t num_fclose;
58136 + atomic_unchecked_t num_hardlinks;
58137 + atomic_unchecked_t num_symlinks;
58138 + atomic_unchecked_t num_locks;
58139 + atomic_unchecked_t num_acl_get;
58140 + atomic_unchecked_t num_acl_set;
58141 } cifs_stats;
58142 #ifdef CONFIG_CIFS_SMB2
58143 struct {
58144 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
58145 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
58146 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
58147 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
58148 } smb2_stats;
58149 #endif /* CONFIG_CIFS_SMB2 */
58150 } stats;
58151 @@ -1170,7 +1170,7 @@ convert_delimiter(char *path, char delim)
58152 }
58153
58154 #ifdef CONFIG_CIFS_STATS
58155 -#define cifs_stats_inc atomic_inc
58156 +#define cifs_stats_inc atomic_inc_unchecked
58157
58158 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
58159 unsigned int bytes)
58160 @@ -1536,8 +1536,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
58161 /* Various Debug counters */
58162 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
58163 #ifdef CONFIG_CIFS_STATS2
58164 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
58165 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
58166 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
58167 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
58168 #endif
58169 GLOBAL_EXTERN atomic_t smBufAllocCount;
58170 GLOBAL_EXTERN atomic_t midCount;
58171 diff --git a/fs/cifs/file.c b/fs/cifs/file.c
58172 index 5ed03e0..e9a3a6c 100644
58173 --- a/fs/cifs/file.c
58174 +++ b/fs/cifs/file.c
58175 @@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
58176 index = mapping->writeback_index; /* Start from prev offset */
58177 end = -1;
58178 } else {
58179 - index = wbc->range_start >> PAGE_CACHE_SHIFT;
58180 - end = wbc->range_end >> PAGE_CACHE_SHIFT;
58181 - if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
58182 + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
58183 range_whole = true;
58184 + index = 0;
58185 + end = ULONG_MAX;
58186 + } else {
58187 + index = wbc->range_start >> PAGE_CACHE_SHIFT;
58188 + end = wbc->range_end >> PAGE_CACHE_SHIFT;
58189 + }
58190 scanned = true;
58191 }
58192 retry:
58193 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
58194 index 3b0c62e..f7d090c 100644
58195 --- a/fs/cifs/misc.c
58196 +++ b/fs/cifs/misc.c
58197 @@ -170,7 +170,7 @@ cifs_buf_get(void)
58198 memset(ret_buf, 0, buf_size + 3);
58199 atomic_inc(&bufAllocCount);
58200 #ifdef CONFIG_CIFS_STATS2
58201 - atomic_inc(&totBufAllocCount);
58202 + atomic_inc_unchecked(&totBufAllocCount);
58203 #endif /* CONFIG_CIFS_STATS2 */
58204 }
58205
58206 @@ -205,7 +205,7 @@ cifs_small_buf_get(void)
58207 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
58208 atomic_inc(&smBufAllocCount);
58209 #ifdef CONFIG_CIFS_STATS2
58210 - atomic_inc(&totSmBufAllocCount);
58211 + atomic_inc_unchecked(&totSmBufAllocCount);
58212 #endif /* CONFIG_CIFS_STATS2 */
58213
58214 }
58215 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
58216 index d1fdfa8..94558f8 100644
58217 --- a/fs/cifs/smb1ops.c
58218 +++ b/fs/cifs/smb1ops.c
58219 @@ -626,27 +626,27 @@ static void
58220 cifs_clear_stats(struct cifs_tcon *tcon)
58221 {
58222 #ifdef CONFIG_CIFS_STATS
58223 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
58224 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
58225 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
58226 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
58227 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
58228 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
58229 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
58230 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
58231 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
58232 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
58233 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
58234 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
58235 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
58236 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
58237 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
58238 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
58239 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
58240 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
58241 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
58242 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
58243 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
58244 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
58245 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
58246 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
58247 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
58248 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
58249 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
58250 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
58251 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
58252 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
58253 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
58254 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
58255 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
58256 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
58257 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
58258 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
58259 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
58260 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
58261 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
58262 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
58263 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
58264 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
58265 #endif
58266 }
58267
58268 @@ -655,36 +655,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
58269 {
58270 #ifdef CONFIG_CIFS_STATS
58271 seq_printf(m, " Oplocks breaks: %d",
58272 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
58273 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
58274 seq_printf(m, "\nReads: %d Bytes: %llu",
58275 - atomic_read(&tcon->stats.cifs_stats.num_reads),
58276 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
58277 (long long)(tcon->bytes_read));
58278 seq_printf(m, "\nWrites: %d Bytes: %llu",
58279 - atomic_read(&tcon->stats.cifs_stats.num_writes),
58280 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
58281 (long long)(tcon->bytes_written));
58282 seq_printf(m, "\nFlushes: %d",
58283 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
58284 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
58285 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
58286 - atomic_read(&tcon->stats.cifs_stats.num_locks),
58287 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
58288 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
58289 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
58290 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
58291 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
58292 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
58293 - atomic_read(&tcon->stats.cifs_stats.num_opens),
58294 - atomic_read(&tcon->stats.cifs_stats.num_closes),
58295 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
58296 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
58297 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
58298 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
58299 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
58300 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
58301 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
58302 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
58303 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
58304 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
58305 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
58306 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
58307 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
58308 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
58309 seq_printf(m, "\nRenames: %d T2 Renames %d",
58310 - atomic_read(&tcon->stats.cifs_stats.num_renames),
58311 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
58312 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
58313 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
58314 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
58315 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
58316 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
58317 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
58318 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
58319 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
58320 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
58321 #endif
58322 }
58323
58324 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
58325 index 35ddc3e..563e809 100644
58326 --- a/fs/cifs/smb2ops.c
58327 +++ b/fs/cifs/smb2ops.c
58328 @@ -364,8 +364,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
58329 #ifdef CONFIG_CIFS_STATS
58330 int i;
58331 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
58332 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
58333 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
58334 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
58335 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
58336 }
58337 #endif
58338 }
58339 @@ -405,65 +405,65 @@ static void
58340 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
58341 {
58342 #ifdef CONFIG_CIFS_STATS
58343 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
58344 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
58345 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
58346 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
58347 seq_printf(m, "\nNegotiates: %d sent %d failed",
58348 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
58349 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
58350 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
58351 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
58352 seq_printf(m, "\nSessionSetups: %d sent %d failed",
58353 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
58354 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
58355 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
58356 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
58357 seq_printf(m, "\nLogoffs: %d sent %d failed",
58358 - atomic_read(&sent[SMB2_LOGOFF_HE]),
58359 - atomic_read(&failed[SMB2_LOGOFF_HE]));
58360 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
58361 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
58362 seq_printf(m, "\nTreeConnects: %d sent %d failed",
58363 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
58364 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
58365 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
58366 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
58367 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
58368 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
58369 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
58370 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
58371 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
58372 seq_printf(m, "\nCreates: %d sent %d failed",
58373 - atomic_read(&sent[SMB2_CREATE_HE]),
58374 - atomic_read(&failed[SMB2_CREATE_HE]));
58375 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
58376 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
58377 seq_printf(m, "\nCloses: %d sent %d failed",
58378 - atomic_read(&sent[SMB2_CLOSE_HE]),
58379 - atomic_read(&failed[SMB2_CLOSE_HE]));
58380 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
58381 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
58382 seq_printf(m, "\nFlushes: %d sent %d failed",
58383 - atomic_read(&sent[SMB2_FLUSH_HE]),
58384 - atomic_read(&failed[SMB2_FLUSH_HE]));
58385 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
58386 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
58387 seq_printf(m, "\nReads: %d sent %d failed",
58388 - atomic_read(&sent[SMB2_READ_HE]),
58389 - atomic_read(&failed[SMB2_READ_HE]));
58390 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
58391 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
58392 seq_printf(m, "\nWrites: %d sent %d failed",
58393 - atomic_read(&sent[SMB2_WRITE_HE]),
58394 - atomic_read(&failed[SMB2_WRITE_HE]));
58395 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
58396 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
58397 seq_printf(m, "\nLocks: %d sent %d failed",
58398 - atomic_read(&sent[SMB2_LOCK_HE]),
58399 - atomic_read(&failed[SMB2_LOCK_HE]));
58400 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
58401 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
58402 seq_printf(m, "\nIOCTLs: %d sent %d failed",
58403 - atomic_read(&sent[SMB2_IOCTL_HE]),
58404 - atomic_read(&failed[SMB2_IOCTL_HE]));
58405 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
58406 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
58407 seq_printf(m, "\nCancels: %d sent %d failed",
58408 - atomic_read(&sent[SMB2_CANCEL_HE]),
58409 - atomic_read(&failed[SMB2_CANCEL_HE]));
58410 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
58411 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
58412 seq_printf(m, "\nEchos: %d sent %d failed",
58413 - atomic_read(&sent[SMB2_ECHO_HE]),
58414 - atomic_read(&failed[SMB2_ECHO_HE]));
58415 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
58416 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
58417 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
58418 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
58419 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
58420 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
58421 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
58422 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
58423 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
58424 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
58425 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
58426 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
58427 seq_printf(m, "\nQueryInfos: %d sent %d failed",
58428 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
58429 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
58430 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
58431 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
58432 seq_printf(m, "\nSetInfos: %d sent %d failed",
58433 - atomic_read(&sent[SMB2_SET_INFO_HE]),
58434 - atomic_read(&failed[SMB2_SET_INFO_HE]));
58435 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
58436 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
58437 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
58438 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
58439 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
58440 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
58441 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
58442 #endif
58443 }
58444
58445 diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
58446 index 1fb6ad2..758e171 100644
58447 --- a/fs/cifs/smb2pdu.c
58448 +++ b/fs/cifs/smb2pdu.c
58449 @@ -2097,8 +2097,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
58450 default:
58451 cifs_dbg(VFS, "info level %u isn't supported\n",
58452 srch_inf->info_level);
58453 - rc = -EINVAL;
58454 - goto qdir_exit;
58455 + return -EINVAL;
58456 }
58457
58458 req->FileIndex = cpu_to_le32(index);
58459 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
58460 index 1da168c..8bc7ff6 100644
58461 --- a/fs/coda/cache.c
58462 +++ b/fs/coda/cache.c
58463 @@ -24,7 +24,7 @@
58464 #include "coda_linux.h"
58465 #include "coda_cache.h"
58466
58467 -static atomic_t permission_epoch = ATOMIC_INIT(0);
58468 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
58469
58470 /* replace or extend an acl cache hit */
58471 void coda_cache_enter(struct inode *inode, int mask)
58472 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
58473 struct coda_inode_info *cii = ITOC(inode);
58474
58475 spin_lock(&cii->c_lock);
58476 - cii->c_cached_epoch = atomic_read(&permission_epoch);
58477 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
58478 if (!uid_eq(cii->c_uid, current_fsuid())) {
58479 cii->c_uid = current_fsuid();
58480 cii->c_cached_perm = mask;
58481 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
58482 {
58483 struct coda_inode_info *cii = ITOC(inode);
58484 spin_lock(&cii->c_lock);
58485 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
58486 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
58487 spin_unlock(&cii->c_lock);
58488 }
58489
58490 /* remove all acl caches */
58491 void coda_cache_clear_all(struct super_block *sb)
58492 {
58493 - atomic_inc(&permission_epoch);
58494 + atomic_inc_unchecked(&permission_epoch);
58495 }
58496
58497
58498 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
58499 spin_lock(&cii->c_lock);
58500 hit = (mask & cii->c_cached_perm) == mask &&
58501 uid_eq(cii->c_uid, current_fsuid()) &&
58502 - cii->c_cached_epoch == atomic_read(&permission_epoch);
58503 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
58504 spin_unlock(&cii->c_lock);
58505
58506 return hit;
58507 diff --git a/fs/compat.c b/fs/compat.c
58508 index 66d3d3c..9c10175 100644
58509 --- a/fs/compat.c
58510 +++ b/fs/compat.c
58511 @@ -54,7 +54,7 @@
58512 #include <asm/ioctls.h>
58513 #include "internal.h"
58514
58515 -int compat_log = 1;
58516 +int compat_log = 0;
58517
58518 int compat_printk(const char *fmt, ...)
58519 {
58520 @@ -512,7 +512,7 @@ COMPAT_SYSCALL_DEFINE2(io_setup, unsigned, nr_reqs, u32 __user *, ctx32p)
58521
58522 set_fs(KERNEL_DS);
58523 /* The __user pointer cast is valid because of the set_fs() */
58524 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
58525 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
58526 set_fs(oldfs);
58527 /* truncating is ok because it's a user address */
58528 if (!ret)
58529 @@ -562,7 +562,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
58530 goto out;
58531
58532 ret = -EINVAL;
58533 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
58534 + if (nr_segs > UIO_MAXIOV)
58535 goto out;
58536 if (nr_segs > fast_segs) {
58537 ret = -ENOMEM;
58538 @@ -850,6 +850,7 @@ struct compat_old_linux_dirent {
58539 struct compat_readdir_callback {
58540 struct dir_context ctx;
58541 struct compat_old_linux_dirent __user *dirent;
58542 + struct file * file;
58543 int result;
58544 };
58545
58546 @@ -867,6 +868,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
58547 buf->result = -EOVERFLOW;
58548 return -EOVERFLOW;
58549 }
58550 +
58551 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58552 + return 0;
58553 +
58554 buf->result++;
58555 dirent = buf->dirent;
58556 if (!access_ok(VERIFY_WRITE, dirent,
58557 @@ -898,6 +903,7 @@ COMPAT_SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
58558 if (!f.file)
58559 return -EBADF;
58560
58561 + buf.file = f.file;
58562 error = iterate_dir(f.file, &buf.ctx);
58563 if (buf.result)
58564 error = buf.result;
58565 @@ -917,6 +923,7 @@ struct compat_getdents_callback {
58566 struct dir_context ctx;
58567 struct compat_linux_dirent __user *current_dir;
58568 struct compat_linux_dirent __user *previous;
58569 + struct file * file;
58570 int count;
58571 int error;
58572 };
58573 @@ -938,6 +945,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
58574 buf->error = -EOVERFLOW;
58575 return -EOVERFLOW;
58576 }
58577 +
58578 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58579 + return 0;
58580 +
58581 dirent = buf->previous;
58582 if (dirent) {
58583 if (__put_user(offset, &dirent->d_off))
58584 @@ -983,6 +994,7 @@ COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd,
58585 if (!f.file)
58586 return -EBADF;
58587
58588 + buf.file = f.file;
58589 error = iterate_dir(f.file, &buf.ctx);
58590 if (error >= 0)
58591 error = buf.error;
58592 @@ -1003,6 +1015,7 @@ struct compat_getdents_callback64 {
58593 struct dir_context ctx;
58594 struct linux_dirent64 __user *current_dir;
58595 struct linux_dirent64 __user *previous;
58596 + struct file * file;
58597 int count;
58598 int error;
58599 };
58600 @@ -1019,6 +1032,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
58601 buf->error = -EINVAL; /* only used if we fail.. */
58602 if (reclen > buf->count)
58603 return -EINVAL;
58604 +
58605 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58606 + return 0;
58607 +
58608 dirent = buf->previous;
58609
58610 if (dirent) {
58611 @@ -1068,6 +1085,7 @@ COMPAT_SYSCALL_DEFINE3(getdents64, unsigned int, fd,
58612 if (!f.file)
58613 return -EBADF;
58614
58615 + buf.file = f.file;
58616 error = iterate_dir(f.file, &buf.ctx);
58617 if (error >= 0)
58618 error = buf.error;
58619 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
58620 index 4d24d17..4f8c09e 100644
58621 --- a/fs/compat_binfmt_elf.c
58622 +++ b/fs/compat_binfmt_elf.c
58623 @@ -30,11 +30,13 @@
58624 #undef elf_phdr
58625 #undef elf_shdr
58626 #undef elf_note
58627 +#undef elf_dyn
58628 #undef elf_addr_t
58629 #define elfhdr elf32_hdr
58630 #define elf_phdr elf32_phdr
58631 #define elf_shdr elf32_shdr
58632 #define elf_note elf32_note
58633 +#define elf_dyn Elf32_Dyn
58634 #define elf_addr_t Elf32_Addr
58635
58636 /*
58637 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
58638 index e822890..fed89d9 100644
58639 --- a/fs/compat_ioctl.c
58640 +++ b/fs/compat_ioctl.c
58641 @@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
58642 return -EFAULT;
58643 if (__get_user(udata, &ss32->iomem_base))
58644 return -EFAULT;
58645 - ss.iomem_base = compat_ptr(udata);
58646 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
58647 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
58648 __get_user(ss.port_high, &ss32->port_high))
58649 return -EFAULT;
58650 @@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
58651 for (i = 0; i < nmsgs; i++) {
58652 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
58653 return -EFAULT;
58654 - if (get_user(datap, &umsgs[i].buf) ||
58655 - put_user(compat_ptr(datap), &tmsgs[i].buf))
58656 + if (get_user(datap, (compat_caddr_t __user *)&umsgs[i].buf) ||
58657 + put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
58658 return -EFAULT;
58659 }
58660 return sys_ioctl(fd, cmd, (unsigned long)tdata);
58661 @@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
58662 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
58663 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
58664 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
58665 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
58666 + copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
58667 return -EFAULT;
58668
58669 return ioctl_preallocate(file, p);
58670 @@ -1618,8 +1618,8 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
58671 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
58672 {
58673 unsigned int a, b;
58674 - a = *(unsigned int *)p;
58675 - b = *(unsigned int *)q;
58676 + a = *(const unsigned int *)p;
58677 + b = *(const unsigned int *)q;
58678 if (a > b)
58679 return 1;
58680 if (a < b)
58681 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
58682 index e081acb..911df21 100644
58683 --- a/fs/configfs/dir.c
58684 +++ b/fs/configfs/dir.c
58685 @@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58686 }
58687 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
58688 struct configfs_dirent *next;
58689 - const char *name;
58690 + const unsigned char * name;
58691 + char d_name[sizeof(next->s_dentry->d_iname)];
58692 int len;
58693 struct inode *inode = NULL;
58694
58695 @@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58696 continue;
58697
58698 name = configfs_get_name(next);
58699 - len = strlen(name);
58700 + if (next->s_dentry && name == next->s_dentry->d_iname) {
58701 + len = next->s_dentry->d_name.len;
58702 + memcpy(d_name, name, len);
58703 + name = d_name;
58704 + } else
58705 + len = strlen(name);
58706
58707 /*
58708 * We'll have a dentry and an inode for
58709 diff --git a/fs/coredump.c b/fs/coredump.c
58710 index a93f7e6..d58bcbe 100644
58711 --- a/fs/coredump.c
58712 +++ b/fs/coredump.c
58713 @@ -442,8 +442,8 @@ static void wait_for_dump_helpers(struct file *file)
58714 struct pipe_inode_info *pipe = file->private_data;
58715
58716 pipe_lock(pipe);
58717 - pipe->readers++;
58718 - pipe->writers--;
58719 + atomic_inc(&pipe->readers);
58720 + atomic_dec(&pipe->writers);
58721 wake_up_interruptible_sync(&pipe->wait);
58722 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58723 pipe_unlock(pipe);
58724 @@ -452,11 +452,11 @@ static void wait_for_dump_helpers(struct file *file)
58725 * We actually want wait_event_freezable() but then we need
58726 * to clear TIF_SIGPENDING and improve dump_interrupted().
58727 */
58728 - wait_event_interruptible(pipe->wait, pipe->readers == 1);
58729 + wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
58730
58731 pipe_lock(pipe);
58732 - pipe->readers--;
58733 - pipe->writers++;
58734 + atomic_dec(&pipe->readers);
58735 + atomic_inc(&pipe->writers);
58736 pipe_unlock(pipe);
58737 }
58738
58739 @@ -503,7 +503,9 @@ void do_coredump(const siginfo_t *siginfo)
58740 struct files_struct *displaced;
58741 bool need_nonrelative = false;
58742 bool core_dumped = false;
58743 - static atomic_t core_dump_count = ATOMIC_INIT(0);
58744 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
58745 + long signr = siginfo->si_signo;
58746 + int dumpable;
58747 struct coredump_params cprm = {
58748 .siginfo = siginfo,
58749 .regs = signal_pt_regs(),
58750 @@ -516,12 +518,17 @@ void do_coredump(const siginfo_t *siginfo)
58751 .mm_flags = mm->flags,
58752 };
58753
58754 - audit_core_dumps(siginfo->si_signo);
58755 + audit_core_dumps(signr);
58756 +
58757 + dumpable = __get_dumpable(cprm.mm_flags);
58758 +
58759 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
58760 + gr_handle_brute_attach(dumpable);
58761
58762 binfmt = mm->binfmt;
58763 if (!binfmt || !binfmt->core_dump)
58764 goto fail;
58765 - if (!__get_dumpable(cprm.mm_flags))
58766 + if (!dumpable)
58767 goto fail;
58768
58769 cred = prepare_creds();
58770 @@ -540,7 +547,7 @@ void do_coredump(const siginfo_t *siginfo)
58771 need_nonrelative = true;
58772 }
58773
58774 - retval = coredump_wait(siginfo->si_signo, &core_state);
58775 + retval = coredump_wait(signr, &core_state);
58776 if (retval < 0)
58777 goto fail_creds;
58778
58779 @@ -583,7 +590,7 @@ void do_coredump(const siginfo_t *siginfo)
58780 }
58781 cprm.limit = RLIM_INFINITY;
58782
58783 - dump_count = atomic_inc_return(&core_dump_count);
58784 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
58785 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
58786 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
58787 task_tgid_vnr(current), current->comm);
58788 @@ -615,6 +622,8 @@ void do_coredump(const siginfo_t *siginfo)
58789 } else {
58790 struct inode *inode;
58791
58792 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
58793 +
58794 if (cprm.limit < binfmt->min_coredump)
58795 goto fail_unlock;
58796
58797 @@ -673,7 +682,7 @@ close_fail:
58798 filp_close(cprm.file, NULL);
58799 fail_dropcount:
58800 if (ispipe)
58801 - atomic_dec(&core_dump_count);
58802 + atomic_dec_unchecked(&core_dump_count);
58803 fail_unlock:
58804 kfree(cn.corename);
58805 coredump_finish(mm, core_dumped);
58806 @@ -694,6 +703,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
58807 struct file *file = cprm->file;
58808 loff_t pos = file->f_pos;
58809 ssize_t n;
58810 +
58811 + gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
58812 if (cprm->written + nr > cprm->limit)
58813 return 0;
58814 while (nr) {
58815 diff --git a/fs/dcache.c b/fs/dcache.c
58816 index e99c6f5..2838bf58 100644
58817 --- a/fs/dcache.c
58818 +++ b/fs/dcache.c
58819 @@ -1445,7 +1445,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
58820 */
58821 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
58822 if (name->len > DNAME_INLINE_LEN-1) {
58823 - dname = kmalloc(name->len + 1, GFP_KERNEL);
58824 + dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
58825 if (!dname) {
58826 kmem_cache_free(dentry_cache, dentry);
58827 return NULL;
58828 @@ -3413,7 +3413,8 @@ void __init vfs_caches_init(unsigned long mempages)
58829 mempages -= reserve;
58830
58831 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
58832 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
58833 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
58834 + SLAB_NO_SANITIZE, NULL);
58835
58836 dcache_init();
58837 inode_init();
58838 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
58839 index 8c41b52..145b1b9 100644
58840 --- a/fs/debugfs/inode.c
58841 +++ b/fs/debugfs/inode.c
58842 @@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
58843 */
58844 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
58845 {
58846 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
58847 + return __create_file(name, S_IFDIR | S_IRWXU,
58848 +#else
58849 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
58850 +#endif
58851 parent, NULL, NULL);
58852 }
58853 EXPORT_SYMBOL_GPL(debugfs_create_dir);
58854 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
58855 index d4a9431..77f9b2e 100644
58856 --- a/fs/ecryptfs/inode.c
58857 +++ b/fs/ecryptfs/inode.c
58858 @@ -673,7 +673,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
58859 old_fs = get_fs();
58860 set_fs(get_ds());
58861 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
58862 - (char __user *)lower_buf,
58863 + (char __force_user *)lower_buf,
58864 PATH_MAX);
58865 set_fs(old_fs);
58866 if (rc < 0)
58867 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
58868 index e4141f2..d8263e8 100644
58869 --- a/fs/ecryptfs/miscdev.c
58870 +++ b/fs/ecryptfs/miscdev.c
58871 @@ -304,7 +304,7 @@ check_list:
58872 goto out_unlock_msg_ctx;
58873 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
58874 if (msg_ctx->msg) {
58875 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
58876 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
58877 goto out_unlock_msg_ctx;
58878 i += packet_length_size;
58879 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
58880 diff --git a/fs/exec.c b/fs/exec.c
58881 index 238b7aa..a421d91 100644
58882 --- a/fs/exec.c
58883 +++ b/fs/exec.c
58884 @@ -56,8 +56,20 @@
58885 #include <linux/pipe_fs_i.h>
58886 #include <linux/oom.h>
58887 #include <linux/compat.h>
58888 +#include <linux/random.h>
58889 +#include <linux/seq_file.h>
58890 +#include <linux/coredump.h>
58891 +#include <linux/mman.h>
58892 +
58893 +#ifdef CONFIG_PAX_REFCOUNT
58894 +#include <linux/kallsyms.h>
58895 +#include <linux/kdebug.h>
58896 +#endif
58897 +
58898 +#include <trace/events/fs.h>
58899
58900 #include <asm/uaccess.h>
58901 +#include <asm/sections.h>
58902 #include <asm/mmu_context.h>
58903 #include <asm/tlb.h>
58904
58905 @@ -66,19 +78,34 @@
58906
58907 #include <trace/events/sched.h>
58908
58909 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58910 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
58911 +{
58912 + 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");
58913 +}
58914 +#endif
58915 +
58916 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
58917 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
58918 +EXPORT_SYMBOL(pax_set_initial_flags_func);
58919 +#endif
58920 +
58921 int suid_dumpable = 0;
58922
58923 static LIST_HEAD(formats);
58924 static DEFINE_RWLOCK(binfmt_lock);
58925
58926 +extern int gr_process_kernel_exec_ban(void);
58927 +extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
58928 +
58929 void __register_binfmt(struct linux_binfmt * fmt, int insert)
58930 {
58931 BUG_ON(!fmt);
58932 if (WARN_ON(!fmt->load_binary))
58933 return;
58934 write_lock(&binfmt_lock);
58935 - insert ? list_add(&fmt->lh, &formats) :
58936 - list_add_tail(&fmt->lh, &formats);
58937 + insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
58938 + pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
58939 write_unlock(&binfmt_lock);
58940 }
58941
58942 @@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
58943 void unregister_binfmt(struct linux_binfmt * fmt)
58944 {
58945 write_lock(&binfmt_lock);
58946 - list_del(&fmt->lh);
58947 + pax_list_del((struct list_head *)&fmt->lh);
58948 write_unlock(&binfmt_lock);
58949 }
58950
58951 @@ -183,18 +210,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58952 int write)
58953 {
58954 struct page *page;
58955 - int ret;
58956
58957 -#ifdef CONFIG_STACK_GROWSUP
58958 - if (write) {
58959 - ret = expand_downwards(bprm->vma, pos);
58960 - if (ret < 0)
58961 - return NULL;
58962 - }
58963 -#endif
58964 - ret = get_user_pages(current, bprm->mm, pos,
58965 - 1, write, 1, &page, NULL);
58966 - if (ret <= 0)
58967 + if (0 > expand_downwards(bprm->vma, pos))
58968 + return NULL;
58969 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
58970 return NULL;
58971
58972 if (write) {
58973 @@ -210,6 +229,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58974 if (size <= ARG_MAX)
58975 return page;
58976
58977 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58978 + // only allow 512KB for argv+env on suid/sgid binaries
58979 + // to prevent easy ASLR exhaustion
58980 + if (((!uid_eq(bprm->cred->euid, current_euid())) ||
58981 + (!gid_eq(bprm->cred->egid, current_egid()))) &&
58982 + (size > (512 * 1024))) {
58983 + put_page(page);
58984 + return NULL;
58985 + }
58986 +#endif
58987 +
58988 /*
58989 * Limit to 1/4-th the stack size for the argv+env strings.
58990 * This ensures that:
58991 @@ -269,6 +299,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58992 vma->vm_end = STACK_TOP_MAX;
58993 vma->vm_start = vma->vm_end - PAGE_SIZE;
58994 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
58995 +
58996 +#ifdef CONFIG_PAX_SEGMEXEC
58997 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
58998 +#endif
58999 +
59000 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
59001 INIT_LIST_HEAD(&vma->anon_vma_chain);
59002
59003 @@ -279,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
59004 mm->stack_vm = mm->total_vm = 1;
59005 up_write(&mm->mmap_sem);
59006 bprm->p = vma->vm_end - sizeof(void *);
59007 +
59008 +#ifdef CONFIG_PAX_RANDUSTACK
59009 + if (randomize_va_space)
59010 + bprm->p ^= prandom_u32() & ~PAGE_MASK;
59011 +#endif
59012 +
59013 return 0;
59014 err:
59015 up_write(&mm->mmap_sem);
59016 @@ -399,7 +440,7 @@ struct user_arg_ptr {
59017 } ptr;
59018 };
59019
59020 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
59021 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
59022 {
59023 const char __user *native;
59024
59025 @@ -408,14 +449,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
59026 compat_uptr_t compat;
59027
59028 if (get_user(compat, argv.ptr.compat + nr))
59029 - return ERR_PTR(-EFAULT);
59030 + return (const char __force_user *)ERR_PTR(-EFAULT);
59031
59032 return compat_ptr(compat);
59033 }
59034 #endif
59035
59036 if (get_user(native, argv.ptr.native + nr))
59037 - return ERR_PTR(-EFAULT);
59038 + return (const char __force_user *)ERR_PTR(-EFAULT);
59039
59040 return native;
59041 }
59042 @@ -434,7 +475,7 @@ static int count(struct user_arg_ptr argv, int max)
59043 if (!p)
59044 break;
59045
59046 - if (IS_ERR(p))
59047 + if (IS_ERR((const char __force_kernel *)p))
59048 return -EFAULT;
59049
59050 if (i >= max)
59051 @@ -469,7 +510,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
59052
59053 ret = -EFAULT;
59054 str = get_user_arg_ptr(argv, argc);
59055 - if (IS_ERR(str))
59056 + if (IS_ERR((const char __force_kernel *)str))
59057 goto out;
59058
59059 len = strnlen_user(str, MAX_ARG_STRLEN);
59060 @@ -551,7 +592,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
59061 int r;
59062 mm_segment_t oldfs = get_fs();
59063 struct user_arg_ptr argv = {
59064 - .ptr.native = (const char __user *const __user *)__argv,
59065 + .ptr.native = (const char __user * const __force_user *)__argv,
59066 };
59067
59068 set_fs(KERNEL_DS);
59069 @@ -586,7 +627,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
59070 unsigned long new_end = old_end - shift;
59071 struct mmu_gather tlb;
59072
59073 - BUG_ON(new_start > new_end);
59074 + if (new_start >= new_end || new_start < mmap_min_addr)
59075 + return -ENOMEM;
59076
59077 /*
59078 * ensure there are no vmas between where we want to go
59079 @@ -595,6 +637,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
59080 if (vma != find_vma(mm, new_start))
59081 return -EFAULT;
59082
59083 +#ifdef CONFIG_PAX_SEGMEXEC
59084 + BUG_ON(pax_find_mirror_vma(vma));
59085 +#endif
59086 +
59087 /*
59088 * cover the whole range: [new_start, old_end)
59089 */
59090 @@ -675,10 +721,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
59091 stack_top = arch_align_stack(stack_top);
59092 stack_top = PAGE_ALIGN(stack_top);
59093
59094 - if (unlikely(stack_top < mmap_min_addr) ||
59095 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
59096 - return -ENOMEM;
59097 -
59098 stack_shift = vma->vm_end - stack_top;
59099
59100 bprm->p -= stack_shift;
59101 @@ -690,8 +732,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
59102 bprm->exec -= stack_shift;
59103
59104 down_write(&mm->mmap_sem);
59105 +
59106 + /* Move stack pages down in memory. */
59107 + if (stack_shift) {
59108 + ret = shift_arg_pages(vma, stack_shift);
59109 + if (ret)
59110 + goto out_unlock;
59111 + }
59112 +
59113 vm_flags = VM_STACK_FLAGS;
59114
59115 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
59116 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59117 + vm_flags &= ~VM_EXEC;
59118 +
59119 +#ifdef CONFIG_PAX_MPROTECT
59120 + if (mm->pax_flags & MF_PAX_MPROTECT)
59121 + vm_flags &= ~VM_MAYEXEC;
59122 +#endif
59123 +
59124 + }
59125 +#endif
59126 +
59127 /*
59128 * Adjust stack execute permissions; explicitly enable for
59129 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
59130 @@ -710,13 +772,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
59131 goto out_unlock;
59132 BUG_ON(prev != vma);
59133
59134 - /* Move stack pages down in memory. */
59135 - if (stack_shift) {
59136 - ret = shift_arg_pages(vma, stack_shift);
59137 - if (ret)
59138 - goto out_unlock;
59139 - }
59140 -
59141 /* mprotect_fixup is overkill to remove the temporary stack flags */
59142 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
59143
59144 @@ -740,6 +795,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
59145 #endif
59146 current->mm->start_stack = bprm->p;
59147 ret = expand_stack(vma, stack_base);
59148 +
59149 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
59150 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
59151 + unsigned long size;
59152 + vm_flags_t vm_flags;
59153 +
59154 + size = STACK_TOP - vma->vm_end;
59155 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
59156 +
59157 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
59158 +
59159 +#ifdef CONFIG_X86
59160 + if (!ret) {
59161 + size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
59162 + ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
59163 + }
59164 +#endif
59165 +
59166 + }
59167 +#endif
59168 +
59169 if (ret)
59170 ret = -EFAULT;
59171
59172 @@ -775,6 +851,8 @@ static struct file *do_open_exec(struct filename *name)
59173
59174 fsnotify_open(file);
59175
59176 + trace_open_exec(name->name);
59177 +
59178 err = deny_write_access(file);
59179 if (err)
59180 goto exit;
59181 @@ -804,7 +882,7 @@ int kernel_read(struct file *file, loff_t offset,
59182 old_fs = get_fs();
59183 set_fs(get_ds());
59184 /* The cast to a user pointer is valid due to the set_fs() */
59185 - result = vfs_read(file, (void __user *)addr, count, &pos);
59186 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
59187 set_fs(old_fs);
59188 return result;
59189 }
59190 @@ -849,6 +927,7 @@ static int exec_mmap(struct mm_struct *mm)
59191 tsk->mm = mm;
59192 tsk->active_mm = mm;
59193 activate_mm(active_mm, mm);
59194 + populate_stack();
59195 tsk->mm->vmacache_seqnum = 0;
59196 vmacache_flush(tsk);
59197 task_unlock(tsk);
59198 @@ -1246,7 +1325,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
59199 }
59200 rcu_read_unlock();
59201
59202 - if (p->fs->users > n_fs)
59203 + if (atomic_read(&p->fs->users) > n_fs)
59204 bprm->unsafe |= LSM_UNSAFE_SHARE;
59205 else
59206 p->fs->in_exec = 1;
59207 @@ -1422,6 +1501,31 @@ static int exec_binprm(struct linux_binprm *bprm)
59208 return ret;
59209 }
59210
59211 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59212 +static DEFINE_PER_CPU(u64, exec_counter);
59213 +static int __init init_exec_counters(void)
59214 +{
59215 + unsigned int cpu;
59216 +
59217 + for_each_possible_cpu(cpu) {
59218 + per_cpu(exec_counter, cpu) = (u64)cpu;
59219 + }
59220 +
59221 + return 0;
59222 +}
59223 +early_initcall(init_exec_counters);
59224 +static inline void increment_exec_counter(void)
59225 +{
59226 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
59227 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
59228 +}
59229 +#else
59230 +static inline void increment_exec_counter(void) {}
59231 +#endif
59232 +
59233 +extern void gr_handle_exec_args(struct linux_binprm *bprm,
59234 + struct user_arg_ptr argv);
59235 +
59236 /*
59237 * sys_execve() executes a new program.
59238 */
59239 @@ -1429,6 +1533,11 @@ static int do_execve_common(struct filename *filename,
59240 struct user_arg_ptr argv,
59241 struct user_arg_ptr envp)
59242 {
59243 +#ifdef CONFIG_GRKERNSEC
59244 + struct file *old_exec_file;
59245 + struct acl_subject_label *old_acl;
59246 + struct rlimit old_rlim[RLIM_NLIMITS];
59247 +#endif
59248 struct linux_binprm *bprm;
59249 struct file *file;
59250 struct files_struct *displaced;
59251 @@ -1437,6 +1546,8 @@ static int do_execve_common(struct filename *filename,
59252 if (IS_ERR(filename))
59253 return PTR_ERR(filename);
59254
59255 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
59256 +
59257 /*
59258 * We move the actual failure in case of RLIMIT_NPROC excess from
59259 * set*uid() to execve() because too many poorly written programs
59260 @@ -1474,11 +1585,21 @@ static int do_execve_common(struct filename *filename,
59261 if (IS_ERR(file))
59262 goto out_unmark;
59263
59264 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
59265 + retval = -EPERM;
59266 + goto out_unmark;
59267 + }
59268 +
59269 sched_exec();
59270
59271 bprm->file = file;
59272 bprm->filename = bprm->interp = filename->name;
59273
59274 + if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
59275 + retval = -EACCES;
59276 + goto out_unmark;
59277 + }
59278 +
59279 retval = bprm_mm_init(bprm);
59280 if (retval)
59281 goto out_unmark;
59282 @@ -1495,24 +1616,70 @@ static int do_execve_common(struct filename *filename,
59283 if (retval < 0)
59284 goto out;
59285
59286 +#ifdef CONFIG_GRKERNSEC
59287 + old_acl = current->acl;
59288 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
59289 + old_exec_file = current->exec_file;
59290 + get_file(file);
59291 + current->exec_file = file;
59292 +#endif
59293 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59294 + /* limit suid stack to 8MB
59295 + * we saved the old limits above and will restore them if this exec fails
59296 + */
59297 + if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
59298 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
59299 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
59300 +#endif
59301 +
59302 + if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
59303 + retval = -EPERM;
59304 + goto out_fail;
59305 + }
59306 +
59307 + if (!gr_tpe_allow(file)) {
59308 + retval = -EACCES;
59309 + goto out_fail;
59310 + }
59311 +
59312 + if (gr_check_crash_exec(file)) {
59313 + retval = -EACCES;
59314 + goto out_fail;
59315 + }
59316 +
59317 + retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
59318 + bprm->unsafe);
59319 + if (retval < 0)
59320 + goto out_fail;
59321 +
59322 retval = copy_strings_kernel(1, &bprm->filename, bprm);
59323 if (retval < 0)
59324 - goto out;
59325 + goto out_fail;
59326
59327 bprm->exec = bprm->p;
59328 retval = copy_strings(bprm->envc, envp, bprm);
59329 if (retval < 0)
59330 - goto out;
59331 + goto out_fail;
59332
59333 retval = copy_strings(bprm->argc, argv, bprm);
59334 if (retval < 0)
59335 - goto out;
59336 + goto out_fail;
59337 +
59338 + gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
59339 +
59340 + gr_handle_exec_args(bprm, argv);
59341
59342 retval = exec_binprm(bprm);
59343 if (retval < 0)
59344 - goto out;
59345 + goto out_fail;
59346 +#ifdef CONFIG_GRKERNSEC
59347 + if (old_exec_file)
59348 + fput(old_exec_file);
59349 +#endif
59350
59351 /* execve succeeded */
59352 +
59353 + increment_exec_counter();
59354 current->fs->in_exec = 0;
59355 current->in_execve = 0;
59356 acct_update_integrals(current);
59357 @@ -1523,6 +1690,14 @@ static int do_execve_common(struct filename *filename,
59358 put_files_struct(displaced);
59359 return retval;
59360
59361 +out_fail:
59362 +#ifdef CONFIG_GRKERNSEC
59363 + current->acl = old_acl;
59364 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
59365 + fput(current->exec_file);
59366 + current->exec_file = old_exec_file;
59367 +#endif
59368 +
59369 out:
59370 if (bprm->mm) {
59371 acct_arg_size(bprm, 0);
59372 @@ -1614,3 +1789,312 @@ COMPAT_SYSCALL_DEFINE3(execve, const char __user *, filename,
59373 return compat_do_execve(getname(filename), argv, envp);
59374 }
59375 #endif
59376 +
59377 +int pax_check_flags(unsigned long *flags)
59378 +{
59379 + int retval = 0;
59380 +
59381 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
59382 + if (*flags & MF_PAX_SEGMEXEC)
59383 + {
59384 + *flags &= ~MF_PAX_SEGMEXEC;
59385 + retval = -EINVAL;
59386 + }
59387 +#endif
59388 +
59389 + if ((*flags & MF_PAX_PAGEEXEC)
59390 +
59391 +#ifdef CONFIG_PAX_PAGEEXEC
59392 + && (*flags & MF_PAX_SEGMEXEC)
59393 +#endif
59394 +
59395 + )
59396 + {
59397 + *flags &= ~MF_PAX_PAGEEXEC;
59398 + retval = -EINVAL;
59399 + }
59400 +
59401 + if ((*flags & MF_PAX_MPROTECT)
59402 +
59403 +#ifdef CONFIG_PAX_MPROTECT
59404 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
59405 +#endif
59406 +
59407 + )
59408 + {
59409 + *flags &= ~MF_PAX_MPROTECT;
59410 + retval = -EINVAL;
59411 + }
59412 +
59413 + if ((*flags & MF_PAX_EMUTRAMP)
59414 +
59415 +#ifdef CONFIG_PAX_EMUTRAMP
59416 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
59417 +#endif
59418 +
59419 + )
59420 + {
59421 + *flags &= ~MF_PAX_EMUTRAMP;
59422 + retval = -EINVAL;
59423 + }
59424 +
59425 + return retval;
59426 +}
59427 +
59428 +EXPORT_SYMBOL(pax_check_flags);
59429 +
59430 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
59431 +char *pax_get_path(const struct path *path, char *buf, int buflen)
59432 +{
59433 + char *pathname = d_path(path, buf, buflen);
59434 +
59435 + if (IS_ERR(pathname))
59436 + goto toolong;
59437 +
59438 + pathname = mangle_path(buf, pathname, "\t\n\\");
59439 + if (!pathname)
59440 + goto toolong;
59441 +
59442 + *pathname = 0;
59443 + return buf;
59444 +
59445 +toolong:
59446 + return "<path too long>";
59447 +}
59448 +EXPORT_SYMBOL(pax_get_path);
59449 +
59450 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
59451 +{
59452 + struct task_struct *tsk = current;
59453 + struct mm_struct *mm = current->mm;
59454 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
59455 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
59456 + char *path_exec = NULL;
59457 + char *path_fault = NULL;
59458 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
59459 + siginfo_t info = { };
59460 +
59461 + if (buffer_exec && buffer_fault) {
59462 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
59463 +
59464 + down_read(&mm->mmap_sem);
59465 + vma = mm->mmap;
59466 + while (vma && (!vma_exec || !vma_fault)) {
59467 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
59468 + vma_exec = vma;
59469 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
59470 + vma_fault = vma;
59471 + vma = vma->vm_next;
59472 + }
59473 + if (vma_exec)
59474 + path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
59475 + if (vma_fault) {
59476 + start = vma_fault->vm_start;
59477 + end = vma_fault->vm_end;
59478 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
59479 + if (vma_fault->vm_file)
59480 + path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
59481 + else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
59482 + path_fault = "<heap>";
59483 + else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
59484 + path_fault = "<stack>";
59485 + else
59486 + path_fault = "<anonymous mapping>";
59487 + }
59488 + up_read(&mm->mmap_sem);
59489 + }
59490 + if (tsk->signal->curr_ip)
59491 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
59492 + else
59493 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
59494 + 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),
59495 + from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
59496 + free_page((unsigned long)buffer_exec);
59497 + free_page((unsigned long)buffer_fault);
59498 + pax_report_insns(regs, pc, sp);
59499 + info.si_signo = SIGKILL;
59500 + info.si_errno = 0;
59501 + info.si_code = SI_KERNEL;
59502 + info.si_pid = 0;
59503 + info.si_uid = 0;
59504 + do_coredump(&info);
59505 +}
59506 +#endif
59507 +
59508 +#ifdef CONFIG_PAX_REFCOUNT
59509 +void pax_report_refcount_overflow(struct pt_regs *regs)
59510 +{
59511 + if (current->signal->curr_ip)
59512 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
59513 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
59514 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
59515 + else
59516 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
59517 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
59518 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
59519 + preempt_disable();
59520 + show_regs(regs);
59521 + preempt_enable();
59522 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
59523 +}
59524 +#endif
59525 +
59526 +#ifdef CONFIG_PAX_USERCOPY
59527 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
59528 +static noinline int check_stack_object(const void *obj, unsigned long len)
59529 +{
59530 + const void * const stack = task_stack_page(current);
59531 + const void * const stackend = stack + THREAD_SIZE;
59532 +
59533 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
59534 + const void *frame = NULL;
59535 + const void *oldframe;
59536 +#endif
59537 +
59538 + if (obj + len < obj)
59539 + return -1;
59540 +
59541 + if (obj + len <= stack || stackend <= obj)
59542 + return 0;
59543 +
59544 + if (obj < stack || stackend < obj + len)
59545 + return -1;
59546 +
59547 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
59548 + oldframe = __builtin_frame_address(1);
59549 + if (oldframe)
59550 + frame = __builtin_frame_address(2);
59551 + /*
59552 + low ----------------------------------------------> high
59553 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
59554 + ^----------------^
59555 + allow copies only within here
59556 + */
59557 + while (stack <= frame && frame < stackend) {
59558 + /* if obj + len extends past the last frame, this
59559 + check won't pass and the next frame will be 0,
59560 + causing us to bail out and correctly report
59561 + the copy as invalid
59562 + */
59563 + if (obj + len <= frame)
59564 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
59565 + oldframe = frame;
59566 + frame = *(const void * const *)frame;
59567 + }
59568 + return -1;
59569 +#else
59570 + return 1;
59571 +#endif
59572 +}
59573 +
59574 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
59575 +{
59576 + if (current->signal->curr_ip)
59577 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
59578 + &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
59579 + else
59580 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
59581 + to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
59582 + dump_stack();
59583 + gr_handle_kernel_exploit();
59584 + do_group_exit(SIGKILL);
59585 +}
59586 +#endif
59587 +
59588 +#ifdef CONFIG_PAX_USERCOPY
59589 +
59590 +static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
59591 +{
59592 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
59593 + unsigned long textlow = ktla_ktva((unsigned long)_stext);
59594 +#ifdef CONFIG_MODULES
59595 + unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
59596 +#else
59597 + unsigned long texthigh = ktla_ktva((unsigned long)_etext);
59598 +#endif
59599 +
59600 +#else
59601 + unsigned long textlow = (unsigned long)_stext;
59602 + unsigned long texthigh = (unsigned long)_etext;
59603 +
59604 +#ifdef CONFIG_X86_64
59605 + /* check against linear mapping as well */
59606 + if (high > (unsigned long)__va(__pa(textlow)) &&
59607 + low < (unsigned long)__va(__pa(texthigh)))
59608 + return true;
59609 +#endif
59610 +
59611 +#endif
59612 +
59613 + if (high <= textlow || low >= texthigh)
59614 + return false;
59615 + else
59616 + return true;
59617 +}
59618 +#endif
59619 +
59620 +void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size)
59621 +{
59622 +#ifdef CONFIG_PAX_USERCOPY
59623 + const char *type;
59624 +#endif
59625 +
59626 +#ifndef CONFIG_STACK_GROWSUP
59627 + unsigned long stackstart = (unsigned long)task_stack_page(current);
59628 + unsigned long currentsp = (unsigned long)&stackstart;
59629 + if (unlikely((currentsp < stackstart + 512 ||
59630 + currentsp >= stackstart + THREAD_SIZE) && !in_interrupt()))
59631 + BUG();
59632 +#endif
59633 +
59634 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
59635 + if (const_size)
59636 + return;
59637 +#endif
59638 +
59639 +#ifdef CONFIG_PAX_USERCOPY
59640 + if (!n)
59641 + return;
59642 +
59643 + type = check_heap_object(ptr, n);
59644 + if (!type) {
59645 + int ret = check_stack_object(ptr, n);
59646 + if (ret == 1 || ret == 2)
59647 + return;
59648 + if (ret == 0) {
59649 + if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
59650 + type = "<kernel text>";
59651 + else
59652 + return;
59653 + } else
59654 + type = "<process stack>";
59655 + }
59656 +
59657 + pax_report_usercopy(ptr, n, to_user, type);
59658 +#endif
59659 +
59660 +}
59661 +EXPORT_SYMBOL(__check_object_size);
59662 +
59663 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
59664 +void pax_track_stack(void)
59665 +{
59666 + unsigned long sp = (unsigned long)&sp;
59667 + if (sp < current_thread_info()->lowest_stack &&
59668 + sp > (unsigned long)task_stack_page(current))
59669 + current_thread_info()->lowest_stack = sp;
59670 + if (unlikely((sp & ~(THREAD_SIZE - 1)) < (THREAD_SIZE/16)))
59671 + BUG();
59672 +}
59673 +EXPORT_SYMBOL(pax_track_stack);
59674 +#endif
59675 +
59676 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
59677 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
59678 +{
59679 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
59680 + dump_stack();
59681 + do_group_exit(SIGKILL);
59682 +}
59683 +EXPORT_SYMBOL(report_size_overflow);
59684 +#endif
59685 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
59686 index 9f9992b..8b59411 100644
59687 --- a/fs/ext2/balloc.c
59688 +++ b/fs/ext2/balloc.c
59689 @@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
59690
59691 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59692 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59693 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59694 + if (free_blocks < root_blocks + 1 &&
59695 !uid_eq(sbi->s_resuid, current_fsuid()) &&
59696 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59697 - !in_group_p (sbi->s_resgid))) {
59698 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59699 return 0;
59700 }
59701 return 1;
59702 diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
59703 index 9142614..97484fa 100644
59704 --- a/fs/ext2/xattr.c
59705 +++ b/fs/ext2/xattr.c
59706 @@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
59707 struct buffer_head *bh = NULL;
59708 struct ext2_xattr_entry *entry;
59709 char *end;
59710 - size_t rest = buffer_size;
59711 + size_t rest = buffer_size, total_size = 0;
59712 int error;
59713
59714 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
59715 @@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
59716 buffer += size;
59717 }
59718 rest -= size;
59719 + total_size += size;
59720 }
59721 }
59722 - error = buffer_size - rest; /* total size */
59723 + error = total_size;
59724
59725 cleanup:
59726 brelse(bh);
59727 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
59728 index 158b5d4..2432610 100644
59729 --- a/fs/ext3/balloc.c
59730 +++ b/fs/ext3/balloc.c
59731 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
59732
59733 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59734 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59735 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59736 + if (free_blocks < root_blocks + 1 &&
59737 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
59738 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59739 - !in_group_p (sbi->s_resgid))) {
59740 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59741 return 0;
59742 }
59743 return 1;
59744 diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
59745 index c6874be..f8a6ae8 100644
59746 --- a/fs/ext3/xattr.c
59747 +++ b/fs/ext3/xattr.c
59748 @@ -330,7 +330,7 @@ static int
59749 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59750 char *buffer, size_t buffer_size)
59751 {
59752 - size_t rest = buffer_size;
59753 + size_t rest = buffer_size, total_size = 0;
59754
59755 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
59756 const struct xattr_handler *handler =
59757 @@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59758 buffer += size;
59759 }
59760 rest -= size;
59761 + total_size += size;
59762 }
59763 }
59764 - return buffer_size - rest;
59765 + return total_size;
59766 }
59767
59768 static int
59769 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
59770 index 5c56785..77698a2 100644
59771 --- a/fs/ext4/balloc.c
59772 +++ b/fs/ext4/balloc.c
59773 @@ -534,8 +534,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
59774 /* Hm, nope. Are (enough) root reserved clusters available? */
59775 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
59776 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
59777 - capable(CAP_SYS_RESOURCE) ||
59778 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
59779 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
59780 + capable_nolog(CAP_SYS_RESOURCE)) {
59781
59782 if (free_clusters >= (nclusters + dirty_clusters +
59783 resv_clusters))
59784 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
59785 index f542e48..c0275f5 100644
59786 --- a/fs/ext4/ext4.h
59787 +++ b/fs/ext4/ext4.h
59788 @@ -1274,19 +1274,19 @@ struct ext4_sb_info {
59789 unsigned long s_mb_last_start;
59790
59791 /* stats for buddy allocator */
59792 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
59793 - atomic_t s_bal_success; /* we found long enough chunks */
59794 - atomic_t s_bal_allocated; /* in blocks */
59795 - atomic_t s_bal_ex_scanned; /* total extents scanned */
59796 - atomic_t s_bal_goals; /* goal hits */
59797 - atomic_t s_bal_breaks; /* too long searches */
59798 - atomic_t s_bal_2orders; /* 2^order hits */
59799 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
59800 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
59801 + atomic_unchecked_t s_bal_allocated; /* in blocks */
59802 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
59803 + atomic_unchecked_t s_bal_goals; /* goal hits */
59804 + atomic_unchecked_t s_bal_breaks; /* too long searches */
59805 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
59806 spinlock_t s_bal_lock;
59807 unsigned long s_mb_buddies_generated;
59808 unsigned long long s_mb_generation_time;
59809 - atomic_t s_mb_lost_chunks;
59810 - atomic_t s_mb_preallocated;
59811 - atomic_t s_mb_discarded;
59812 + atomic_unchecked_t s_mb_lost_chunks;
59813 + atomic_unchecked_t s_mb_preallocated;
59814 + atomic_unchecked_t s_mb_discarded;
59815 atomic_t s_lock_busy;
59816
59817 /* locality groups */
59818 diff --git a/fs/ext4/indirect.c b/fs/ext4/indirect.c
59819 index e6574d7..c30cbe2 100644
59820 --- a/fs/ext4/indirect.c
59821 +++ b/fs/ext4/indirect.c
59822 @@ -1345,8 +1345,8 @@ static int free_hole_blocks(handle_t *handle, struct inode *inode,
59823 if (level == 0 ||
59824 (bh && all_zeroes((__le32 *)bh->b_data,
59825 (__le32 *)bh->b_data + addr_per_block))) {
59826 - ext4_free_data(handle, inode, parent_bh, &blk, &blk+1);
59827 - *i_data = 0;
59828 + ext4_free_data(handle, inode, parent_bh,
59829 + i_data, i_data + 1);
59830 }
59831 brelse(bh);
59832 bh = NULL;
59833 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
59834 index 2735a72..d083044 100644
59835 --- a/fs/ext4/mballoc.c
59836 +++ b/fs/ext4/mballoc.c
59837 @@ -1889,7 +1889,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
59838 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
59839
59840 if (EXT4_SB(sb)->s_mb_stats)
59841 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
59842 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
59843
59844 break;
59845 }
59846 @@ -2199,7 +2199,7 @@ repeat:
59847 ac->ac_status = AC_STATUS_CONTINUE;
59848 ac->ac_flags |= EXT4_MB_HINT_FIRST;
59849 cr = 3;
59850 - atomic_inc(&sbi->s_mb_lost_chunks);
59851 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
59852 goto repeat;
59853 }
59854 }
59855 @@ -2707,25 +2707,25 @@ int ext4_mb_release(struct super_block *sb)
59856 if (sbi->s_mb_stats) {
59857 ext4_msg(sb, KERN_INFO,
59858 "mballoc: %u blocks %u reqs (%u success)",
59859 - atomic_read(&sbi->s_bal_allocated),
59860 - atomic_read(&sbi->s_bal_reqs),
59861 - atomic_read(&sbi->s_bal_success));
59862 + atomic_read_unchecked(&sbi->s_bal_allocated),
59863 + atomic_read_unchecked(&sbi->s_bal_reqs),
59864 + atomic_read_unchecked(&sbi->s_bal_success));
59865 ext4_msg(sb, KERN_INFO,
59866 "mballoc: %u extents scanned, %u goal hits, "
59867 "%u 2^N hits, %u breaks, %u lost",
59868 - atomic_read(&sbi->s_bal_ex_scanned),
59869 - atomic_read(&sbi->s_bal_goals),
59870 - atomic_read(&sbi->s_bal_2orders),
59871 - atomic_read(&sbi->s_bal_breaks),
59872 - atomic_read(&sbi->s_mb_lost_chunks));
59873 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
59874 + atomic_read_unchecked(&sbi->s_bal_goals),
59875 + atomic_read_unchecked(&sbi->s_bal_2orders),
59876 + atomic_read_unchecked(&sbi->s_bal_breaks),
59877 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
59878 ext4_msg(sb, KERN_INFO,
59879 "mballoc: %lu generated and it took %Lu",
59880 sbi->s_mb_buddies_generated,
59881 sbi->s_mb_generation_time);
59882 ext4_msg(sb, KERN_INFO,
59883 "mballoc: %u preallocated, %u discarded",
59884 - atomic_read(&sbi->s_mb_preallocated),
59885 - atomic_read(&sbi->s_mb_discarded));
59886 + atomic_read_unchecked(&sbi->s_mb_preallocated),
59887 + atomic_read_unchecked(&sbi->s_mb_discarded));
59888 }
59889
59890 free_percpu(sbi->s_locality_groups);
59891 @@ -3179,16 +3179,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
59892 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
59893
59894 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
59895 - atomic_inc(&sbi->s_bal_reqs);
59896 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59897 + atomic_inc_unchecked(&sbi->s_bal_reqs);
59898 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59899 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
59900 - atomic_inc(&sbi->s_bal_success);
59901 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
59902 + atomic_inc_unchecked(&sbi->s_bal_success);
59903 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
59904 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
59905 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
59906 - atomic_inc(&sbi->s_bal_goals);
59907 + atomic_inc_unchecked(&sbi->s_bal_goals);
59908 if (ac->ac_found > sbi->s_mb_max_to_scan)
59909 - atomic_inc(&sbi->s_bal_breaks);
59910 + atomic_inc_unchecked(&sbi->s_bal_breaks);
59911 }
59912
59913 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
59914 @@ -3593,7 +3593,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
59915 trace_ext4_mb_new_inode_pa(ac, pa);
59916
59917 ext4_mb_use_inode_pa(ac, pa);
59918 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
59919 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
59920
59921 ei = EXT4_I(ac->ac_inode);
59922 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59923 @@ -3653,7 +3653,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
59924 trace_ext4_mb_new_group_pa(ac, pa);
59925
59926 ext4_mb_use_group_pa(ac, pa);
59927 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59928 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59929
59930 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59931 lg = ac->ac_lg;
59932 @@ -3742,7 +3742,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
59933 * from the bitmap and continue.
59934 */
59935 }
59936 - atomic_add(free, &sbi->s_mb_discarded);
59937 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
59938
59939 return err;
59940 }
59941 @@ -3760,7 +3760,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
59942 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
59943 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
59944 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
59945 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59946 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59947 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
59948
59949 return 0;
59950 diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
59951 index 04434ad..6404663 100644
59952 --- a/fs/ext4/mmp.c
59953 +++ b/fs/ext4/mmp.c
59954 @@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
59955 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
59956 const char *function, unsigned int line, const char *msg)
59957 {
59958 - __ext4_warning(sb, function, line, msg);
59959 + __ext4_warning(sb, function, line, "%s", msg);
59960 __ext4_warning(sb, function, line,
59961 "MMP failure info: last update time: %llu, last update "
59962 "node: %s, last update device: %s\n",
59963 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
59964 index 29a403c..f58dbdb 100644
59965 --- a/fs/ext4/super.c
59966 +++ b/fs/ext4/super.c
59967 @@ -1275,7 +1275,7 @@ static ext4_fsblk_t get_sb_block(void **data)
59968 }
59969
59970 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
59971 -static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59972 +static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59973 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
59974
59975 #ifdef CONFIG_QUOTA
59976 @@ -2453,7 +2453,7 @@ struct ext4_attr {
59977 int offset;
59978 int deprecated_val;
59979 } u;
59980 -};
59981 +} __do_const;
59982
59983 static int parse_strtoull(const char *buf,
59984 unsigned long long max, unsigned long long *value)
59985 diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
59986 index 4eec399..1d9444c 100644
59987 --- a/fs/ext4/xattr.c
59988 +++ b/fs/ext4/xattr.c
59989 @@ -383,7 +383,7 @@ static int
59990 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59991 char *buffer, size_t buffer_size)
59992 {
59993 - size_t rest = buffer_size;
59994 + size_t rest = buffer_size, total_size = 0;
59995
59996 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
59997 const struct xattr_handler *handler =
59998 @@ -400,9 +400,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59999 buffer += size;
60000 }
60001 rest -= size;
60002 + total_size += size;
60003 }
60004 }
60005 - return buffer_size - rest;
60006 + return total_size;
60007 }
60008
60009 static int
60010 diff --git a/fs/fcntl.c b/fs/fcntl.c
60011 index 72c82f6..a18b263 100644
60012 --- a/fs/fcntl.c
60013 +++ b/fs/fcntl.c
60014 @@ -106,6 +106,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
60015 if (err)
60016 return err;
60017
60018 + if (gr_handle_chroot_fowner(pid, type))
60019 + return -ENOENT;
60020 + if (gr_check_protected_task_fowner(pid, type))
60021 + return -EACCES;
60022 +
60023 f_modown(filp, pid, type, force);
60024 return 0;
60025 }
60026 diff --git a/fs/fhandle.c b/fs/fhandle.c
60027 index 999ff5c..ac037c9 100644
60028 --- a/fs/fhandle.c
60029 +++ b/fs/fhandle.c
60030 @@ -8,6 +8,7 @@
60031 #include <linux/fs_struct.h>
60032 #include <linux/fsnotify.h>
60033 #include <linux/personality.h>
60034 +#include <linux/grsecurity.h>
60035 #include <asm/uaccess.h>
60036 #include "internal.h"
60037 #include "mount.h"
60038 @@ -67,8 +68,7 @@ static long do_sys_name_to_handle(struct path *path,
60039 } else
60040 retval = 0;
60041 /* copy the mount id */
60042 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
60043 - sizeof(*mnt_id)) ||
60044 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
60045 copy_to_user(ufh, handle,
60046 sizeof(struct file_handle) + handle_bytes))
60047 retval = -EFAULT;
60048 @@ -175,7 +175,7 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
60049 * the directory. Ideally we would like CAP_DAC_SEARCH.
60050 * But we don't have that
60051 */
60052 - if (!capable(CAP_DAC_READ_SEARCH)) {
60053 + if (!capable(CAP_DAC_READ_SEARCH) || !gr_chroot_fhandle()) {
60054 retval = -EPERM;
60055 goto out_err;
60056 }
60057 diff --git a/fs/file.c b/fs/file.c
60058 index 8f294cf..d0f3872 100644
60059 --- a/fs/file.c
60060 +++ b/fs/file.c
60061 @@ -16,6 +16,7 @@
60062 #include <linux/slab.h>
60063 #include <linux/vmalloc.h>
60064 #include <linux/file.h>
60065 +#include <linux/security.h>
60066 #include <linux/fdtable.h>
60067 #include <linux/bitops.h>
60068 #include <linux/interrupt.h>
60069 @@ -144,7 +145,7 @@ out:
60070 * Return <0 error code on error; 1 on successful completion.
60071 * The files->file_lock should be held on entry, and will be held on exit.
60072 */
60073 -static int expand_fdtable(struct files_struct *files, int nr)
60074 +static int expand_fdtable(struct files_struct *files, unsigned int nr)
60075 __releases(files->file_lock)
60076 __acquires(files->file_lock)
60077 {
60078 @@ -189,7 +190,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
60079 * expanded and execution may have blocked.
60080 * The files->file_lock should be held on entry, and will be held on exit.
60081 */
60082 -static int expand_files(struct files_struct *files, int nr)
60083 +static int expand_files(struct files_struct *files, unsigned int nr)
60084 {
60085 struct fdtable *fdt;
60086
60087 @@ -804,6 +805,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
60088 if (!file)
60089 return __close_fd(files, fd);
60090
60091 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
60092 if (fd >= rlimit(RLIMIT_NOFILE))
60093 return -EBADF;
60094
60095 @@ -830,6 +832,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
60096 if (unlikely(oldfd == newfd))
60097 return -EINVAL;
60098
60099 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
60100 if (newfd >= rlimit(RLIMIT_NOFILE))
60101 return -EBADF;
60102
60103 @@ -885,6 +888,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
60104 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
60105 {
60106 int err;
60107 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
60108 if (from >= rlimit(RLIMIT_NOFILE))
60109 return -EINVAL;
60110 err = alloc_fd(from, flags);
60111 diff --git a/fs/filesystems.c b/fs/filesystems.c
60112 index 5797d45..7d7d79a 100644
60113 --- a/fs/filesystems.c
60114 +++ b/fs/filesystems.c
60115 @@ -275,7 +275,11 @@ struct file_system_type *get_fs_type(const char *name)
60116 int len = dot ? dot - name : strlen(name);
60117
60118 fs = __get_fs_type(name, len);
60119 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
60120 + if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
60121 +#else
60122 if (!fs && (request_module("fs-%.*s", len, name) == 0))
60123 +#endif
60124 fs = __get_fs_type(name, len);
60125
60126 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
60127 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
60128 index 7dca743..543d620 100644
60129 --- a/fs/fs_struct.c
60130 +++ b/fs/fs_struct.c
60131 @@ -4,6 +4,7 @@
60132 #include <linux/path.h>
60133 #include <linux/slab.h>
60134 #include <linux/fs_struct.h>
60135 +#include <linux/grsecurity.h>
60136 #include "internal.h"
60137
60138 /*
60139 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
60140 write_seqcount_begin(&fs->seq);
60141 old_root = fs->root;
60142 fs->root = *path;
60143 + gr_set_chroot_entries(current, path);
60144 write_seqcount_end(&fs->seq);
60145 spin_unlock(&fs->lock);
60146 if (old_root.dentry)
60147 @@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
60148 int hits = 0;
60149 spin_lock(&fs->lock);
60150 write_seqcount_begin(&fs->seq);
60151 + /* this root replacement is only done by pivot_root,
60152 + leave grsec's chroot tagging alone for this task
60153 + so that a pivoted root isn't treated as a chroot
60154 + */
60155 hits += replace_path(&fs->root, old_root, new_root);
60156 hits += replace_path(&fs->pwd, old_root, new_root);
60157 write_seqcount_end(&fs->seq);
60158 @@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
60159 task_lock(tsk);
60160 spin_lock(&fs->lock);
60161 tsk->fs = NULL;
60162 - kill = !--fs->users;
60163 + gr_clear_chroot_entries(tsk);
60164 + kill = !atomic_dec_return(&fs->users);
60165 spin_unlock(&fs->lock);
60166 task_unlock(tsk);
60167 if (kill)
60168 @@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
60169 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
60170 /* We don't need to lock fs - think why ;-) */
60171 if (fs) {
60172 - fs->users = 1;
60173 + atomic_set(&fs->users, 1);
60174 fs->in_exec = 0;
60175 spin_lock_init(&fs->lock);
60176 seqcount_init(&fs->seq);
60177 @@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
60178 spin_lock(&old->lock);
60179 fs->root = old->root;
60180 path_get(&fs->root);
60181 + /* instead of calling gr_set_chroot_entries here,
60182 + we call it from every caller of this function
60183 + */
60184 fs->pwd = old->pwd;
60185 path_get(&fs->pwd);
60186 spin_unlock(&old->lock);
60187 @@ -139,8 +149,9 @@ int unshare_fs_struct(void)
60188
60189 task_lock(current);
60190 spin_lock(&fs->lock);
60191 - kill = !--fs->users;
60192 + kill = !atomic_dec_return(&fs->users);
60193 current->fs = new_fs;
60194 + gr_set_chroot_entries(current, &new_fs->root);
60195 spin_unlock(&fs->lock);
60196 task_unlock(current);
60197
60198 @@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
60199
60200 int current_umask(void)
60201 {
60202 - return current->fs->umask;
60203 + return current->fs->umask | gr_acl_umask();
60204 }
60205 EXPORT_SYMBOL(current_umask);
60206
60207 /* to be mentioned only in INIT_TASK */
60208 struct fs_struct init_fs = {
60209 - .users = 1,
60210 + .users = ATOMIC_INIT(1),
60211 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
60212 .seq = SEQCNT_ZERO(init_fs.seq),
60213 .umask = 0022,
60214 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
60215 index 29d7feb..303644d 100644
60216 --- a/fs/fscache/cookie.c
60217 +++ b/fs/fscache/cookie.c
60218 @@ -19,7 +19,7 @@
60219
60220 struct kmem_cache *fscache_cookie_jar;
60221
60222 -static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
60223 +static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
60224
60225 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
60226 static int fscache_alloc_object(struct fscache_cache *cache,
60227 @@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
60228 parent ? (char *) parent->def->name : "<no-parent>",
60229 def->name, netfs_data, enable);
60230
60231 - fscache_stat(&fscache_n_acquires);
60232 + fscache_stat_unchecked(&fscache_n_acquires);
60233
60234 /* if there's no parent cookie, then we don't create one here either */
60235 if (!parent) {
60236 - fscache_stat(&fscache_n_acquires_null);
60237 + fscache_stat_unchecked(&fscache_n_acquires_null);
60238 _leave(" [no parent]");
60239 return NULL;
60240 }
60241 @@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
60242 /* allocate and initialise a cookie */
60243 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
60244 if (!cookie) {
60245 - fscache_stat(&fscache_n_acquires_oom);
60246 + fscache_stat_unchecked(&fscache_n_acquires_oom);
60247 _leave(" [ENOMEM]");
60248 return NULL;
60249 }
60250 @@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
60251
60252 switch (cookie->def->type) {
60253 case FSCACHE_COOKIE_TYPE_INDEX:
60254 - fscache_stat(&fscache_n_cookie_index);
60255 + fscache_stat_unchecked(&fscache_n_cookie_index);
60256 break;
60257 case FSCACHE_COOKIE_TYPE_DATAFILE:
60258 - fscache_stat(&fscache_n_cookie_data);
60259 + fscache_stat_unchecked(&fscache_n_cookie_data);
60260 break;
60261 default:
60262 - fscache_stat(&fscache_n_cookie_special);
60263 + fscache_stat_unchecked(&fscache_n_cookie_special);
60264 break;
60265 }
60266
60267 @@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
60268 } else {
60269 atomic_dec(&parent->n_children);
60270 __fscache_cookie_put(cookie);
60271 - fscache_stat(&fscache_n_acquires_nobufs);
60272 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
60273 _leave(" = NULL");
60274 return NULL;
60275 }
60276 @@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
60277 }
60278 }
60279
60280 - fscache_stat(&fscache_n_acquires_ok);
60281 + fscache_stat_unchecked(&fscache_n_acquires_ok);
60282 _leave(" = %p", cookie);
60283 return cookie;
60284 }
60285 @@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
60286 cache = fscache_select_cache_for_object(cookie->parent);
60287 if (!cache) {
60288 up_read(&fscache_addremove_sem);
60289 - fscache_stat(&fscache_n_acquires_no_cache);
60290 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
60291 _leave(" = -ENOMEDIUM [no cache]");
60292 return -ENOMEDIUM;
60293 }
60294 @@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
60295 object = cache->ops->alloc_object(cache, cookie);
60296 fscache_stat_d(&fscache_n_cop_alloc_object);
60297 if (IS_ERR(object)) {
60298 - fscache_stat(&fscache_n_object_no_alloc);
60299 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
60300 ret = PTR_ERR(object);
60301 goto error;
60302 }
60303
60304 - fscache_stat(&fscache_n_object_alloc);
60305 + fscache_stat_unchecked(&fscache_n_object_alloc);
60306
60307 - object->debug_id = atomic_inc_return(&fscache_object_debug_id);
60308 + object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
60309
60310 _debug("ALLOC OBJ%x: %s {%lx}",
60311 object->debug_id, cookie->def->name, object->events);
60312 @@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
60313
60314 _enter("{%s}", cookie->def->name);
60315
60316 - fscache_stat(&fscache_n_invalidates);
60317 + fscache_stat_unchecked(&fscache_n_invalidates);
60318
60319 /* Only permit invalidation of data files. Invalidating an index will
60320 * require the caller to release all its attachments to the tree rooted
60321 @@ -477,10 +477,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
60322 {
60323 struct fscache_object *object;
60324
60325 - fscache_stat(&fscache_n_updates);
60326 + fscache_stat_unchecked(&fscache_n_updates);
60327
60328 if (!cookie) {
60329 - fscache_stat(&fscache_n_updates_null);
60330 + fscache_stat_unchecked(&fscache_n_updates_null);
60331 _leave(" [no cookie]");
60332 return;
60333 }
60334 @@ -581,12 +581,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
60335 */
60336 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
60337 {
60338 - fscache_stat(&fscache_n_relinquishes);
60339 + fscache_stat_unchecked(&fscache_n_relinquishes);
60340 if (retire)
60341 - fscache_stat(&fscache_n_relinquishes_retire);
60342 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
60343
60344 if (!cookie) {
60345 - fscache_stat(&fscache_n_relinquishes_null);
60346 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
60347 _leave(" [no cookie]");
60348 return;
60349 }
60350 @@ -687,7 +687,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
60351 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
60352 goto inconsistent;
60353
60354 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
60355 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60356
60357 __fscache_use_cookie(cookie);
60358 if (fscache_submit_op(object, op) < 0)
60359 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
60360 index 4226f66..0fb3f45 100644
60361 --- a/fs/fscache/internal.h
60362 +++ b/fs/fscache/internal.h
60363 @@ -133,8 +133,8 @@ extern void fscache_operation_gc(struct work_struct *);
60364 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
60365 extern int fscache_wait_for_operation_activation(struct fscache_object *,
60366 struct fscache_operation *,
60367 - atomic_t *,
60368 - atomic_t *,
60369 + atomic_unchecked_t *,
60370 + atomic_unchecked_t *,
60371 void (*)(struct fscache_operation *));
60372 extern void fscache_invalidate_writes(struct fscache_cookie *);
60373
60374 @@ -153,101 +153,101 @@ extern void fscache_proc_cleanup(void);
60375 * stats.c
60376 */
60377 #ifdef CONFIG_FSCACHE_STATS
60378 -extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
60379 -extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
60380 +extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
60381 +extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
60382
60383 -extern atomic_t fscache_n_op_pend;
60384 -extern atomic_t fscache_n_op_run;
60385 -extern atomic_t fscache_n_op_enqueue;
60386 -extern atomic_t fscache_n_op_deferred_release;
60387 -extern atomic_t fscache_n_op_release;
60388 -extern atomic_t fscache_n_op_gc;
60389 -extern atomic_t fscache_n_op_cancelled;
60390 -extern atomic_t fscache_n_op_rejected;
60391 +extern atomic_unchecked_t fscache_n_op_pend;
60392 +extern atomic_unchecked_t fscache_n_op_run;
60393 +extern atomic_unchecked_t fscache_n_op_enqueue;
60394 +extern atomic_unchecked_t fscache_n_op_deferred_release;
60395 +extern atomic_unchecked_t fscache_n_op_release;
60396 +extern atomic_unchecked_t fscache_n_op_gc;
60397 +extern atomic_unchecked_t fscache_n_op_cancelled;
60398 +extern atomic_unchecked_t fscache_n_op_rejected;
60399
60400 -extern atomic_t fscache_n_attr_changed;
60401 -extern atomic_t fscache_n_attr_changed_ok;
60402 -extern atomic_t fscache_n_attr_changed_nobufs;
60403 -extern atomic_t fscache_n_attr_changed_nomem;
60404 -extern atomic_t fscache_n_attr_changed_calls;
60405 +extern atomic_unchecked_t fscache_n_attr_changed;
60406 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
60407 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
60408 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
60409 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
60410
60411 -extern atomic_t fscache_n_allocs;
60412 -extern atomic_t fscache_n_allocs_ok;
60413 -extern atomic_t fscache_n_allocs_wait;
60414 -extern atomic_t fscache_n_allocs_nobufs;
60415 -extern atomic_t fscache_n_allocs_intr;
60416 -extern atomic_t fscache_n_allocs_object_dead;
60417 -extern atomic_t fscache_n_alloc_ops;
60418 -extern atomic_t fscache_n_alloc_op_waits;
60419 +extern atomic_unchecked_t fscache_n_allocs;
60420 +extern atomic_unchecked_t fscache_n_allocs_ok;
60421 +extern atomic_unchecked_t fscache_n_allocs_wait;
60422 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
60423 +extern atomic_unchecked_t fscache_n_allocs_intr;
60424 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
60425 +extern atomic_unchecked_t fscache_n_alloc_ops;
60426 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
60427
60428 -extern atomic_t fscache_n_retrievals;
60429 -extern atomic_t fscache_n_retrievals_ok;
60430 -extern atomic_t fscache_n_retrievals_wait;
60431 -extern atomic_t fscache_n_retrievals_nodata;
60432 -extern atomic_t fscache_n_retrievals_nobufs;
60433 -extern atomic_t fscache_n_retrievals_intr;
60434 -extern atomic_t fscache_n_retrievals_nomem;
60435 -extern atomic_t fscache_n_retrievals_object_dead;
60436 -extern atomic_t fscache_n_retrieval_ops;
60437 -extern atomic_t fscache_n_retrieval_op_waits;
60438 +extern atomic_unchecked_t fscache_n_retrievals;
60439 +extern atomic_unchecked_t fscache_n_retrievals_ok;
60440 +extern atomic_unchecked_t fscache_n_retrievals_wait;
60441 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
60442 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
60443 +extern atomic_unchecked_t fscache_n_retrievals_intr;
60444 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
60445 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
60446 +extern atomic_unchecked_t fscache_n_retrieval_ops;
60447 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
60448
60449 -extern atomic_t fscache_n_stores;
60450 -extern atomic_t fscache_n_stores_ok;
60451 -extern atomic_t fscache_n_stores_again;
60452 -extern atomic_t fscache_n_stores_nobufs;
60453 -extern atomic_t fscache_n_stores_oom;
60454 -extern atomic_t fscache_n_store_ops;
60455 -extern atomic_t fscache_n_store_calls;
60456 -extern atomic_t fscache_n_store_pages;
60457 -extern atomic_t fscache_n_store_radix_deletes;
60458 -extern atomic_t fscache_n_store_pages_over_limit;
60459 +extern atomic_unchecked_t fscache_n_stores;
60460 +extern atomic_unchecked_t fscache_n_stores_ok;
60461 +extern atomic_unchecked_t fscache_n_stores_again;
60462 +extern atomic_unchecked_t fscache_n_stores_nobufs;
60463 +extern atomic_unchecked_t fscache_n_stores_oom;
60464 +extern atomic_unchecked_t fscache_n_store_ops;
60465 +extern atomic_unchecked_t fscache_n_store_calls;
60466 +extern atomic_unchecked_t fscache_n_store_pages;
60467 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
60468 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
60469
60470 -extern atomic_t fscache_n_store_vmscan_not_storing;
60471 -extern atomic_t fscache_n_store_vmscan_gone;
60472 -extern atomic_t fscache_n_store_vmscan_busy;
60473 -extern atomic_t fscache_n_store_vmscan_cancelled;
60474 -extern atomic_t fscache_n_store_vmscan_wait;
60475 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
60476 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
60477 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
60478 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
60479 +extern atomic_unchecked_t fscache_n_store_vmscan_wait;
60480
60481 -extern atomic_t fscache_n_marks;
60482 -extern atomic_t fscache_n_uncaches;
60483 +extern atomic_unchecked_t fscache_n_marks;
60484 +extern atomic_unchecked_t fscache_n_uncaches;
60485
60486 -extern atomic_t fscache_n_acquires;
60487 -extern atomic_t fscache_n_acquires_null;
60488 -extern atomic_t fscache_n_acquires_no_cache;
60489 -extern atomic_t fscache_n_acquires_ok;
60490 -extern atomic_t fscache_n_acquires_nobufs;
60491 -extern atomic_t fscache_n_acquires_oom;
60492 +extern atomic_unchecked_t fscache_n_acquires;
60493 +extern atomic_unchecked_t fscache_n_acquires_null;
60494 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
60495 +extern atomic_unchecked_t fscache_n_acquires_ok;
60496 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
60497 +extern atomic_unchecked_t fscache_n_acquires_oom;
60498
60499 -extern atomic_t fscache_n_invalidates;
60500 -extern atomic_t fscache_n_invalidates_run;
60501 +extern atomic_unchecked_t fscache_n_invalidates;
60502 +extern atomic_unchecked_t fscache_n_invalidates_run;
60503
60504 -extern atomic_t fscache_n_updates;
60505 -extern atomic_t fscache_n_updates_null;
60506 -extern atomic_t fscache_n_updates_run;
60507 +extern atomic_unchecked_t fscache_n_updates;
60508 +extern atomic_unchecked_t fscache_n_updates_null;
60509 +extern atomic_unchecked_t fscache_n_updates_run;
60510
60511 -extern atomic_t fscache_n_relinquishes;
60512 -extern atomic_t fscache_n_relinquishes_null;
60513 -extern atomic_t fscache_n_relinquishes_waitcrt;
60514 -extern atomic_t fscache_n_relinquishes_retire;
60515 +extern atomic_unchecked_t fscache_n_relinquishes;
60516 +extern atomic_unchecked_t fscache_n_relinquishes_null;
60517 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
60518 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
60519
60520 -extern atomic_t fscache_n_cookie_index;
60521 -extern atomic_t fscache_n_cookie_data;
60522 -extern atomic_t fscache_n_cookie_special;
60523 +extern atomic_unchecked_t fscache_n_cookie_index;
60524 +extern atomic_unchecked_t fscache_n_cookie_data;
60525 +extern atomic_unchecked_t fscache_n_cookie_special;
60526
60527 -extern atomic_t fscache_n_object_alloc;
60528 -extern atomic_t fscache_n_object_no_alloc;
60529 -extern atomic_t fscache_n_object_lookups;
60530 -extern atomic_t fscache_n_object_lookups_negative;
60531 -extern atomic_t fscache_n_object_lookups_positive;
60532 -extern atomic_t fscache_n_object_lookups_timed_out;
60533 -extern atomic_t fscache_n_object_created;
60534 -extern atomic_t fscache_n_object_avail;
60535 -extern atomic_t fscache_n_object_dead;
60536 +extern atomic_unchecked_t fscache_n_object_alloc;
60537 +extern atomic_unchecked_t fscache_n_object_no_alloc;
60538 +extern atomic_unchecked_t fscache_n_object_lookups;
60539 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
60540 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
60541 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
60542 +extern atomic_unchecked_t fscache_n_object_created;
60543 +extern atomic_unchecked_t fscache_n_object_avail;
60544 +extern atomic_unchecked_t fscache_n_object_dead;
60545
60546 -extern atomic_t fscache_n_checkaux_none;
60547 -extern atomic_t fscache_n_checkaux_okay;
60548 -extern atomic_t fscache_n_checkaux_update;
60549 -extern atomic_t fscache_n_checkaux_obsolete;
60550 +extern atomic_unchecked_t fscache_n_checkaux_none;
60551 +extern atomic_unchecked_t fscache_n_checkaux_okay;
60552 +extern atomic_unchecked_t fscache_n_checkaux_update;
60553 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
60554
60555 extern atomic_t fscache_n_cop_alloc_object;
60556 extern atomic_t fscache_n_cop_lookup_object;
60557 @@ -272,6 +272,11 @@ static inline void fscache_stat(atomic_t *stat)
60558 atomic_inc(stat);
60559 }
60560
60561 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
60562 +{
60563 + atomic_inc_unchecked(stat);
60564 +}
60565 +
60566 static inline void fscache_stat_d(atomic_t *stat)
60567 {
60568 atomic_dec(stat);
60569 @@ -284,6 +289,7 @@ extern const struct file_operations fscache_stats_fops;
60570
60571 #define __fscache_stat(stat) (NULL)
60572 #define fscache_stat(stat) do {} while (0)
60573 +#define fscache_stat_unchecked(stat) do {} while (0)
60574 #define fscache_stat_d(stat) do {} while (0)
60575 #endif
60576
60577 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
60578 index d3b4539..ed0c659 100644
60579 --- a/fs/fscache/object.c
60580 +++ b/fs/fscache/object.c
60581 @@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
60582 _debug("LOOKUP \"%s\" in \"%s\"",
60583 cookie->def->name, object->cache->tag->name);
60584
60585 - fscache_stat(&fscache_n_object_lookups);
60586 + fscache_stat_unchecked(&fscache_n_object_lookups);
60587 fscache_stat(&fscache_n_cop_lookup_object);
60588 ret = object->cache->ops->lookup_object(object);
60589 fscache_stat_d(&fscache_n_cop_lookup_object);
60590 @@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
60591 if (ret == -ETIMEDOUT) {
60592 /* probably stuck behind another object, so move this one to
60593 * the back of the queue */
60594 - fscache_stat(&fscache_n_object_lookups_timed_out);
60595 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
60596 _leave(" [timeout]");
60597 return NO_TRANSIT;
60598 }
60599 @@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
60600 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
60601
60602 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
60603 - fscache_stat(&fscache_n_object_lookups_negative);
60604 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
60605
60606 /* Allow write requests to begin stacking up and read requests to begin
60607 * returning ENODATA.
60608 @@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
60609 /* if we were still looking up, then we must have a positive lookup
60610 * result, in which case there may be data available */
60611 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
60612 - fscache_stat(&fscache_n_object_lookups_positive);
60613 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
60614
60615 /* We do (presumably) have data */
60616 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
60617 @@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
60618 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
60619 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
60620 } else {
60621 - fscache_stat(&fscache_n_object_created);
60622 + fscache_stat_unchecked(&fscache_n_object_created);
60623 }
60624
60625 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
60626 @@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
60627 fscache_stat_d(&fscache_n_cop_lookup_complete);
60628
60629 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
60630 - fscache_stat(&fscache_n_object_avail);
60631 + fscache_stat_unchecked(&fscache_n_object_avail);
60632
60633 _leave("");
60634 return transit_to(JUMPSTART_DEPS);
60635 @@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
60636
60637 /* this just shifts the object release to the work processor */
60638 fscache_put_object(object);
60639 - fscache_stat(&fscache_n_object_dead);
60640 + fscache_stat_unchecked(&fscache_n_object_dead);
60641
60642 _leave("");
60643 return transit_to(OBJECT_DEAD);
60644 @@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60645 enum fscache_checkaux result;
60646
60647 if (!object->cookie->def->check_aux) {
60648 - fscache_stat(&fscache_n_checkaux_none);
60649 + fscache_stat_unchecked(&fscache_n_checkaux_none);
60650 return FSCACHE_CHECKAUX_OKAY;
60651 }
60652
60653 @@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60654 switch (result) {
60655 /* entry okay as is */
60656 case FSCACHE_CHECKAUX_OKAY:
60657 - fscache_stat(&fscache_n_checkaux_okay);
60658 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
60659 break;
60660
60661 /* entry requires update */
60662 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
60663 - fscache_stat(&fscache_n_checkaux_update);
60664 + fscache_stat_unchecked(&fscache_n_checkaux_update);
60665 break;
60666
60667 /* entry requires deletion */
60668 case FSCACHE_CHECKAUX_OBSOLETE:
60669 - fscache_stat(&fscache_n_checkaux_obsolete);
60670 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
60671 break;
60672
60673 default:
60674 @@ -992,7 +992,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
60675 {
60676 const struct fscache_state *s;
60677
60678 - fscache_stat(&fscache_n_invalidates_run);
60679 + fscache_stat_unchecked(&fscache_n_invalidates_run);
60680 fscache_stat(&fscache_n_cop_invalidate_object);
60681 s = _fscache_invalidate_object(object, event);
60682 fscache_stat_d(&fscache_n_cop_invalidate_object);
60683 @@ -1007,7 +1007,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
60684 {
60685 _enter("{OBJ%x},%d", object->debug_id, event);
60686
60687 - fscache_stat(&fscache_n_updates_run);
60688 + fscache_stat_unchecked(&fscache_n_updates_run);
60689 fscache_stat(&fscache_n_cop_update_object);
60690 object->cache->ops->update_object(object);
60691 fscache_stat_d(&fscache_n_cop_update_object);
60692 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
60693 index 318071a..379938b 100644
60694 --- a/fs/fscache/operation.c
60695 +++ b/fs/fscache/operation.c
60696 @@ -17,7 +17,7 @@
60697 #include <linux/slab.h>
60698 #include "internal.h"
60699
60700 -atomic_t fscache_op_debug_id;
60701 +atomic_unchecked_t fscache_op_debug_id;
60702 EXPORT_SYMBOL(fscache_op_debug_id);
60703
60704 /**
60705 @@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
60706 ASSERTCMP(atomic_read(&op->usage), >, 0);
60707 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
60708
60709 - fscache_stat(&fscache_n_op_enqueue);
60710 + fscache_stat_unchecked(&fscache_n_op_enqueue);
60711 switch (op->flags & FSCACHE_OP_TYPE) {
60712 case FSCACHE_OP_ASYNC:
60713 _debug("queue async");
60714 @@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
60715 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
60716 if (op->processor)
60717 fscache_enqueue_operation(op);
60718 - fscache_stat(&fscache_n_op_run);
60719 + fscache_stat_unchecked(&fscache_n_op_run);
60720 }
60721
60722 /*
60723 @@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60724 if (object->n_in_progress > 0) {
60725 atomic_inc(&op->usage);
60726 list_add_tail(&op->pend_link, &object->pending_ops);
60727 - fscache_stat(&fscache_n_op_pend);
60728 + fscache_stat_unchecked(&fscache_n_op_pend);
60729 } else if (!list_empty(&object->pending_ops)) {
60730 atomic_inc(&op->usage);
60731 list_add_tail(&op->pend_link, &object->pending_ops);
60732 - fscache_stat(&fscache_n_op_pend);
60733 + fscache_stat_unchecked(&fscache_n_op_pend);
60734 fscache_start_operations(object);
60735 } else {
60736 ASSERTCMP(object->n_in_progress, ==, 0);
60737 @@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60738 object->n_exclusive++; /* reads and writes must wait */
60739 atomic_inc(&op->usage);
60740 list_add_tail(&op->pend_link, &object->pending_ops);
60741 - fscache_stat(&fscache_n_op_pend);
60742 + fscache_stat_unchecked(&fscache_n_op_pend);
60743 ret = 0;
60744 } else {
60745 /* If we're in any other state, there must have been an I/O
60746 @@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
60747 if (object->n_exclusive > 0) {
60748 atomic_inc(&op->usage);
60749 list_add_tail(&op->pend_link, &object->pending_ops);
60750 - fscache_stat(&fscache_n_op_pend);
60751 + fscache_stat_unchecked(&fscache_n_op_pend);
60752 } else if (!list_empty(&object->pending_ops)) {
60753 atomic_inc(&op->usage);
60754 list_add_tail(&op->pend_link, &object->pending_ops);
60755 - fscache_stat(&fscache_n_op_pend);
60756 + fscache_stat_unchecked(&fscache_n_op_pend);
60757 fscache_start_operations(object);
60758 } else {
60759 ASSERTCMP(object->n_exclusive, ==, 0);
60760 @@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
60761 object->n_ops++;
60762 atomic_inc(&op->usage);
60763 list_add_tail(&op->pend_link, &object->pending_ops);
60764 - fscache_stat(&fscache_n_op_pend);
60765 + fscache_stat_unchecked(&fscache_n_op_pend);
60766 ret = 0;
60767 } else if (fscache_object_is_dying(object)) {
60768 - fscache_stat(&fscache_n_op_rejected);
60769 + fscache_stat_unchecked(&fscache_n_op_rejected);
60770 op->state = FSCACHE_OP_ST_CANCELLED;
60771 ret = -ENOBUFS;
60772 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
60773 @@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
60774 ret = -EBUSY;
60775 if (op->state == FSCACHE_OP_ST_PENDING) {
60776 ASSERT(!list_empty(&op->pend_link));
60777 - fscache_stat(&fscache_n_op_cancelled);
60778 + fscache_stat_unchecked(&fscache_n_op_cancelled);
60779 list_del_init(&op->pend_link);
60780 if (do_cancel)
60781 do_cancel(op);
60782 @@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
60783 while (!list_empty(&object->pending_ops)) {
60784 op = list_entry(object->pending_ops.next,
60785 struct fscache_operation, pend_link);
60786 - fscache_stat(&fscache_n_op_cancelled);
60787 + fscache_stat_unchecked(&fscache_n_op_cancelled);
60788 list_del_init(&op->pend_link);
60789
60790 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
60791 @@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
60792 op->state, ==, FSCACHE_OP_ST_CANCELLED);
60793 op->state = FSCACHE_OP_ST_DEAD;
60794
60795 - fscache_stat(&fscache_n_op_release);
60796 + fscache_stat_unchecked(&fscache_n_op_release);
60797
60798 if (op->release) {
60799 op->release(op);
60800 @@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
60801 * lock, and defer it otherwise */
60802 if (!spin_trylock(&object->lock)) {
60803 _debug("defer put");
60804 - fscache_stat(&fscache_n_op_deferred_release);
60805 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
60806
60807 cache = object->cache;
60808 spin_lock(&cache->op_gc_list_lock);
60809 @@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
60810
60811 _debug("GC DEFERRED REL OBJ%x OP%x",
60812 object->debug_id, op->debug_id);
60813 - fscache_stat(&fscache_n_op_gc);
60814 + fscache_stat_unchecked(&fscache_n_op_gc);
60815
60816 ASSERTCMP(atomic_read(&op->usage), ==, 0);
60817 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
60818 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
60819 index 7f5c658..6c1e164 100644
60820 --- a/fs/fscache/page.c
60821 +++ b/fs/fscache/page.c
60822 @@ -61,7 +61,7 @@ try_again:
60823 val = radix_tree_lookup(&cookie->stores, page->index);
60824 if (!val) {
60825 rcu_read_unlock();
60826 - fscache_stat(&fscache_n_store_vmscan_not_storing);
60827 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
60828 __fscache_uncache_page(cookie, page);
60829 return true;
60830 }
60831 @@ -91,11 +91,11 @@ try_again:
60832 spin_unlock(&cookie->stores_lock);
60833
60834 if (xpage) {
60835 - fscache_stat(&fscache_n_store_vmscan_cancelled);
60836 - fscache_stat(&fscache_n_store_radix_deletes);
60837 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
60838 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60839 ASSERTCMP(xpage, ==, page);
60840 } else {
60841 - fscache_stat(&fscache_n_store_vmscan_gone);
60842 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
60843 }
60844
60845 wake_up_bit(&cookie->flags, 0);
60846 @@ -110,11 +110,11 @@ page_busy:
60847 * sleeping on memory allocation, so we may need to impose a timeout
60848 * too. */
60849 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
60850 - fscache_stat(&fscache_n_store_vmscan_busy);
60851 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
60852 return false;
60853 }
60854
60855 - fscache_stat(&fscache_n_store_vmscan_wait);
60856 + fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
60857 __fscache_wait_on_page_write(cookie, page);
60858 gfp &= ~__GFP_WAIT;
60859 goto try_again;
60860 @@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
60861 FSCACHE_COOKIE_STORING_TAG);
60862 if (!radix_tree_tag_get(&cookie->stores, page->index,
60863 FSCACHE_COOKIE_PENDING_TAG)) {
60864 - fscache_stat(&fscache_n_store_radix_deletes);
60865 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60866 xpage = radix_tree_delete(&cookie->stores, page->index);
60867 }
60868 spin_unlock(&cookie->stores_lock);
60869 @@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
60870
60871 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
60872
60873 - fscache_stat(&fscache_n_attr_changed_calls);
60874 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
60875
60876 if (fscache_object_is_active(object)) {
60877 fscache_stat(&fscache_n_cop_attr_changed);
60878 @@ -188,11 +188,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60879
60880 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60881
60882 - fscache_stat(&fscache_n_attr_changed);
60883 + fscache_stat_unchecked(&fscache_n_attr_changed);
60884
60885 op = kzalloc(sizeof(*op), GFP_KERNEL);
60886 if (!op) {
60887 - fscache_stat(&fscache_n_attr_changed_nomem);
60888 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
60889 _leave(" = -ENOMEM");
60890 return -ENOMEM;
60891 }
60892 @@ -214,7 +214,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60893 if (fscache_submit_exclusive_op(object, op) < 0)
60894 goto nobufs;
60895 spin_unlock(&cookie->lock);
60896 - fscache_stat(&fscache_n_attr_changed_ok);
60897 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
60898 fscache_put_operation(op);
60899 _leave(" = 0");
60900 return 0;
60901 @@ -225,7 +225,7 @@ nobufs:
60902 kfree(op);
60903 if (wake_cookie)
60904 __fscache_wake_unused_cookie(cookie);
60905 - fscache_stat(&fscache_n_attr_changed_nobufs);
60906 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
60907 _leave(" = %d", -ENOBUFS);
60908 return -ENOBUFS;
60909 }
60910 @@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
60911 /* allocate a retrieval operation and attempt to submit it */
60912 op = kzalloc(sizeof(*op), GFP_NOIO);
60913 if (!op) {
60914 - fscache_stat(&fscache_n_retrievals_nomem);
60915 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60916 return NULL;
60917 }
60918
60919 @@ -294,13 +294,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
60920 return 0;
60921 }
60922
60923 - fscache_stat(&fscache_n_retrievals_wait);
60924 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
60925
60926 jif = jiffies;
60927 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
60928 fscache_wait_bit_interruptible,
60929 TASK_INTERRUPTIBLE) != 0) {
60930 - fscache_stat(&fscache_n_retrievals_intr);
60931 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
60932 _leave(" = -ERESTARTSYS");
60933 return -ERESTARTSYS;
60934 }
60935 @@ -329,8 +329,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
60936 */
60937 int fscache_wait_for_operation_activation(struct fscache_object *object,
60938 struct fscache_operation *op,
60939 - atomic_t *stat_op_waits,
60940 - atomic_t *stat_object_dead,
60941 + atomic_unchecked_t *stat_op_waits,
60942 + atomic_unchecked_t *stat_object_dead,
60943 void (*do_cancel)(struct fscache_operation *))
60944 {
60945 int ret;
60946 @@ -340,7 +340,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60947
60948 _debug(">>> WT");
60949 if (stat_op_waits)
60950 - fscache_stat(stat_op_waits);
60951 + fscache_stat_unchecked(stat_op_waits);
60952 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
60953 fscache_wait_bit_interruptible,
60954 TASK_INTERRUPTIBLE) != 0) {
60955 @@ -358,7 +358,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60956 check_if_dead:
60957 if (op->state == FSCACHE_OP_ST_CANCELLED) {
60958 if (stat_object_dead)
60959 - fscache_stat(stat_object_dead);
60960 + fscache_stat_unchecked(stat_object_dead);
60961 _leave(" = -ENOBUFS [cancelled]");
60962 return -ENOBUFS;
60963 }
60964 @@ -366,7 +366,7 @@ check_if_dead:
60965 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
60966 fscache_cancel_op(op, do_cancel);
60967 if (stat_object_dead)
60968 - fscache_stat(stat_object_dead);
60969 + fscache_stat_unchecked(stat_object_dead);
60970 return -ENOBUFS;
60971 }
60972 return 0;
60973 @@ -394,7 +394,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60974
60975 _enter("%p,%p,,,", cookie, page);
60976
60977 - fscache_stat(&fscache_n_retrievals);
60978 + fscache_stat_unchecked(&fscache_n_retrievals);
60979
60980 if (hlist_empty(&cookie->backing_objects))
60981 goto nobufs;
60982 @@ -436,7 +436,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60983 goto nobufs_unlock_dec;
60984 spin_unlock(&cookie->lock);
60985
60986 - fscache_stat(&fscache_n_retrieval_ops);
60987 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
60988
60989 /* pin the netfs read context in case we need to do the actual netfs
60990 * read because we've encountered a cache read failure */
60991 @@ -467,15 +467,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60992
60993 error:
60994 if (ret == -ENOMEM)
60995 - fscache_stat(&fscache_n_retrievals_nomem);
60996 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60997 else if (ret == -ERESTARTSYS)
60998 - fscache_stat(&fscache_n_retrievals_intr);
60999 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
61000 else if (ret == -ENODATA)
61001 - fscache_stat(&fscache_n_retrievals_nodata);
61002 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
61003 else if (ret < 0)
61004 - fscache_stat(&fscache_n_retrievals_nobufs);
61005 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
61006 else
61007 - fscache_stat(&fscache_n_retrievals_ok);
61008 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
61009
61010 fscache_put_retrieval(op);
61011 _leave(" = %d", ret);
61012 @@ -490,7 +490,7 @@ nobufs_unlock:
61013 __fscache_wake_unused_cookie(cookie);
61014 kfree(op);
61015 nobufs:
61016 - fscache_stat(&fscache_n_retrievals_nobufs);
61017 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
61018 _leave(" = -ENOBUFS");
61019 return -ENOBUFS;
61020 }
61021 @@ -529,7 +529,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
61022
61023 _enter("%p,,%d,,,", cookie, *nr_pages);
61024
61025 - fscache_stat(&fscache_n_retrievals);
61026 + fscache_stat_unchecked(&fscache_n_retrievals);
61027
61028 if (hlist_empty(&cookie->backing_objects))
61029 goto nobufs;
61030 @@ -567,7 +567,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
61031 goto nobufs_unlock_dec;
61032 spin_unlock(&cookie->lock);
61033
61034 - fscache_stat(&fscache_n_retrieval_ops);
61035 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
61036
61037 /* pin the netfs read context in case we need to do the actual netfs
61038 * read because we've encountered a cache read failure */
61039 @@ -598,15 +598,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
61040
61041 error:
61042 if (ret == -ENOMEM)
61043 - fscache_stat(&fscache_n_retrievals_nomem);
61044 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
61045 else if (ret == -ERESTARTSYS)
61046 - fscache_stat(&fscache_n_retrievals_intr);
61047 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
61048 else if (ret == -ENODATA)
61049 - fscache_stat(&fscache_n_retrievals_nodata);
61050 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
61051 else if (ret < 0)
61052 - fscache_stat(&fscache_n_retrievals_nobufs);
61053 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
61054 else
61055 - fscache_stat(&fscache_n_retrievals_ok);
61056 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
61057
61058 fscache_put_retrieval(op);
61059 _leave(" = %d", ret);
61060 @@ -621,7 +621,7 @@ nobufs_unlock:
61061 if (wake_cookie)
61062 __fscache_wake_unused_cookie(cookie);
61063 nobufs:
61064 - fscache_stat(&fscache_n_retrievals_nobufs);
61065 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
61066 _leave(" = -ENOBUFS");
61067 return -ENOBUFS;
61068 }
61069 @@ -646,7 +646,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
61070
61071 _enter("%p,%p,,,", cookie, page);
61072
61073 - fscache_stat(&fscache_n_allocs);
61074 + fscache_stat_unchecked(&fscache_n_allocs);
61075
61076 if (hlist_empty(&cookie->backing_objects))
61077 goto nobufs;
61078 @@ -680,7 +680,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
61079 goto nobufs_unlock_dec;
61080 spin_unlock(&cookie->lock);
61081
61082 - fscache_stat(&fscache_n_alloc_ops);
61083 + fscache_stat_unchecked(&fscache_n_alloc_ops);
61084
61085 ret = fscache_wait_for_operation_activation(
61086 object, &op->op,
61087 @@ -697,11 +697,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
61088
61089 error:
61090 if (ret == -ERESTARTSYS)
61091 - fscache_stat(&fscache_n_allocs_intr);
61092 + fscache_stat_unchecked(&fscache_n_allocs_intr);
61093 else if (ret < 0)
61094 - fscache_stat(&fscache_n_allocs_nobufs);
61095 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
61096 else
61097 - fscache_stat(&fscache_n_allocs_ok);
61098 + fscache_stat_unchecked(&fscache_n_allocs_ok);
61099
61100 fscache_put_retrieval(op);
61101 _leave(" = %d", ret);
61102 @@ -715,7 +715,7 @@ nobufs_unlock:
61103 if (wake_cookie)
61104 __fscache_wake_unused_cookie(cookie);
61105 nobufs:
61106 - fscache_stat(&fscache_n_allocs_nobufs);
61107 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
61108 _leave(" = -ENOBUFS");
61109 return -ENOBUFS;
61110 }
61111 @@ -791,7 +791,7 @@ static void fscache_write_op(struct fscache_operation *_op)
61112
61113 spin_lock(&cookie->stores_lock);
61114
61115 - fscache_stat(&fscache_n_store_calls);
61116 + fscache_stat_unchecked(&fscache_n_store_calls);
61117
61118 /* find a page to store */
61119 page = NULL;
61120 @@ -802,7 +802,7 @@ static void fscache_write_op(struct fscache_operation *_op)
61121 page = results[0];
61122 _debug("gang %d [%lx]", n, page->index);
61123 if (page->index > op->store_limit) {
61124 - fscache_stat(&fscache_n_store_pages_over_limit);
61125 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
61126 goto superseded;
61127 }
61128
61129 @@ -814,7 +814,7 @@ static void fscache_write_op(struct fscache_operation *_op)
61130 spin_unlock(&cookie->stores_lock);
61131 spin_unlock(&object->lock);
61132
61133 - fscache_stat(&fscache_n_store_pages);
61134 + fscache_stat_unchecked(&fscache_n_store_pages);
61135 fscache_stat(&fscache_n_cop_write_page);
61136 ret = object->cache->ops->write_page(op, page);
61137 fscache_stat_d(&fscache_n_cop_write_page);
61138 @@ -918,7 +918,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
61139 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
61140 ASSERT(PageFsCache(page));
61141
61142 - fscache_stat(&fscache_n_stores);
61143 + fscache_stat_unchecked(&fscache_n_stores);
61144
61145 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
61146 _leave(" = -ENOBUFS [invalidating]");
61147 @@ -977,7 +977,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
61148 spin_unlock(&cookie->stores_lock);
61149 spin_unlock(&object->lock);
61150
61151 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
61152 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
61153 op->store_limit = object->store_limit;
61154
61155 __fscache_use_cookie(cookie);
61156 @@ -986,8 +986,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
61157
61158 spin_unlock(&cookie->lock);
61159 radix_tree_preload_end();
61160 - fscache_stat(&fscache_n_store_ops);
61161 - fscache_stat(&fscache_n_stores_ok);
61162 + fscache_stat_unchecked(&fscache_n_store_ops);
61163 + fscache_stat_unchecked(&fscache_n_stores_ok);
61164
61165 /* the work queue now carries its own ref on the object */
61166 fscache_put_operation(&op->op);
61167 @@ -995,14 +995,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
61168 return 0;
61169
61170 already_queued:
61171 - fscache_stat(&fscache_n_stores_again);
61172 + fscache_stat_unchecked(&fscache_n_stores_again);
61173 already_pending:
61174 spin_unlock(&cookie->stores_lock);
61175 spin_unlock(&object->lock);
61176 spin_unlock(&cookie->lock);
61177 radix_tree_preload_end();
61178 kfree(op);
61179 - fscache_stat(&fscache_n_stores_ok);
61180 + fscache_stat_unchecked(&fscache_n_stores_ok);
61181 _leave(" = 0");
61182 return 0;
61183
61184 @@ -1024,14 +1024,14 @@ nobufs:
61185 kfree(op);
61186 if (wake_cookie)
61187 __fscache_wake_unused_cookie(cookie);
61188 - fscache_stat(&fscache_n_stores_nobufs);
61189 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
61190 _leave(" = -ENOBUFS");
61191 return -ENOBUFS;
61192
61193 nomem_free:
61194 kfree(op);
61195 nomem:
61196 - fscache_stat(&fscache_n_stores_oom);
61197 + fscache_stat_unchecked(&fscache_n_stores_oom);
61198 _leave(" = -ENOMEM");
61199 return -ENOMEM;
61200 }
61201 @@ -1049,7 +1049,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
61202 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
61203 ASSERTCMP(page, !=, NULL);
61204
61205 - fscache_stat(&fscache_n_uncaches);
61206 + fscache_stat_unchecked(&fscache_n_uncaches);
61207
61208 /* cache withdrawal may beat us to it */
61209 if (!PageFsCache(page))
61210 @@ -1100,7 +1100,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
61211 struct fscache_cookie *cookie = op->op.object->cookie;
61212
61213 #ifdef CONFIG_FSCACHE_STATS
61214 - atomic_inc(&fscache_n_marks);
61215 + atomic_inc_unchecked(&fscache_n_marks);
61216 #endif
61217
61218 _debug("- mark %p{%lx}", page, page->index);
61219 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
61220 index 40d13c7..ddf52b9 100644
61221 --- a/fs/fscache/stats.c
61222 +++ b/fs/fscache/stats.c
61223 @@ -18,99 +18,99 @@
61224 /*
61225 * operation counters
61226 */
61227 -atomic_t fscache_n_op_pend;
61228 -atomic_t fscache_n_op_run;
61229 -atomic_t fscache_n_op_enqueue;
61230 -atomic_t fscache_n_op_requeue;
61231 -atomic_t fscache_n_op_deferred_release;
61232 -atomic_t fscache_n_op_release;
61233 -atomic_t fscache_n_op_gc;
61234 -atomic_t fscache_n_op_cancelled;
61235 -atomic_t fscache_n_op_rejected;
61236 +atomic_unchecked_t fscache_n_op_pend;
61237 +atomic_unchecked_t fscache_n_op_run;
61238 +atomic_unchecked_t fscache_n_op_enqueue;
61239 +atomic_unchecked_t fscache_n_op_requeue;
61240 +atomic_unchecked_t fscache_n_op_deferred_release;
61241 +atomic_unchecked_t fscache_n_op_release;
61242 +atomic_unchecked_t fscache_n_op_gc;
61243 +atomic_unchecked_t fscache_n_op_cancelled;
61244 +atomic_unchecked_t fscache_n_op_rejected;
61245
61246 -atomic_t fscache_n_attr_changed;
61247 -atomic_t fscache_n_attr_changed_ok;
61248 -atomic_t fscache_n_attr_changed_nobufs;
61249 -atomic_t fscache_n_attr_changed_nomem;
61250 -atomic_t fscache_n_attr_changed_calls;
61251 +atomic_unchecked_t fscache_n_attr_changed;
61252 +atomic_unchecked_t fscache_n_attr_changed_ok;
61253 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
61254 +atomic_unchecked_t fscache_n_attr_changed_nomem;
61255 +atomic_unchecked_t fscache_n_attr_changed_calls;
61256
61257 -atomic_t fscache_n_allocs;
61258 -atomic_t fscache_n_allocs_ok;
61259 -atomic_t fscache_n_allocs_wait;
61260 -atomic_t fscache_n_allocs_nobufs;
61261 -atomic_t fscache_n_allocs_intr;
61262 -atomic_t fscache_n_allocs_object_dead;
61263 -atomic_t fscache_n_alloc_ops;
61264 -atomic_t fscache_n_alloc_op_waits;
61265 +atomic_unchecked_t fscache_n_allocs;
61266 +atomic_unchecked_t fscache_n_allocs_ok;
61267 +atomic_unchecked_t fscache_n_allocs_wait;
61268 +atomic_unchecked_t fscache_n_allocs_nobufs;
61269 +atomic_unchecked_t fscache_n_allocs_intr;
61270 +atomic_unchecked_t fscache_n_allocs_object_dead;
61271 +atomic_unchecked_t fscache_n_alloc_ops;
61272 +atomic_unchecked_t fscache_n_alloc_op_waits;
61273
61274 -atomic_t fscache_n_retrievals;
61275 -atomic_t fscache_n_retrievals_ok;
61276 -atomic_t fscache_n_retrievals_wait;
61277 -atomic_t fscache_n_retrievals_nodata;
61278 -atomic_t fscache_n_retrievals_nobufs;
61279 -atomic_t fscache_n_retrievals_intr;
61280 -atomic_t fscache_n_retrievals_nomem;
61281 -atomic_t fscache_n_retrievals_object_dead;
61282 -atomic_t fscache_n_retrieval_ops;
61283 -atomic_t fscache_n_retrieval_op_waits;
61284 +atomic_unchecked_t fscache_n_retrievals;
61285 +atomic_unchecked_t fscache_n_retrievals_ok;
61286 +atomic_unchecked_t fscache_n_retrievals_wait;
61287 +atomic_unchecked_t fscache_n_retrievals_nodata;
61288 +atomic_unchecked_t fscache_n_retrievals_nobufs;
61289 +atomic_unchecked_t fscache_n_retrievals_intr;
61290 +atomic_unchecked_t fscache_n_retrievals_nomem;
61291 +atomic_unchecked_t fscache_n_retrievals_object_dead;
61292 +atomic_unchecked_t fscache_n_retrieval_ops;
61293 +atomic_unchecked_t fscache_n_retrieval_op_waits;
61294
61295 -atomic_t fscache_n_stores;
61296 -atomic_t fscache_n_stores_ok;
61297 -atomic_t fscache_n_stores_again;
61298 -atomic_t fscache_n_stores_nobufs;
61299 -atomic_t fscache_n_stores_oom;
61300 -atomic_t fscache_n_store_ops;
61301 -atomic_t fscache_n_store_calls;
61302 -atomic_t fscache_n_store_pages;
61303 -atomic_t fscache_n_store_radix_deletes;
61304 -atomic_t fscache_n_store_pages_over_limit;
61305 +atomic_unchecked_t fscache_n_stores;
61306 +atomic_unchecked_t fscache_n_stores_ok;
61307 +atomic_unchecked_t fscache_n_stores_again;
61308 +atomic_unchecked_t fscache_n_stores_nobufs;
61309 +atomic_unchecked_t fscache_n_stores_oom;
61310 +atomic_unchecked_t fscache_n_store_ops;
61311 +atomic_unchecked_t fscache_n_store_calls;
61312 +atomic_unchecked_t fscache_n_store_pages;
61313 +atomic_unchecked_t fscache_n_store_radix_deletes;
61314 +atomic_unchecked_t fscache_n_store_pages_over_limit;
61315
61316 -atomic_t fscache_n_store_vmscan_not_storing;
61317 -atomic_t fscache_n_store_vmscan_gone;
61318 -atomic_t fscache_n_store_vmscan_busy;
61319 -atomic_t fscache_n_store_vmscan_cancelled;
61320 -atomic_t fscache_n_store_vmscan_wait;
61321 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
61322 +atomic_unchecked_t fscache_n_store_vmscan_gone;
61323 +atomic_unchecked_t fscache_n_store_vmscan_busy;
61324 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
61325 +atomic_unchecked_t fscache_n_store_vmscan_wait;
61326
61327 -atomic_t fscache_n_marks;
61328 -atomic_t fscache_n_uncaches;
61329 +atomic_unchecked_t fscache_n_marks;
61330 +atomic_unchecked_t fscache_n_uncaches;
61331
61332 -atomic_t fscache_n_acquires;
61333 -atomic_t fscache_n_acquires_null;
61334 -atomic_t fscache_n_acquires_no_cache;
61335 -atomic_t fscache_n_acquires_ok;
61336 -atomic_t fscache_n_acquires_nobufs;
61337 -atomic_t fscache_n_acquires_oom;
61338 +atomic_unchecked_t fscache_n_acquires;
61339 +atomic_unchecked_t fscache_n_acquires_null;
61340 +atomic_unchecked_t fscache_n_acquires_no_cache;
61341 +atomic_unchecked_t fscache_n_acquires_ok;
61342 +atomic_unchecked_t fscache_n_acquires_nobufs;
61343 +atomic_unchecked_t fscache_n_acquires_oom;
61344
61345 -atomic_t fscache_n_invalidates;
61346 -atomic_t fscache_n_invalidates_run;
61347 +atomic_unchecked_t fscache_n_invalidates;
61348 +atomic_unchecked_t fscache_n_invalidates_run;
61349
61350 -atomic_t fscache_n_updates;
61351 -atomic_t fscache_n_updates_null;
61352 -atomic_t fscache_n_updates_run;
61353 +atomic_unchecked_t fscache_n_updates;
61354 +atomic_unchecked_t fscache_n_updates_null;
61355 +atomic_unchecked_t fscache_n_updates_run;
61356
61357 -atomic_t fscache_n_relinquishes;
61358 -atomic_t fscache_n_relinquishes_null;
61359 -atomic_t fscache_n_relinquishes_waitcrt;
61360 -atomic_t fscache_n_relinquishes_retire;
61361 +atomic_unchecked_t fscache_n_relinquishes;
61362 +atomic_unchecked_t fscache_n_relinquishes_null;
61363 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
61364 +atomic_unchecked_t fscache_n_relinquishes_retire;
61365
61366 -atomic_t fscache_n_cookie_index;
61367 -atomic_t fscache_n_cookie_data;
61368 -atomic_t fscache_n_cookie_special;
61369 +atomic_unchecked_t fscache_n_cookie_index;
61370 +atomic_unchecked_t fscache_n_cookie_data;
61371 +atomic_unchecked_t fscache_n_cookie_special;
61372
61373 -atomic_t fscache_n_object_alloc;
61374 -atomic_t fscache_n_object_no_alloc;
61375 -atomic_t fscache_n_object_lookups;
61376 -atomic_t fscache_n_object_lookups_negative;
61377 -atomic_t fscache_n_object_lookups_positive;
61378 -atomic_t fscache_n_object_lookups_timed_out;
61379 -atomic_t fscache_n_object_created;
61380 -atomic_t fscache_n_object_avail;
61381 -atomic_t fscache_n_object_dead;
61382 +atomic_unchecked_t fscache_n_object_alloc;
61383 +atomic_unchecked_t fscache_n_object_no_alloc;
61384 +atomic_unchecked_t fscache_n_object_lookups;
61385 +atomic_unchecked_t fscache_n_object_lookups_negative;
61386 +atomic_unchecked_t fscache_n_object_lookups_positive;
61387 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
61388 +atomic_unchecked_t fscache_n_object_created;
61389 +atomic_unchecked_t fscache_n_object_avail;
61390 +atomic_unchecked_t fscache_n_object_dead;
61391
61392 -atomic_t fscache_n_checkaux_none;
61393 -atomic_t fscache_n_checkaux_okay;
61394 -atomic_t fscache_n_checkaux_update;
61395 -atomic_t fscache_n_checkaux_obsolete;
61396 +atomic_unchecked_t fscache_n_checkaux_none;
61397 +atomic_unchecked_t fscache_n_checkaux_okay;
61398 +atomic_unchecked_t fscache_n_checkaux_update;
61399 +atomic_unchecked_t fscache_n_checkaux_obsolete;
61400
61401 atomic_t fscache_n_cop_alloc_object;
61402 atomic_t fscache_n_cop_lookup_object;
61403 @@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
61404 seq_puts(m, "FS-Cache statistics\n");
61405
61406 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
61407 - atomic_read(&fscache_n_cookie_index),
61408 - atomic_read(&fscache_n_cookie_data),
61409 - atomic_read(&fscache_n_cookie_special));
61410 + atomic_read_unchecked(&fscache_n_cookie_index),
61411 + atomic_read_unchecked(&fscache_n_cookie_data),
61412 + atomic_read_unchecked(&fscache_n_cookie_special));
61413
61414 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
61415 - atomic_read(&fscache_n_object_alloc),
61416 - atomic_read(&fscache_n_object_no_alloc),
61417 - atomic_read(&fscache_n_object_avail),
61418 - atomic_read(&fscache_n_object_dead));
61419 + atomic_read_unchecked(&fscache_n_object_alloc),
61420 + atomic_read_unchecked(&fscache_n_object_no_alloc),
61421 + atomic_read_unchecked(&fscache_n_object_avail),
61422 + atomic_read_unchecked(&fscache_n_object_dead));
61423 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
61424 - atomic_read(&fscache_n_checkaux_none),
61425 - atomic_read(&fscache_n_checkaux_okay),
61426 - atomic_read(&fscache_n_checkaux_update),
61427 - atomic_read(&fscache_n_checkaux_obsolete));
61428 + atomic_read_unchecked(&fscache_n_checkaux_none),
61429 + atomic_read_unchecked(&fscache_n_checkaux_okay),
61430 + atomic_read_unchecked(&fscache_n_checkaux_update),
61431 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
61432
61433 seq_printf(m, "Pages : mrk=%u unc=%u\n",
61434 - atomic_read(&fscache_n_marks),
61435 - atomic_read(&fscache_n_uncaches));
61436 + atomic_read_unchecked(&fscache_n_marks),
61437 + atomic_read_unchecked(&fscache_n_uncaches));
61438
61439 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
61440 " oom=%u\n",
61441 - atomic_read(&fscache_n_acquires),
61442 - atomic_read(&fscache_n_acquires_null),
61443 - atomic_read(&fscache_n_acquires_no_cache),
61444 - atomic_read(&fscache_n_acquires_ok),
61445 - atomic_read(&fscache_n_acquires_nobufs),
61446 - atomic_read(&fscache_n_acquires_oom));
61447 + atomic_read_unchecked(&fscache_n_acquires),
61448 + atomic_read_unchecked(&fscache_n_acquires_null),
61449 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
61450 + atomic_read_unchecked(&fscache_n_acquires_ok),
61451 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
61452 + atomic_read_unchecked(&fscache_n_acquires_oom));
61453
61454 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
61455 - atomic_read(&fscache_n_object_lookups),
61456 - atomic_read(&fscache_n_object_lookups_negative),
61457 - atomic_read(&fscache_n_object_lookups_positive),
61458 - atomic_read(&fscache_n_object_created),
61459 - atomic_read(&fscache_n_object_lookups_timed_out));
61460 + atomic_read_unchecked(&fscache_n_object_lookups),
61461 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
61462 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
61463 + atomic_read_unchecked(&fscache_n_object_created),
61464 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
61465
61466 seq_printf(m, "Invals : n=%u run=%u\n",
61467 - atomic_read(&fscache_n_invalidates),
61468 - atomic_read(&fscache_n_invalidates_run));
61469 + atomic_read_unchecked(&fscache_n_invalidates),
61470 + atomic_read_unchecked(&fscache_n_invalidates_run));
61471
61472 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
61473 - atomic_read(&fscache_n_updates),
61474 - atomic_read(&fscache_n_updates_null),
61475 - atomic_read(&fscache_n_updates_run));
61476 + atomic_read_unchecked(&fscache_n_updates),
61477 + atomic_read_unchecked(&fscache_n_updates_null),
61478 + atomic_read_unchecked(&fscache_n_updates_run));
61479
61480 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
61481 - atomic_read(&fscache_n_relinquishes),
61482 - atomic_read(&fscache_n_relinquishes_null),
61483 - atomic_read(&fscache_n_relinquishes_waitcrt),
61484 - atomic_read(&fscache_n_relinquishes_retire));
61485 + atomic_read_unchecked(&fscache_n_relinquishes),
61486 + atomic_read_unchecked(&fscache_n_relinquishes_null),
61487 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
61488 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
61489
61490 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
61491 - atomic_read(&fscache_n_attr_changed),
61492 - atomic_read(&fscache_n_attr_changed_ok),
61493 - atomic_read(&fscache_n_attr_changed_nobufs),
61494 - atomic_read(&fscache_n_attr_changed_nomem),
61495 - atomic_read(&fscache_n_attr_changed_calls));
61496 + atomic_read_unchecked(&fscache_n_attr_changed),
61497 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
61498 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
61499 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
61500 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
61501
61502 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
61503 - atomic_read(&fscache_n_allocs),
61504 - atomic_read(&fscache_n_allocs_ok),
61505 - atomic_read(&fscache_n_allocs_wait),
61506 - atomic_read(&fscache_n_allocs_nobufs),
61507 - atomic_read(&fscache_n_allocs_intr));
61508 + atomic_read_unchecked(&fscache_n_allocs),
61509 + atomic_read_unchecked(&fscache_n_allocs_ok),
61510 + atomic_read_unchecked(&fscache_n_allocs_wait),
61511 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
61512 + atomic_read_unchecked(&fscache_n_allocs_intr));
61513 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
61514 - atomic_read(&fscache_n_alloc_ops),
61515 - atomic_read(&fscache_n_alloc_op_waits),
61516 - atomic_read(&fscache_n_allocs_object_dead));
61517 + atomic_read_unchecked(&fscache_n_alloc_ops),
61518 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
61519 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
61520
61521 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
61522 " int=%u oom=%u\n",
61523 - atomic_read(&fscache_n_retrievals),
61524 - atomic_read(&fscache_n_retrievals_ok),
61525 - atomic_read(&fscache_n_retrievals_wait),
61526 - atomic_read(&fscache_n_retrievals_nodata),
61527 - atomic_read(&fscache_n_retrievals_nobufs),
61528 - atomic_read(&fscache_n_retrievals_intr),
61529 - atomic_read(&fscache_n_retrievals_nomem));
61530 + atomic_read_unchecked(&fscache_n_retrievals),
61531 + atomic_read_unchecked(&fscache_n_retrievals_ok),
61532 + atomic_read_unchecked(&fscache_n_retrievals_wait),
61533 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
61534 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
61535 + atomic_read_unchecked(&fscache_n_retrievals_intr),
61536 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
61537 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
61538 - atomic_read(&fscache_n_retrieval_ops),
61539 - atomic_read(&fscache_n_retrieval_op_waits),
61540 - atomic_read(&fscache_n_retrievals_object_dead));
61541 + atomic_read_unchecked(&fscache_n_retrieval_ops),
61542 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
61543 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
61544
61545 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
61546 - atomic_read(&fscache_n_stores),
61547 - atomic_read(&fscache_n_stores_ok),
61548 - atomic_read(&fscache_n_stores_again),
61549 - atomic_read(&fscache_n_stores_nobufs),
61550 - atomic_read(&fscache_n_stores_oom));
61551 + atomic_read_unchecked(&fscache_n_stores),
61552 + atomic_read_unchecked(&fscache_n_stores_ok),
61553 + atomic_read_unchecked(&fscache_n_stores_again),
61554 + atomic_read_unchecked(&fscache_n_stores_nobufs),
61555 + atomic_read_unchecked(&fscache_n_stores_oom));
61556 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
61557 - atomic_read(&fscache_n_store_ops),
61558 - atomic_read(&fscache_n_store_calls),
61559 - atomic_read(&fscache_n_store_pages),
61560 - atomic_read(&fscache_n_store_radix_deletes),
61561 - atomic_read(&fscache_n_store_pages_over_limit));
61562 + atomic_read_unchecked(&fscache_n_store_ops),
61563 + atomic_read_unchecked(&fscache_n_store_calls),
61564 + atomic_read_unchecked(&fscache_n_store_pages),
61565 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
61566 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
61567
61568 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
61569 - atomic_read(&fscache_n_store_vmscan_not_storing),
61570 - atomic_read(&fscache_n_store_vmscan_gone),
61571 - atomic_read(&fscache_n_store_vmscan_busy),
61572 - atomic_read(&fscache_n_store_vmscan_cancelled),
61573 - atomic_read(&fscache_n_store_vmscan_wait));
61574 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
61575 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
61576 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
61577 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
61578 + atomic_read_unchecked(&fscache_n_store_vmscan_wait));
61579
61580 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
61581 - atomic_read(&fscache_n_op_pend),
61582 - atomic_read(&fscache_n_op_run),
61583 - atomic_read(&fscache_n_op_enqueue),
61584 - atomic_read(&fscache_n_op_cancelled),
61585 - atomic_read(&fscache_n_op_rejected));
61586 + atomic_read_unchecked(&fscache_n_op_pend),
61587 + atomic_read_unchecked(&fscache_n_op_run),
61588 + atomic_read_unchecked(&fscache_n_op_enqueue),
61589 + atomic_read_unchecked(&fscache_n_op_cancelled),
61590 + atomic_read_unchecked(&fscache_n_op_rejected));
61591 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
61592 - atomic_read(&fscache_n_op_deferred_release),
61593 - atomic_read(&fscache_n_op_release),
61594 - atomic_read(&fscache_n_op_gc));
61595 + atomic_read_unchecked(&fscache_n_op_deferred_release),
61596 + atomic_read_unchecked(&fscache_n_op_release),
61597 + atomic_read_unchecked(&fscache_n_op_gc));
61598
61599 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
61600 atomic_read(&fscache_n_cop_alloc_object),
61601 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
61602 index 13b691a..1ffca5ae 100644
61603 --- a/fs/fuse/cuse.c
61604 +++ b/fs/fuse/cuse.c
61605 @@ -607,10 +607,12 @@ static int __init cuse_init(void)
61606 INIT_LIST_HEAD(&cuse_conntbl[i]);
61607
61608 /* inherit and extend fuse_dev_operations */
61609 - cuse_channel_fops = fuse_dev_operations;
61610 - cuse_channel_fops.owner = THIS_MODULE;
61611 - cuse_channel_fops.open = cuse_channel_open;
61612 - cuse_channel_fops.release = cuse_channel_release;
61613 + pax_open_kernel();
61614 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
61615 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
61616 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
61617 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
61618 + pax_close_kernel();
61619
61620 cuse_class = class_create(THIS_MODULE, "cuse");
61621 if (IS_ERR(cuse_class))
61622 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
61623 index 75fa055..73b76d8 100644
61624 --- a/fs/fuse/dev.c
61625 +++ b/fs/fuse/dev.c
61626 @@ -1318,7 +1318,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
61627 ret = 0;
61628 pipe_lock(pipe);
61629
61630 - if (!pipe->readers) {
61631 + if (!atomic_read(&pipe->readers)) {
61632 send_sig(SIGPIPE, current, 0);
61633 if (!ret)
61634 ret = -EPIPE;
61635 @@ -1347,7 +1347,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
61636 page_nr++;
61637 ret += buf->len;
61638
61639 - if (pipe->files)
61640 + if (atomic_read(&pipe->files))
61641 do_wakeup = 1;
61642 }
61643
61644 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
61645 index 202a972..c4836eb 100644
61646 --- a/fs/fuse/dir.c
61647 +++ b/fs/fuse/dir.c
61648 @@ -1479,7 +1479,7 @@ static char *read_link(struct dentry *dentry)
61649 return link;
61650 }
61651
61652 -static void free_link(char *link)
61653 +static void free_link(const char *link)
61654 {
61655 if (!IS_ERR(link))
61656 free_page((unsigned long) link);
61657 diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
61658 index 9c470fd..aae410e 100644
61659 --- a/fs/hostfs/hostfs_kern.c
61660 +++ b/fs/hostfs/hostfs_kern.c
61661 @@ -898,7 +898,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
61662
61663 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
61664 {
61665 - char *s = nd_get_link(nd);
61666 + const char *s = nd_get_link(nd);
61667 if (!IS_ERR(s))
61668 __putname(s);
61669 }
61670 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
61671 index e19d4c0..8a357a9 100644
61672 --- a/fs/hugetlbfs/inode.c
61673 +++ b/fs/hugetlbfs/inode.c
61674 @@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61675 struct mm_struct *mm = current->mm;
61676 struct vm_area_struct *vma;
61677 struct hstate *h = hstate_file(file);
61678 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
61679 struct vm_unmapped_area_info info;
61680
61681 if (len & ~huge_page_mask(h))
61682 @@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61683 return addr;
61684 }
61685
61686 +#ifdef CONFIG_PAX_RANDMMAP
61687 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
61688 +#endif
61689 +
61690 if (addr) {
61691 addr = ALIGN(addr, huge_page_size(h));
61692 vma = find_vma(mm, addr);
61693 - if (TASK_SIZE - len >= addr &&
61694 - (!vma || addr + len <= vma->vm_start))
61695 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
61696 return addr;
61697 }
61698
61699 info.flags = 0;
61700 info.length = len;
61701 info.low_limit = TASK_UNMAPPED_BASE;
61702 +
61703 +#ifdef CONFIG_PAX_RANDMMAP
61704 + if (mm->pax_flags & MF_PAX_RANDMMAP)
61705 + info.low_limit += mm->delta_mmap;
61706 +#endif
61707 +
61708 info.high_limit = TASK_SIZE;
61709 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
61710 info.align_offset = 0;
61711 @@ -921,7 +931,7 @@ static struct file_system_type hugetlbfs_fs_type = {
61712 };
61713 MODULE_ALIAS_FS("hugetlbfs");
61714
61715 -static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61716 +struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61717
61718 static int can_do_hugetlb_shm(void)
61719 {
61720 diff --git a/fs/inode.c b/fs/inode.c
61721 index d2fb2f2..a6444b0 100644
61722 --- a/fs/inode.c
61723 +++ b/fs/inode.c
61724 @@ -839,16 +839,20 @@ unsigned int get_next_ino(void)
61725 unsigned int *p = &get_cpu_var(last_ino);
61726 unsigned int res = *p;
61727
61728 +start:
61729 +
61730 #ifdef CONFIG_SMP
61731 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
61732 - static atomic_t shared_last_ino;
61733 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
61734 + static atomic_unchecked_t shared_last_ino;
61735 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
61736
61737 res = next - LAST_INO_BATCH;
61738 }
61739 #endif
61740
61741 - *p = ++res;
61742 + if (unlikely(!++res))
61743 + goto start; /* never zero */
61744 + *p = res;
61745 put_cpu_var(last_ino);
61746 return res;
61747 }
61748 diff --git a/fs/isofs/inode.c b/fs/isofs/inode.c
61749 index 4556ce1..5ddaf86 100644
61750 --- a/fs/isofs/inode.c
61751 +++ b/fs/isofs/inode.c
61752 @@ -61,7 +61,7 @@ static void isofs_put_super(struct super_block *sb)
61753 return;
61754 }
61755
61756 -static int isofs_read_inode(struct inode *);
61757 +static int isofs_read_inode(struct inode *, int relocated);
61758 static int isofs_statfs (struct dentry *, struct kstatfs *);
61759
61760 static struct kmem_cache *isofs_inode_cachep;
61761 @@ -1259,7 +1259,7 @@ out_toomany:
61762 goto out;
61763 }
61764
61765 -static int isofs_read_inode(struct inode *inode)
61766 +static int isofs_read_inode(struct inode *inode, int relocated)
61767 {
61768 struct super_block *sb = inode->i_sb;
61769 struct isofs_sb_info *sbi = ISOFS_SB(sb);
61770 @@ -1404,7 +1404,7 @@ static int isofs_read_inode(struct inode *inode)
61771 */
61772
61773 if (!high_sierra) {
61774 - parse_rock_ridge_inode(de, inode);
61775 + parse_rock_ridge_inode(de, inode, relocated);
61776 /* if we want uid/gid set, override the rock ridge setting */
61777 if (sbi->s_uid_set)
61778 inode->i_uid = sbi->s_uid;
61779 @@ -1483,9 +1483,10 @@ static int isofs_iget5_set(struct inode *ino, void *data)
61780 * offset that point to the underlying meta-data for the inode. The
61781 * code below is otherwise similar to the iget() code in
61782 * include/linux/fs.h */
61783 -struct inode *isofs_iget(struct super_block *sb,
61784 - unsigned long block,
61785 - unsigned long offset)
61786 +struct inode *__isofs_iget(struct super_block *sb,
61787 + unsigned long block,
61788 + unsigned long offset,
61789 + int relocated)
61790 {
61791 unsigned long hashval;
61792 struct inode *inode;
61793 @@ -1507,7 +1508,7 @@ struct inode *isofs_iget(struct super_block *sb,
61794 return ERR_PTR(-ENOMEM);
61795
61796 if (inode->i_state & I_NEW) {
61797 - ret = isofs_read_inode(inode);
61798 + ret = isofs_read_inode(inode, relocated);
61799 if (ret < 0) {
61800 iget_failed(inode);
61801 inode = ERR_PTR(ret);
61802 diff --git a/fs/isofs/isofs.h b/fs/isofs/isofs.h
61803 index 9916723..0ac4c1f 100644
61804 --- a/fs/isofs/isofs.h
61805 +++ b/fs/isofs/isofs.h
61806 @@ -107,7 +107,7 @@ extern int iso_date(char *, int);
61807
61808 struct inode; /* To make gcc happy */
61809
61810 -extern int parse_rock_ridge_inode(struct iso_directory_record *, struct inode *);
61811 +extern int parse_rock_ridge_inode(struct iso_directory_record *, struct inode *, int relocated);
61812 extern int get_rock_ridge_filename(struct iso_directory_record *, char *, struct inode *);
61813 extern int isofs_name_translate(struct iso_directory_record *, char *, struct inode *);
61814
61815 @@ -118,9 +118,24 @@ extern struct dentry *isofs_lookup(struct inode *, struct dentry *, unsigned int
61816 extern struct buffer_head *isofs_bread(struct inode *, sector_t);
61817 extern int isofs_get_blocks(struct inode *, sector_t, struct buffer_head **, unsigned long);
61818
61819 -extern struct inode *isofs_iget(struct super_block *sb,
61820 - unsigned long block,
61821 - unsigned long offset);
61822 +struct inode *__isofs_iget(struct super_block *sb,
61823 + unsigned long block,
61824 + unsigned long offset,
61825 + int relocated);
61826 +
61827 +static inline struct inode *isofs_iget(struct super_block *sb,
61828 + unsigned long block,
61829 + unsigned long offset)
61830 +{
61831 + return __isofs_iget(sb, block, offset, 0);
61832 +}
61833 +
61834 +static inline struct inode *isofs_iget_reloc(struct super_block *sb,
61835 + unsigned long block,
61836 + unsigned long offset)
61837 +{
61838 + return __isofs_iget(sb, block, offset, 1);
61839 +}
61840
61841 /* Because the inode number is no longer relevant to finding the
61842 * underlying meta-data for an inode, we are free to choose a more
61843 diff --git a/fs/isofs/rock.c b/fs/isofs/rock.c
61844 index c0bf424..f488bba 100644
61845 --- a/fs/isofs/rock.c
61846 +++ b/fs/isofs/rock.c
61847 @@ -288,12 +288,16 @@ eio:
61848 goto out;
61849 }
61850
61851 +#define RR_REGARD_XA 1
61852 +#define RR_RELOC_DE 2
61853 +
61854 static int
61855 parse_rock_ridge_inode_internal(struct iso_directory_record *de,
61856 - struct inode *inode, int regard_xa)
61857 + struct inode *inode, int flags)
61858 {
61859 int symlink_len = 0;
61860 int cnt, sig;
61861 + unsigned int reloc_block;
61862 struct inode *reloc;
61863 struct rock_ridge *rr;
61864 int rootflag;
61865 @@ -305,7 +309,7 @@ parse_rock_ridge_inode_internal(struct iso_directory_record *de,
61866
61867 init_rock_state(&rs, inode);
61868 setup_rock_ridge(de, inode, &rs);
61869 - if (regard_xa) {
61870 + if (flags & RR_REGARD_XA) {
61871 rs.chr += 14;
61872 rs.len -= 14;
61873 if (rs.len < 0)
61874 @@ -485,12 +489,22 @@ repeat:
61875 "relocated directory\n");
61876 goto out;
61877 case SIG('C', 'L'):
61878 - ISOFS_I(inode)->i_first_extent =
61879 - isonum_733(rr->u.CL.location);
61880 - reloc =
61881 - isofs_iget(inode->i_sb,
61882 - ISOFS_I(inode)->i_first_extent,
61883 - 0);
61884 + if (flags & RR_RELOC_DE) {
61885 + printk(KERN_ERR
61886 + "ISOFS: Recursive directory relocation "
61887 + "is not supported\n");
61888 + goto eio;
61889 + }
61890 + reloc_block = isonum_733(rr->u.CL.location);
61891 + if (reloc_block == ISOFS_I(inode)->i_iget5_block &&
61892 + ISOFS_I(inode)->i_iget5_offset == 0) {
61893 + printk(KERN_ERR
61894 + "ISOFS: Directory relocation points to "
61895 + "itself\n");
61896 + goto eio;
61897 + }
61898 + ISOFS_I(inode)->i_first_extent = reloc_block;
61899 + reloc = isofs_iget_reloc(inode->i_sb, reloc_block, 0);
61900 if (IS_ERR(reloc)) {
61901 ret = PTR_ERR(reloc);
61902 goto out;
61903 @@ -637,9 +651,11 @@ static char *get_symlink_chunk(char *rpnt, struct rock_ridge *rr, char *plimit)
61904 return rpnt;
61905 }
61906
61907 -int parse_rock_ridge_inode(struct iso_directory_record *de, struct inode *inode)
61908 +int parse_rock_ridge_inode(struct iso_directory_record *de, struct inode *inode,
61909 + int relocated)
61910 {
61911 - int result = parse_rock_ridge_inode_internal(de, inode, 0);
61912 + int flags = relocated ? RR_RELOC_DE : 0;
61913 + int result = parse_rock_ridge_inode_internal(de, inode, flags);
61914
61915 /*
61916 * if rockridge flag was reset and we didn't look for attributes
61917 @@ -647,7 +663,8 @@ int parse_rock_ridge_inode(struct iso_directory_record *de, struct inode *inode)
61918 */
61919 if ((ISOFS_SB(inode->i_sb)->s_rock_offset == -1)
61920 && (ISOFS_SB(inode->i_sb)->s_rock == 2)) {
61921 - result = parse_rock_ridge_inode_internal(de, inode, 14);
61922 + result = parse_rock_ridge_inode_internal(de, inode,
61923 + flags | RR_REGARD_XA);
61924 }
61925 return result;
61926 }
61927 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
61928 index 4a6cf28..d3a29d3 100644
61929 --- a/fs/jffs2/erase.c
61930 +++ b/fs/jffs2/erase.c
61931 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
61932 struct jffs2_unknown_node marker = {
61933 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
61934 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61935 - .totlen = cpu_to_je32(c->cleanmarker_size)
61936 + .totlen = cpu_to_je32(c->cleanmarker_size),
61937 + .hdr_crc = cpu_to_je32(0)
61938 };
61939
61940 jffs2_prealloc_raw_node_refs(c, jeb, 1);
61941 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
61942 index a6597d6..41b30ec 100644
61943 --- a/fs/jffs2/wbuf.c
61944 +++ b/fs/jffs2/wbuf.c
61945 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
61946 {
61947 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
61948 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61949 - .totlen = constant_cpu_to_je32(8)
61950 + .totlen = constant_cpu_to_je32(8),
61951 + .hdr_crc = constant_cpu_to_je32(0)
61952 };
61953
61954 /*
61955 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
61956 index 97f7fda..09bd33d 100644
61957 --- a/fs/jfs/super.c
61958 +++ b/fs/jfs/super.c
61959 @@ -885,7 +885,7 @@ static int __init init_jfs_fs(void)
61960
61961 jfs_inode_cachep =
61962 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
61963 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
61964 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
61965 init_once);
61966 if (jfs_inode_cachep == NULL)
61967 return -ENOMEM;
61968 diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
61969 index a693f5b..82276a1 100644
61970 --- a/fs/kernfs/dir.c
61971 +++ b/fs/kernfs/dir.c
61972 @@ -182,7 +182,7 @@ struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn)
61973 *
61974 * Returns 31 bit hash of ns + name (so it fits in an off_t )
61975 */
61976 -static unsigned int kernfs_name_hash(const char *name, const void *ns)
61977 +static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
61978 {
61979 unsigned long hash = init_name_hash();
61980 unsigned int len = strlen(name);
61981 diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
61982 index 5e9a80c..3853a24 100644
61983 --- a/fs/kernfs/file.c
61984 +++ b/fs/kernfs/file.c
61985 @@ -33,7 +33,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
61986
61987 struct kernfs_open_node {
61988 atomic_t refcnt;
61989 - atomic_t event;
61990 + atomic_unchecked_t event;
61991 wait_queue_head_t poll;
61992 struct list_head files; /* goes through kernfs_open_file.list */
61993 };
61994 @@ -149,7 +149,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
61995 {
61996 struct kernfs_open_file *of = sf->private;
61997
61998 - of->event = atomic_read(&of->kn->attr.open->event);
61999 + of->event = atomic_read_unchecked(&of->kn->attr.open->event);
62000
62001 return of->kn->attr.ops->seq_show(sf, v);
62002 }
62003 @@ -361,12 +361,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
62004 return ret;
62005 }
62006
62007 -static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
62008 - void *buf, int len, int write)
62009 +static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
62010 + void *buf, size_t len, int write)
62011 {
62012 struct file *file = vma->vm_file;
62013 struct kernfs_open_file *of = kernfs_of(file);
62014 - int ret;
62015 + ssize_t ret;
62016
62017 if (!of->vm_ops)
62018 return -EINVAL;
62019 @@ -567,7 +567,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
62020 return -ENOMEM;
62021
62022 atomic_set(&new_on->refcnt, 0);
62023 - atomic_set(&new_on->event, 1);
62024 + atomic_set_unchecked(&new_on->event, 1);
62025 init_waitqueue_head(&new_on->poll);
62026 INIT_LIST_HEAD(&new_on->files);
62027 goto retry;
62028 @@ -773,7 +773,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
62029
62030 kernfs_put_active(kn);
62031
62032 - if (of->event != atomic_read(&on->event))
62033 + if (of->event != atomic_read_unchecked(&on->event))
62034 goto trigger;
62035
62036 return DEFAULT_POLLMASK;
62037 @@ -798,7 +798,7 @@ void kernfs_notify(struct kernfs_node *kn)
62038 if (!WARN_ON(kernfs_type(kn) != KERNFS_FILE)) {
62039 on = kn->attr.open;
62040 if (on) {
62041 - atomic_inc(&on->event);
62042 + atomic_inc_unchecked(&on->event);
62043 wake_up_interruptible(&on->poll);
62044 }
62045 }
62046 diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
62047 index 8a19889..4c3069a 100644
62048 --- a/fs/kernfs/symlink.c
62049 +++ b/fs/kernfs/symlink.c
62050 @@ -128,7 +128,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
62051 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
62052 void *cookie)
62053 {
62054 - char *page = nd_get_link(nd);
62055 + const char *page = nd_get_link(nd);
62056 if (!IS_ERR(page))
62057 free_page((unsigned long)page);
62058 }
62059 diff --git a/fs/libfs.c b/fs/libfs.c
62060 index a184424..944ddce 100644
62061 --- a/fs/libfs.c
62062 +++ b/fs/libfs.c
62063 @@ -159,6 +159,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
62064
62065 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
62066 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
62067 + char d_name[sizeof(next->d_iname)];
62068 + const unsigned char *name;
62069 +
62070 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
62071 if (!simple_positive(next)) {
62072 spin_unlock(&next->d_lock);
62073 @@ -167,7 +170,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
62074
62075 spin_unlock(&next->d_lock);
62076 spin_unlock(&dentry->d_lock);
62077 - if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
62078 + name = next->d_name.name;
62079 + if (name == next->d_iname) {
62080 + memcpy(d_name, name, next->d_name.len);
62081 + name = d_name;
62082 + }
62083 + if (!dir_emit(ctx, name, next->d_name.len,
62084 next->d_inode->i_ino, dt_type(next->d_inode)))
62085 return 0;
62086 spin_lock(&dentry->d_lock);
62087 @@ -999,7 +1007,7 @@ EXPORT_SYMBOL(noop_fsync);
62088 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
62089 void *cookie)
62090 {
62091 - char *s = nd_get_link(nd);
62092 + const char *s = nd_get_link(nd);
62093 if (!IS_ERR(s))
62094 kfree(s);
62095 }
62096 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
62097 index acd3947..1f896e2 100644
62098 --- a/fs/lockd/clntproc.c
62099 +++ b/fs/lockd/clntproc.c
62100 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
62101 /*
62102 * Cookie counter for NLM requests
62103 */
62104 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
62105 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
62106
62107 void nlmclnt_next_cookie(struct nlm_cookie *c)
62108 {
62109 - u32 cookie = atomic_inc_return(&nlm_cookie);
62110 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
62111
62112 memcpy(c->data, &cookie, 4);
62113 c->len=4;
62114 diff --git a/fs/locks.c b/fs/locks.c
62115 index e390bd9..c79870e 100644
62116 --- a/fs/locks.c
62117 +++ b/fs/locks.c
62118 @@ -2315,16 +2315,16 @@ void locks_remove_file(struct file *filp)
62119 locks_remove_posix(filp, (fl_owner_t)filp);
62120
62121 if (filp->f_op->flock) {
62122 - struct file_lock fl = {
62123 + struct file_lock flock = {
62124 .fl_pid = current->tgid,
62125 .fl_file = filp,
62126 .fl_flags = FL_FLOCK,
62127 .fl_type = F_UNLCK,
62128 .fl_end = OFFSET_MAX,
62129 };
62130 - filp->f_op->flock(filp, F_SETLKW, &fl);
62131 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
62132 - fl.fl_ops->fl_release_private(&fl);
62133 + filp->f_op->flock(filp, F_SETLKW, &flock);
62134 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
62135 + flock.fl_ops->fl_release_private(&flock);
62136 }
62137
62138 spin_lock(&inode->i_lock);
62139 diff --git a/fs/mount.h b/fs/mount.h
62140 index d55297f..f5b28c5 100644
62141 --- a/fs/mount.h
62142 +++ b/fs/mount.h
62143 @@ -11,7 +11,7 @@ struct mnt_namespace {
62144 u64 seq; /* Sequence number to prevent loops */
62145 wait_queue_head_t poll;
62146 u64 event;
62147 -};
62148 +} __randomize_layout;
62149
62150 struct mnt_pcp {
62151 int mnt_count;
62152 @@ -57,7 +57,7 @@ struct mount {
62153 int mnt_expiry_mark; /* true if marked for expiry */
62154 int mnt_pinned;
62155 struct path mnt_ex_mountpoint;
62156 -};
62157 +} __randomize_layout;
62158
62159 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
62160
62161 diff --git a/fs/namei.c b/fs/namei.c
62162 index 9eb787e..5f520b67 100644
62163 --- a/fs/namei.c
62164 +++ b/fs/namei.c
62165 @@ -330,17 +330,32 @@ int generic_permission(struct inode *inode, int mask)
62166 if (ret != -EACCES)
62167 return ret;
62168
62169 +#ifdef CONFIG_GRKERNSEC
62170 + /* we'll block if we have to log due to a denied capability use */
62171 + if (mask & MAY_NOT_BLOCK)
62172 + return -ECHILD;
62173 +#endif
62174 +
62175 if (S_ISDIR(inode->i_mode)) {
62176 /* DACs are overridable for directories */
62177 - if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
62178 - return 0;
62179 if (!(mask & MAY_WRITE))
62180 - if (capable_wrt_inode_uidgid(inode,
62181 - CAP_DAC_READ_SEARCH))
62182 + if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
62183 + capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
62184 return 0;
62185 + if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
62186 + return 0;
62187 return -EACCES;
62188 }
62189 /*
62190 + * Searching includes executable on directories, else just read.
62191 + */
62192 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
62193 + if (mask == MAY_READ)
62194 + if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
62195 + capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
62196 + return 0;
62197 +
62198 + /*
62199 * Read/write DACs are always overridable.
62200 * Executable DACs are overridable when there is
62201 * at least one exec bit set.
62202 @@ -349,14 +364,6 @@ int generic_permission(struct inode *inode, int mask)
62203 if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
62204 return 0;
62205
62206 - /*
62207 - * Searching includes executable on directories, else just read.
62208 - */
62209 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
62210 - if (mask == MAY_READ)
62211 - if (capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
62212 - return 0;
62213 -
62214 return -EACCES;
62215 }
62216 EXPORT_SYMBOL(generic_permission);
62217 @@ -824,7 +831,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
62218 {
62219 struct dentry *dentry = link->dentry;
62220 int error;
62221 - char *s;
62222 + const char *s;
62223
62224 BUG_ON(nd->flags & LOOKUP_RCU);
62225
62226 @@ -845,6 +852,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
62227 if (error)
62228 goto out_put_nd_path;
62229
62230 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
62231 + dentry->d_inode, dentry, nd->path.mnt)) {
62232 + error = -EACCES;
62233 + goto out_put_nd_path;
62234 + }
62235 +
62236 nd->last_type = LAST_BIND;
62237 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
62238 error = PTR_ERR(*p);
62239 @@ -1596,6 +1609,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
62240 if (res)
62241 break;
62242 res = walk_component(nd, path, LOOKUP_FOLLOW);
62243 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
62244 + res = -EACCES;
62245 put_link(nd, &link, cookie);
62246 } while (res > 0);
62247
62248 @@ -1669,7 +1684,7 @@ EXPORT_SYMBOL(full_name_hash);
62249 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
62250 {
62251 unsigned long a, b, adata, bdata, mask, hash, len;
62252 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
62253 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
62254
62255 hash = a = 0;
62256 len = -sizeof(unsigned long);
62257 @@ -1953,6 +1968,8 @@ static int path_lookupat(int dfd, const char *name,
62258 if (err)
62259 break;
62260 err = lookup_last(nd, &path);
62261 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
62262 + err = -EACCES;
62263 put_link(nd, &link, cookie);
62264 }
62265 }
62266 @@ -1960,6 +1977,13 @@ static int path_lookupat(int dfd, const char *name,
62267 if (!err)
62268 err = complete_walk(nd);
62269
62270 + if (!err && !(nd->flags & LOOKUP_PARENT)) {
62271 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
62272 + path_put(&nd->path);
62273 + err = -ENOENT;
62274 + }
62275 + }
62276 +
62277 if (!err && nd->flags & LOOKUP_DIRECTORY) {
62278 if (!d_can_lookup(nd->path.dentry)) {
62279 path_put(&nd->path);
62280 @@ -1987,8 +2011,15 @@ static int filename_lookup(int dfd, struct filename *name,
62281 retval = path_lookupat(dfd, name->name,
62282 flags | LOOKUP_REVAL, nd);
62283
62284 - if (likely(!retval))
62285 + if (likely(!retval)) {
62286 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
62287 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
62288 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
62289 + path_put(&nd->path);
62290 + return -ENOENT;
62291 + }
62292 + }
62293 + }
62294 return retval;
62295 }
62296
62297 @@ -2570,6 +2601,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
62298 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
62299 return -EPERM;
62300
62301 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
62302 + return -EPERM;
62303 + if (gr_handle_rawio(inode))
62304 + return -EPERM;
62305 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
62306 + return -EACCES;
62307 +
62308 return 0;
62309 }
62310
62311 @@ -2801,7 +2839,7 @@ looked_up:
62312 * cleared otherwise prior to returning.
62313 */
62314 static int lookup_open(struct nameidata *nd, struct path *path,
62315 - struct file *file,
62316 + struct path *link, struct file *file,
62317 const struct open_flags *op,
62318 bool got_write, int *opened)
62319 {
62320 @@ -2836,6 +2874,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
62321 /* Negative dentry, just create the file */
62322 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
62323 umode_t mode = op->mode;
62324 +
62325 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
62326 + error = -EACCES;
62327 + goto out_dput;
62328 + }
62329 +
62330 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
62331 + error = -EACCES;
62332 + goto out_dput;
62333 + }
62334 +
62335 if (!IS_POSIXACL(dir->d_inode))
62336 mode &= ~current_umask();
62337 /*
62338 @@ -2857,6 +2906,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
62339 nd->flags & LOOKUP_EXCL);
62340 if (error)
62341 goto out_dput;
62342 + else
62343 + gr_handle_create(dentry, nd->path.mnt);
62344 }
62345 out_no_open:
62346 path->dentry = dentry;
62347 @@ -2871,7 +2922,7 @@ out_dput:
62348 /*
62349 * Handle the last step of open()
62350 */
62351 -static int do_last(struct nameidata *nd, struct path *path,
62352 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
62353 struct file *file, const struct open_flags *op,
62354 int *opened, struct filename *name)
62355 {
62356 @@ -2921,6 +2972,15 @@ static int do_last(struct nameidata *nd, struct path *path,
62357 if (error)
62358 return error;
62359
62360 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
62361 + error = -ENOENT;
62362 + goto out;
62363 + }
62364 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
62365 + error = -EACCES;
62366 + goto out;
62367 + }
62368 +
62369 audit_inode(name, dir, LOOKUP_PARENT);
62370 error = -EISDIR;
62371 /* trailing slashes? */
62372 @@ -2940,7 +3000,7 @@ retry_lookup:
62373 */
62374 }
62375 mutex_lock(&dir->d_inode->i_mutex);
62376 - error = lookup_open(nd, path, file, op, got_write, opened);
62377 + error = lookup_open(nd, path, link, file, op, got_write, opened);
62378 mutex_unlock(&dir->d_inode->i_mutex);
62379
62380 if (error <= 0) {
62381 @@ -2964,11 +3024,28 @@ retry_lookup:
62382 goto finish_open_created;
62383 }
62384
62385 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
62386 + error = -ENOENT;
62387 + goto exit_dput;
62388 + }
62389 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
62390 + error = -EACCES;
62391 + goto exit_dput;
62392 + }
62393 +
62394 /*
62395 * create/update audit record if it already exists.
62396 */
62397 - if (d_is_positive(path->dentry))
62398 + if (d_is_positive(path->dentry)) {
62399 + /* only check if O_CREAT is specified, all other checks need to go
62400 + into may_open */
62401 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
62402 + error = -EACCES;
62403 + goto exit_dput;
62404 + }
62405 +
62406 audit_inode(name, path->dentry, 0);
62407 + }
62408
62409 /*
62410 * If atomic_open() acquired write access it is dropped now due to
62411 @@ -3009,6 +3086,11 @@ finish_lookup:
62412 }
62413 }
62414 BUG_ON(inode != path->dentry->d_inode);
62415 + /* if we're resolving a symlink to another symlink */
62416 + if (link && gr_handle_symlink_owner(link, inode)) {
62417 + error = -EACCES;
62418 + goto out;
62419 + }
62420 return 1;
62421 }
62422
62423 @@ -3018,7 +3100,6 @@ finish_lookup:
62424 save_parent.dentry = nd->path.dentry;
62425 save_parent.mnt = mntget(path->mnt);
62426 nd->path.dentry = path->dentry;
62427 -
62428 }
62429 nd->inode = inode;
62430 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
62431 @@ -3028,7 +3109,18 @@ finish_open:
62432 path_put(&save_parent);
62433 return error;
62434 }
62435 +
62436 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
62437 + error = -ENOENT;
62438 + goto out;
62439 + }
62440 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
62441 + error = -EACCES;
62442 + goto out;
62443 + }
62444 +
62445 audit_inode(name, nd->path.dentry, 0);
62446 +
62447 error = -EISDIR;
62448 if ((open_flag & O_CREAT) && d_is_dir(nd->path.dentry))
62449 goto out;
62450 @@ -3191,7 +3283,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
62451 if (unlikely(error))
62452 goto out;
62453
62454 - error = do_last(nd, &path, file, op, &opened, pathname);
62455 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
62456 while (unlikely(error > 0)) { /* trailing symlink */
62457 struct path link = path;
62458 void *cookie;
62459 @@ -3209,7 +3301,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
62460 error = follow_link(&link, nd, &cookie);
62461 if (unlikely(error))
62462 break;
62463 - error = do_last(nd, &path, file, op, &opened, pathname);
62464 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
62465 put_link(nd, &link, cookie);
62466 }
62467 out:
62468 @@ -3309,9 +3401,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
62469 goto unlock;
62470
62471 error = -EEXIST;
62472 - if (d_is_positive(dentry))
62473 + if (d_is_positive(dentry)) {
62474 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
62475 + error = -ENOENT;
62476 goto fail;
62477 -
62478 + }
62479 /*
62480 * Special case - lookup gave negative, but... we had foo/bar/
62481 * From the vfs_mknod() POV we just have a negative dentry -
62482 @@ -3363,6 +3457,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
62483 }
62484 EXPORT_SYMBOL(user_path_create);
62485
62486 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
62487 +{
62488 + struct filename *tmp = getname(pathname);
62489 + struct dentry *res;
62490 + if (IS_ERR(tmp))
62491 + return ERR_CAST(tmp);
62492 + res = kern_path_create(dfd, tmp->name, path, lookup_flags);
62493 + if (IS_ERR(res))
62494 + putname(tmp);
62495 + else
62496 + *to = tmp;
62497 + return res;
62498 +}
62499 +
62500 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
62501 {
62502 int error = may_create(dir, dentry);
62503 @@ -3426,6 +3534,17 @@ retry:
62504
62505 if (!IS_POSIXACL(path.dentry->d_inode))
62506 mode &= ~current_umask();
62507 +
62508 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
62509 + error = -EPERM;
62510 + goto out;
62511 + }
62512 +
62513 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
62514 + error = -EACCES;
62515 + goto out;
62516 + }
62517 +
62518 error = security_path_mknod(&path, dentry, mode, dev);
62519 if (error)
62520 goto out;
62521 @@ -3442,6 +3561,8 @@ retry:
62522 break;
62523 }
62524 out:
62525 + if (!error)
62526 + gr_handle_create(dentry, path.mnt);
62527 done_path_create(&path, dentry);
62528 if (retry_estale(error, lookup_flags)) {
62529 lookup_flags |= LOOKUP_REVAL;
62530 @@ -3495,9 +3616,16 @@ retry:
62531
62532 if (!IS_POSIXACL(path.dentry->d_inode))
62533 mode &= ~current_umask();
62534 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
62535 + error = -EACCES;
62536 + goto out;
62537 + }
62538 error = security_path_mkdir(&path, dentry, mode);
62539 if (!error)
62540 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
62541 + if (!error)
62542 + gr_handle_create(dentry, path.mnt);
62543 +out:
62544 done_path_create(&path, dentry);
62545 if (retry_estale(error, lookup_flags)) {
62546 lookup_flags |= LOOKUP_REVAL;
62547 @@ -3580,6 +3708,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
62548 struct filename *name;
62549 struct dentry *dentry;
62550 struct nameidata nd;
62551 + ino_t saved_ino = 0;
62552 + dev_t saved_dev = 0;
62553 unsigned int lookup_flags = 0;
62554 retry:
62555 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
62556 @@ -3612,10 +3742,21 @@ retry:
62557 error = -ENOENT;
62558 goto exit3;
62559 }
62560 +
62561 + saved_ino = dentry->d_inode->i_ino;
62562 + saved_dev = gr_get_dev_from_dentry(dentry);
62563 +
62564 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
62565 + error = -EACCES;
62566 + goto exit3;
62567 + }
62568 +
62569 error = security_path_rmdir(&nd.path, dentry);
62570 if (error)
62571 goto exit3;
62572 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
62573 + if (!error && (saved_dev || saved_ino))
62574 + gr_handle_delete(saved_ino, saved_dev);
62575 exit3:
62576 dput(dentry);
62577 exit2:
62578 @@ -3706,6 +3847,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
62579 struct nameidata nd;
62580 struct inode *inode = NULL;
62581 struct inode *delegated_inode = NULL;
62582 + ino_t saved_ino = 0;
62583 + dev_t saved_dev = 0;
62584 unsigned int lookup_flags = 0;
62585 retry:
62586 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
62587 @@ -3732,10 +3875,22 @@ retry_deleg:
62588 if (d_is_negative(dentry))
62589 goto slashes;
62590 ihold(inode);
62591 +
62592 + if (inode->i_nlink <= 1) {
62593 + saved_ino = inode->i_ino;
62594 + saved_dev = gr_get_dev_from_dentry(dentry);
62595 + }
62596 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
62597 + error = -EACCES;
62598 + goto exit2;
62599 + }
62600 +
62601 error = security_path_unlink(&nd.path, dentry);
62602 if (error)
62603 goto exit2;
62604 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
62605 + if (!error && (saved_ino || saved_dev))
62606 + gr_handle_delete(saved_ino, saved_dev);
62607 exit2:
62608 dput(dentry);
62609 }
62610 @@ -3824,9 +3979,17 @@ retry:
62611 if (IS_ERR(dentry))
62612 goto out_putname;
62613
62614 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
62615 + error = -EACCES;
62616 + goto out;
62617 + }
62618 +
62619 error = security_path_symlink(&path, dentry, from->name);
62620 if (!error)
62621 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
62622 + if (!error)
62623 + gr_handle_create(dentry, path.mnt);
62624 +out:
62625 done_path_create(&path, dentry);
62626 if (retry_estale(error, lookup_flags)) {
62627 lookup_flags |= LOOKUP_REVAL;
62628 @@ -3930,6 +4093,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
62629 struct dentry *new_dentry;
62630 struct path old_path, new_path;
62631 struct inode *delegated_inode = NULL;
62632 + struct filename *to = NULL;
62633 int how = 0;
62634 int error;
62635
62636 @@ -3953,7 +4117,7 @@ retry:
62637 if (error)
62638 return error;
62639
62640 - new_dentry = user_path_create(newdfd, newname, &new_path,
62641 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
62642 (how & LOOKUP_REVAL));
62643 error = PTR_ERR(new_dentry);
62644 if (IS_ERR(new_dentry))
62645 @@ -3965,11 +4129,28 @@ retry:
62646 error = may_linkat(&old_path);
62647 if (unlikely(error))
62648 goto out_dput;
62649 +
62650 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
62651 + old_path.dentry->d_inode,
62652 + old_path.dentry->d_inode->i_mode, to)) {
62653 + error = -EACCES;
62654 + goto out_dput;
62655 + }
62656 +
62657 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
62658 + old_path.dentry, old_path.mnt, to)) {
62659 + error = -EACCES;
62660 + goto out_dput;
62661 + }
62662 +
62663 error = security_path_link(old_path.dentry, &new_path, new_dentry);
62664 if (error)
62665 goto out_dput;
62666 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
62667 + if (!error)
62668 + gr_handle_create(new_dentry, new_path.mnt);
62669 out_dput:
62670 + putname(to);
62671 done_path_create(&new_path, new_dentry);
62672 if (delegated_inode) {
62673 error = break_deleg_wait(&delegated_inode);
62674 @@ -4279,6 +4460,12 @@ retry_deleg:
62675 if (new_dentry == trap)
62676 goto exit5;
62677
62678 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
62679 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
62680 + to, flags);
62681 + if (error)
62682 + goto exit5;
62683 +
62684 error = security_path_rename(&oldnd.path, old_dentry,
62685 &newnd.path, new_dentry, flags);
62686 if (error)
62687 @@ -4286,6 +4473,9 @@ retry_deleg:
62688 error = vfs_rename(old_dir->d_inode, old_dentry,
62689 new_dir->d_inode, new_dentry,
62690 &delegated_inode, flags);
62691 + if (!error)
62692 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
62693 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0, flags);
62694 exit5:
62695 dput(new_dentry);
62696 exit4:
62697 @@ -4328,14 +4518,24 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
62698
62699 int readlink_copy(char __user *buffer, int buflen, const char *link)
62700 {
62701 + char tmpbuf[64];
62702 + const char *newlink;
62703 int len = PTR_ERR(link);
62704 +
62705 if (IS_ERR(link))
62706 goto out;
62707
62708 len = strlen(link);
62709 if (len > (unsigned) buflen)
62710 len = buflen;
62711 - if (copy_to_user(buffer, link, len))
62712 +
62713 + if (len < sizeof(tmpbuf)) {
62714 + memcpy(tmpbuf, link, len);
62715 + newlink = tmpbuf;
62716 + } else
62717 + newlink = link;
62718 +
62719 + if (copy_to_user(buffer, newlink, len))
62720 len = -EFAULT;
62721 out:
62722 return len;
62723 diff --git a/fs/namespace.c b/fs/namespace.c
62724 index 182bc41..72e3cf1 100644
62725 --- a/fs/namespace.c
62726 +++ b/fs/namespace.c
62727 @@ -1348,6 +1348,9 @@ static int do_umount(struct mount *mnt, int flags)
62728 if (!(sb->s_flags & MS_RDONLY))
62729 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
62730 up_write(&sb->s_umount);
62731 +
62732 + gr_log_remount(mnt->mnt_devname, retval);
62733 +
62734 return retval;
62735 }
62736
62737 @@ -1370,6 +1373,9 @@ static int do_umount(struct mount *mnt, int flags)
62738 }
62739 unlock_mount_hash();
62740 namespace_unlock();
62741 +
62742 + gr_log_unmount(mnt->mnt_devname, retval);
62743 +
62744 return retval;
62745 }
62746
62747 @@ -1389,7 +1395,7 @@ static inline bool may_mount(void)
62748 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
62749 */
62750
62751 -SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
62752 +SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
62753 {
62754 struct path path;
62755 struct mount *mnt;
62756 @@ -1431,7 +1437,7 @@ out:
62757 /*
62758 * The 2.0 compatible umount. No flags.
62759 */
62760 -SYSCALL_DEFINE1(oldumount, char __user *, name)
62761 +SYSCALL_DEFINE1(oldumount, const char __user *, name)
62762 {
62763 return sys_umount(name, 0);
62764 }
62765 @@ -2440,6 +2446,16 @@ long do_mount(const char *dev_name, const char *dir_name,
62766 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
62767 MS_STRICTATIME);
62768
62769 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
62770 + retval = -EPERM;
62771 + goto dput_out;
62772 + }
62773 +
62774 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
62775 + retval = -EPERM;
62776 + goto dput_out;
62777 + }
62778 +
62779 if (flags & MS_REMOUNT)
62780 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
62781 data_page);
62782 @@ -2454,6 +2470,9 @@ long do_mount(const char *dev_name, const char *dir_name,
62783 dev_name, data_page);
62784 dput_out:
62785 path_put(&path);
62786 +
62787 + gr_log_mount(dev_name, dir_name, retval);
62788 +
62789 return retval;
62790 }
62791
62792 @@ -2471,7 +2490,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
62793 * number incrementing at 10Ghz will take 12,427 years to wrap which
62794 * is effectively never, so we can ignore the possibility.
62795 */
62796 -static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
62797 +static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
62798
62799 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62800 {
62801 @@ -2486,7 +2505,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62802 kfree(new_ns);
62803 return ERR_PTR(ret);
62804 }
62805 - new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
62806 + new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
62807 atomic_set(&new_ns->count, 1);
62808 new_ns->root = NULL;
62809 INIT_LIST_HEAD(&new_ns->list);
62810 @@ -2496,7 +2515,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62811 return new_ns;
62812 }
62813
62814 -struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
62815 +__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
62816 struct user_namespace *user_ns, struct fs_struct *new_fs)
62817 {
62818 struct mnt_namespace *new_ns;
62819 @@ -2617,8 +2636,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
62820 }
62821 EXPORT_SYMBOL(mount_subtree);
62822
62823 -SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
62824 - char __user *, type, unsigned long, flags, void __user *, data)
62825 +SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
62826 + const char __user *, type, unsigned long, flags, void __user *, data)
62827 {
62828 int ret;
62829 char *kernel_type;
62830 @@ -2731,6 +2750,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
62831 if (error)
62832 goto out2;
62833
62834 + if (gr_handle_chroot_pivot()) {
62835 + error = -EPERM;
62836 + goto out2;
62837 + }
62838 +
62839 get_fs_root(current->fs, &root);
62840 old_mp = lock_mount(&old);
62841 error = PTR_ERR(old_mp);
62842 @@ -2999,7 +3023,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
62843 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
62844 return -EPERM;
62845
62846 - if (fs->users != 1)
62847 + if (atomic_read(&fs->users) != 1)
62848 return -EINVAL;
62849
62850 get_mnt_ns(mnt_ns);
62851 diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
62852 index f4ccfe6..a5cf064 100644
62853 --- a/fs/nfs/callback_xdr.c
62854 +++ b/fs/nfs/callback_xdr.c
62855 @@ -51,7 +51,7 @@ struct callback_op {
62856 callback_decode_arg_t decode_args;
62857 callback_encode_res_t encode_res;
62858 long res_maxsize;
62859 -};
62860 +} __do_const;
62861
62862 static struct callback_op callback_ops[];
62863
62864 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
62865 index c79f3e7..d61d671 100644
62866 --- a/fs/nfs/inode.c
62867 +++ b/fs/nfs/inode.c
62868 @@ -1209,16 +1209,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
62869 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
62870 }
62871
62872 -static atomic_long_t nfs_attr_generation_counter;
62873 +static atomic_long_unchecked_t nfs_attr_generation_counter;
62874
62875 static unsigned long nfs_read_attr_generation_counter(void)
62876 {
62877 - return atomic_long_read(&nfs_attr_generation_counter);
62878 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
62879 }
62880
62881 unsigned long nfs_inc_attr_generation_counter(void)
62882 {
62883 - return atomic_long_inc_return(&nfs_attr_generation_counter);
62884 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
62885 }
62886
62887 void nfs_fattr_init(struct nfs_fattr *fattr)
62888 diff --git a/fs/nfs/nfs3acl.c b/fs/nfs/nfs3acl.c
62889 index 8f854dd..d0fec26 100644
62890 --- a/fs/nfs/nfs3acl.c
62891 +++ b/fs/nfs/nfs3acl.c
62892 @@ -256,7 +256,7 @@ nfs3_list_one_acl(struct inode *inode, int type, const char *name, void *data,
62893 char *p = data + *result;
62894
62895 acl = get_acl(inode, type);
62896 - if (!acl)
62897 + if (IS_ERR_OR_NULL(acl))
62898 return 0;
62899
62900 posix_acl_release(acl);
62901 diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
62902 index 95e3720..46c23fa 100644
62903 --- a/fs/nfsd/nfs4proc.c
62904 +++ b/fs/nfsd/nfs4proc.c
62905 @@ -1169,7 +1169,7 @@ struct nfsd4_operation {
62906 nfsd4op_rsize op_rsize_bop;
62907 stateid_getter op_get_currentstateid;
62908 stateid_setter op_set_currentstateid;
62909 -};
62910 +} __do_const;
62911
62912 static struct nfsd4_operation nfsd4_ops[];
62913
62914 diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
62915 index 3297158..7bb8436 100644
62916 --- a/fs/nfsd/nfs4xdr.c
62917 +++ b/fs/nfsd/nfs4xdr.c
62918 @@ -1541,7 +1541,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
62919
62920 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
62921
62922 -static nfsd4_dec nfsd4_dec_ops[] = {
62923 +static const nfsd4_dec nfsd4_dec_ops[] = {
62924 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
62925 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
62926 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
62927 diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
62928 index f8f060f..c4ba09a 100644
62929 --- a/fs/nfsd/nfscache.c
62930 +++ b/fs/nfsd/nfscache.c
62931 @@ -519,14 +519,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
62932 {
62933 struct svc_cacherep *rp = rqstp->rq_cacherep;
62934 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
62935 - int len;
62936 + long len;
62937 size_t bufsize = 0;
62938
62939 if (!rp)
62940 return;
62941
62942 - len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
62943 - len >>= 2;
62944 + if (statp) {
62945 + len = (char*)statp - (char*)resv->iov_base;
62946 + len = resv->iov_len - len;
62947 + len >>= 2;
62948 + }
62949
62950 /* Don't cache excessive amounts of data and XDR failures */
62951 if (!statp || len > (256 >> 2)) {
62952 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
62953 index 16f0673..1c2c30ab 100644
62954 --- a/fs/nfsd/vfs.c
62955 +++ b/fs/nfsd/vfs.c
62956 @@ -843,7 +843,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62957 } else {
62958 oldfs = get_fs();
62959 set_fs(KERNEL_DS);
62960 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
62961 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
62962 set_fs(oldfs);
62963 }
62964
62965 @@ -934,7 +934,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62966
62967 /* Write the data. */
62968 oldfs = get_fs(); set_fs(KERNEL_DS);
62969 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
62970 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
62971 set_fs(oldfs);
62972 if (host_err < 0)
62973 goto out_nfserr;
62974 @@ -1479,7 +1479,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
62975 */
62976
62977 oldfs = get_fs(); set_fs(KERNEL_DS);
62978 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
62979 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
62980 set_fs(oldfs);
62981
62982 if (host_err < 0)
62983 diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
62984 index 52ccd34..43a53b1 100644
62985 --- a/fs/nls/nls_base.c
62986 +++ b/fs/nls/nls_base.c
62987 @@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
62988
62989 int __register_nls(struct nls_table *nls, struct module *owner)
62990 {
62991 - struct nls_table ** tmp = &tables;
62992 + struct nls_table *tmp = tables;
62993
62994 if (nls->next)
62995 return -EBUSY;
62996
62997 - nls->owner = owner;
62998 + pax_open_kernel();
62999 + *(void **)&nls->owner = owner;
63000 + pax_close_kernel();
63001 spin_lock(&nls_lock);
63002 - while (*tmp) {
63003 - if (nls == *tmp) {
63004 + while (tmp) {
63005 + if (nls == tmp) {
63006 spin_unlock(&nls_lock);
63007 return -EBUSY;
63008 }
63009 - tmp = &(*tmp)->next;
63010 + tmp = tmp->next;
63011 }
63012 - nls->next = tables;
63013 + pax_open_kernel();
63014 + *(struct nls_table **)&nls->next = tables;
63015 + pax_close_kernel();
63016 tables = nls;
63017 spin_unlock(&nls_lock);
63018 return 0;
63019 @@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
63020
63021 int unregister_nls(struct nls_table * nls)
63022 {
63023 - struct nls_table ** tmp = &tables;
63024 + struct nls_table * const * tmp = &tables;
63025
63026 spin_lock(&nls_lock);
63027 while (*tmp) {
63028 if (nls == *tmp) {
63029 - *tmp = nls->next;
63030 + pax_open_kernel();
63031 + *(struct nls_table **)tmp = nls->next;
63032 + pax_close_kernel();
63033 spin_unlock(&nls_lock);
63034 return 0;
63035 }
63036 diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
63037 index 162b3f1..6076a7c 100644
63038 --- a/fs/nls/nls_euc-jp.c
63039 +++ b/fs/nls/nls_euc-jp.c
63040 @@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
63041 p_nls = load_nls("cp932");
63042
63043 if (p_nls) {
63044 - table.charset2upper = p_nls->charset2upper;
63045 - table.charset2lower = p_nls->charset2lower;
63046 + pax_open_kernel();
63047 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
63048 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
63049 + pax_close_kernel();
63050 return register_nls(&table);
63051 }
63052
63053 diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
63054 index a80a741..7b96e1b 100644
63055 --- a/fs/nls/nls_koi8-ru.c
63056 +++ b/fs/nls/nls_koi8-ru.c
63057 @@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
63058 p_nls = load_nls("koi8-u");
63059
63060 if (p_nls) {
63061 - table.charset2upper = p_nls->charset2upper;
63062 - table.charset2lower = p_nls->charset2lower;
63063 + pax_open_kernel();
63064 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
63065 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
63066 + pax_close_kernel();
63067 return register_nls(&table);
63068 }
63069
63070 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
63071 index 732648b..d3b017f 100644
63072 --- a/fs/notify/fanotify/fanotify_user.c
63073 +++ b/fs/notify/fanotify/fanotify_user.c
63074 @@ -203,8 +203,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
63075
63076 fd = fanotify_event_metadata.fd;
63077 ret = -EFAULT;
63078 - if (copy_to_user(buf, &fanotify_event_metadata,
63079 - fanotify_event_metadata.event_len))
63080 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
63081 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
63082 goto out_close_fd;
63083
63084 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
63085 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
63086 index 1e58402..bb2d6f4 100644
63087 --- a/fs/notify/notification.c
63088 +++ b/fs/notify/notification.c
63089 @@ -48,7 +48,7 @@
63090 #include <linux/fsnotify_backend.h>
63091 #include "fsnotify.h"
63092
63093 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
63094 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
63095
63096 /**
63097 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
63098 @@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
63099 */
63100 u32 fsnotify_get_cookie(void)
63101 {
63102 - return atomic_inc_return(&fsnotify_sync_cookie);
63103 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
63104 }
63105 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
63106
63107 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
63108 index 9e38daf..5727cae 100644
63109 --- a/fs/ntfs/dir.c
63110 +++ b/fs/ntfs/dir.c
63111 @@ -1310,7 +1310,7 @@ find_next_index_buffer:
63112 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
63113 ~(s64)(ndir->itype.index.block_size - 1)));
63114 /* Bounds checks. */
63115 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
63116 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
63117 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
63118 "inode 0x%lx or driver bug.", vdir->i_ino);
63119 goto err_out;
63120 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
63121 index db9bd8a..8338fb6 100644
63122 --- a/fs/ntfs/file.c
63123 +++ b/fs/ntfs/file.c
63124 @@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
63125 char *addr;
63126 size_t total = 0;
63127 unsigned len;
63128 - int left;
63129 + unsigned left;
63130
63131 do {
63132 len = PAGE_CACHE_SIZE - ofs;
63133 diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
63134 index 9de2491..3306095 100644
63135 --- a/fs/ntfs/super.c
63136 +++ b/fs/ntfs/super.c
63137 @@ -688,7 +688,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
63138 if (!silent)
63139 ntfs_error(sb, "Primary boot sector is invalid.");
63140 } else if (!silent)
63141 - ntfs_error(sb, read_err_str, "primary");
63142 + ntfs_error(sb, read_err_str, "%s", "primary");
63143 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
63144 if (bh_primary)
63145 brelse(bh_primary);
63146 @@ -704,7 +704,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
63147 goto hotfix_primary_boot_sector;
63148 brelse(bh_backup);
63149 } else if (!silent)
63150 - ntfs_error(sb, read_err_str, "backup");
63151 + ntfs_error(sb, read_err_str, "%s", "backup");
63152 /* Try to read NT3.51- backup boot sector. */
63153 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
63154 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
63155 @@ -715,7 +715,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
63156 "sector.");
63157 brelse(bh_backup);
63158 } else if (!silent)
63159 - ntfs_error(sb, read_err_str, "backup");
63160 + ntfs_error(sb, read_err_str, "%s", "backup");
63161 /* We failed. Cleanup and return. */
63162 if (bh_primary)
63163 brelse(bh_primary);
63164 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
63165 index 0440134..d52c93a 100644
63166 --- a/fs/ocfs2/localalloc.c
63167 +++ b/fs/ocfs2/localalloc.c
63168 @@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
63169 goto bail;
63170 }
63171
63172 - atomic_inc(&osb->alloc_stats.moves);
63173 + atomic_inc_unchecked(&osb->alloc_stats.moves);
63174
63175 bail:
63176 if (handle)
63177 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
63178 index 8d64a97..c37665d 100644
63179 --- a/fs/ocfs2/ocfs2.h
63180 +++ b/fs/ocfs2/ocfs2.h
63181 @@ -236,11 +236,11 @@ enum ocfs2_vol_state
63182
63183 struct ocfs2_alloc_stats
63184 {
63185 - atomic_t moves;
63186 - atomic_t local_data;
63187 - atomic_t bitmap_data;
63188 - atomic_t bg_allocs;
63189 - atomic_t bg_extends;
63190 + atomic_unchecked_t moves;
63191 + atomic_unchecked_t local_data;
63192 + atomic_unchecked_t bitmap_data;
63193 + atomic_unchecked_t bg_allocs;
63194 + atomic_unchecked_t bg_extends;
63195 };
63196
63197 enum ocfs2_local_alloc_state
63198 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
63199 index 0cb889a..6a26b24 100644
63200 --- a/fs/ocfs2/suballoc.c
63201 +++ b/fs/ocfs2/suballoc.c
63202 @@ -867,7 +867,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
63203 mlog_errno(status);
63204 goto bail;
63205 }
63206 - atomic_inc(&osb->alloc_stats.bg_extends);
63207 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
63208
63209 /* You should never ask for this much metadata */
63210 BUG_ON(bits_wanted >
63211 @@ -2014,7 +2014,7 @@ int ocfs2_claim_metadata(handle_t *handle,
63212 mlog_errno(status);
63213 goto bail;
63214 }
63215 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
63216 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
63217
63218 *suballoc_loc = res.sr_bg_blkno;
63219 *suballoc_bit_start = res.sr_bit_offset;
63220 @@ -2180,7 +2180,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
63221 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
63222 res->sr_bits);
63223
63224 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
63225 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
63226
63227 BUG_ON(res->sr_bits != 1);
63228
63229 @@ -2222,7 +2222,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
63230 mlog_errno(status);
63231 goto bail;
63232 }
63233 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
63234 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
63235
63236 BUG_ON(res.sr_bits != 1);
63237
63238 @@ -2326,7 +2326,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
63239 cluster_start,
63240 num_clusters);
63241 if (!status)
63242 - atomic_inc(&osb->alloc_stats.local_data);
63243 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
63244 } else {
63245 if (min_clusters > (osb->bitmap_cpg - 1)) {
63246 /* The only paths asking for contiguousness
63247 @@ -2352,7 +2352,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
63248 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
63249 res.sr_bg_blkno,
63250 res.sr_bit_offset);
63251 - atomic_inc(&osb->alloc_stats.bitmap_data);
63252 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
63253 *num_clusters = res.sr_bits;
63254 }
63255 }
63256 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
63257 index a7cdd56..c583144 100644
63258 --- a/fs/ocfs2/super.c
63259 +++ b/fs/ocfs2/super.c
63260 @@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
63261 "%10s => GlobalAllocs: %d LocalAllocs: %d "
63262 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
63263 "Stats",
63264 - atomic_read(&osb->alloc_stats.bitmap_data),
63265 - atomic_read(&osb->alloc_stats.local_data),
63266 - atomic_read(&osb->alloc_stats.bg_allocs),
63267 - atomic_read(&osb->alloc_stats.moves),
63268 - atomic_read(&osb->alloc_stats.bg_extends));
63269 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
63270 + atomic_read_unchecked(&osb->alloc_stats.local_data),
63271 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
63272 + atomic_read_unchecked(&osb->alloc_stats.moves),
63273 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
63274
63275 out += snprintf(buf + out, len - out,
63276 "%10s => State: %u Descriptor: %llu Size: %u bits "
63277 @@ -2104,11 +2104,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
63278
63279 mutex_init(&osb->system_file_mutex);
63280
63281 - atomic_set(&osb->alloc_stats.moves, 0);
63282 - atomic_set(&osb->alloc_stats.local_data, 0);
63283 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
63284 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
63285 - atomic_set(&osb->alloc_stats.bg_extends, 0);
63286 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
63287 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
63288 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
63289 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
63290 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
63291
63292 /* Copy the blockcheck stats from the superblock probe */
63293 osb->osb_ecc_stats = *stats;
63294 diff --git a/fs/open.c b/fs/open.c
63295 index dd24f21..c1f4b3a 100644
63296 --- a/fs/open.c
63297 +++ b/fs/open.c
63298 @@ -32,6 +32,8 @@
63299 #include <linux/dnotify.h>
63300 #include <linux/compat.h>
63301
63302 +#define CREATE_TRACE_POINTS
63303 +#include <trace/events/fs.h>
63304 #include "internal.h"
63305
63306 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
63307 @@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
63308 error = locks_verify_truncate(inode, NULL, length);
63309 if (!error)
63310 error = security_path_truncate(path);
63311 + if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
63312 + error = -EACCES;
63313 if (!error)
63314 error = do_truncate(path->dentry, length, 0, NULL);
63315
63316 @@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
63317 error = locks_verify_truncate(inode, f.file, length);
63318 if (!error)
63319 error = security_path_truncate(&f.file->f_path);
63320 + if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
63321 + error = -EACCES;
63322 if (!error)
63323 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
63324 sb_end_write(inode->i_sb);
63325 @@ -380,6 +386,9 @@ retry:
63326 if (__mnt_is_readonly(path.mnt))
63327 res = -EROFS;
63328
63329 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
63330 + res = -EACCES;
63331 +
63332 out_path_release:
63333 path_put(&path);
63334 if (retry_estale(res, lookup_flags)) {
63335 @@ -411,6 +420,8 @@ retry:
63336 if (error)
63337 goto dput_and_out;
63338
63339 + gr_log_chdir(path.dentry, path.mnt);
63340 +
63341 set_fs_pwd(current->fs, &path);
63342
63343 dput_and_out:
63344 @@ -440,6 +451,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
63345 goto out_putf;
63346
63347 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
63348 +
63349 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
63350 + error = -EPERM;
63351 +
63352 + if (!error)
63353 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
63354 +
63355 if (!error)
63356 set_fs_pwd(current->fs, &f.file->f_path);
63357 out_putf:
63358 @@ -469,7 +487,13 @@ retry:
63359 if (error)
63360 goto dput_and_out;
63361
63362 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
63363 + goto dput_and_out;
63364 +
63365 set_fs_root(current->fs, &path);
63366 +
63367 + gr_handle_chroot_chdir(&path);
63368 +
63369 error = 0;
63370 dput_and_out:
63371 path_put(&path);
63372 @@ -493,6 +517,16 @@ static int chmod_common(struct path *path, umode_t mode)
63373 return error;
63374 retry_deleg:
63375 mutex_lock(&inode->i_mutex);
63376 +
63377 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
63378 + error = -EACCES;
63379 + goto out_unlock;
63380 + }
63381 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
63382 + error = -EACCES;
63383 + goto out_unlock;
63384 + }
63385 +
63386 error = security_path_chmod(path, mode);
63387 if (error)
63388 goto out_unlock;
63389 @@ -558,6 +592,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
63390 uid = make_kuid(current_user_ns(), user);
63391 gid = make_kgid(current_user_ns(), group);
63392
63393 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
63394 + return -EACCES;
63395 +
63396 newattrs.ia_valid = ATTR_CTIME;
63397 if (user != (uid_t) -1) {
63398 if (!uid_valid(uid))
63399 @@ -977,6 +1014,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
63400 } else {
63401 fsnotify_open(f);
63402 fd_install(fd, f);
63403 + trace_do_sys_open(tmp->name, flags, mode);
63404 }
63405 }
63406 putname(tmp);
63407 diff --git a/fs/pipe.c b/fs/pipe.c
63408 index 034bffa..6c6b522 100644
63409 --- a/fs/pipe.c
63410 +++ b/fs/pipe.c
63411 @@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
63412
63413 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
63414 {
63415 - if (pipe->files)
63416 + if (atomic_read(&pipe->files))
63417 mutex_lock_nested(&pipe->mutex, subclass);
63418 }
63419
63420 @@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
63421
63422 void pipe_unlock(struct pipe_inode_info *pipe)
63423 {
63424 - if (pipe->files)
63425 + if (atomic_read(&pipe->files))
63426 mutex_unlock(&pipe->mutex);
63427 }
63428 EXPORT_SYMBOL(pipe_unlock);
63429 @@ -342,9 +342,9 @@ pipe_read(struct kiocb *iocb, const struct iovec *_iov,
63430 }
63431 if (bufs) /* More to do? */
63432 continue;
63433 - if (!pipe->writers)
63434 + if (!atomic_read(&pipe->writers))
63435 break;
63436 - if (!pipe->waiting_writers) {
63437 + if (!atomic_read(&pipe->waiting_writers)) {
63438 /* syscall merging: Usually we must not sleep
63439 * if O_NONBLOCK is set, or if we got some data.
63440 * But if a writer sleeps in kernel space, then
63441 @@ -406,7 +406,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
63442 ret = 0;
63443 __pipe_lock(pipe);
63444
63445 - if (!pipe->readers) {
63446 + if (!atomic_read(&pipe->readers)) {
63447 send_sig(SIGPIPE, current, 0);
63448 ret = -EPIPE;
63449 goto out;
63450 @@ -461,7 +461,7 @@ redo1:
63451 for (;;) {
63452 int bufs;
63453
63454 - if (!pipe->readers) {
63455 + if (!atomic_read(&pipe->readers)) {
63456 send_sig(SIGPIPE, current, 0);
63457 if (!ret)
63458 ret = -EPIPE;
63459 @@ -552,9 +552,9 @@ redo2:
63460 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
63461 do_wakeup = 0;
63462 }
63463 - pipe->waiting_writers++;
63464 + atomic_inc(&pipe->waiting_writers);
63465 pipe_wait(pipe);
63466 - pipe->waiting_writers--;
63467 + atomic_dec(&pipe->waiting_writers);
63468 }
63469 out:
63470 __pipe_unlock(pipe);
63471 @@ -609,7 +609,7 @@ pipe_poll(struct file *filp, poll_table *wait)
63472 mask = 0;
63473 if (filp->f_mode & FMODE_READ) {
63474 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
63475 - if (!pipe->writers && filp->f_version != pipe->w_counter)
63476 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
63477 mask |= POLLHUP;
63478 }
63479
63480 @@ -619,7 +619,7 @@ pipe_poll(struct file *filp, poll_table *wait)
63481 * Most Unices do not set POLLERR for FIFOs but on Linux they
63482 * behave exactly like pipes for poll().
63483 */
63484 - if (!pipe->readers)
63485 + if (!atomic_read(&pipe->readers))
63486 mask |= POLLERR;
63487 }
63488
63489 @@ -631,7 +631,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
63490 int kill = 0;
63491
63492 spin_lock(&inode->i_lock);
63493 - if (!--pipe->files) {
63494 + if (atomic_dec_and_test(&pipe->files)) {
63495 inode->i_pipe = NULL;
63496 kill = 1;
63497 }
63498 @@ -648,11 +648,11 @@ pipe_release(struct inode *inode, struct file *file)
63499
63500 __pipe_lock(pipe);
63501 if (file->f_mode & FMODE_READ)
63502 - pipe->readers--;
63503 + atomic_dec(&pipe->readers);
63504 if (file->f_mode & FMODE_WRITE)
63505 - pipe->writers--;
63506 + atomic_dec(&pipe->writers);
63507
63508 - if (pipe->readers || pipe->writers) {
63509 + if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
63510 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
63511 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
63512 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
63513 @@ -717,7 +717,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
63514 kfree(pipe);
63515 }
63516
63517 -static struct vfsmount *pipe_mnt __read_mostly;
63518 +struct vfsmount *pipe_mnt __read_mostly;
63519
63520 /*
63521 * pipefs_dname() is called from d_path().
63522 @@ -747,8 +747,9 @@ static struct inode * get_pipe_inode(void)
63523 goto fail_iput;
63524
63525 inode->i_pipe = pipe;
63526 - pipe->files = 2;
63527 - pipe->readers = pipe->writers = 1;
63528 + atomic_set(&pipe->files, 2);
63529 + atomic_set(&pipe->readers, 1);
63530 + atomic_set(&pipe->writers, 1);
63531 inode->i_fop = &pipefifo_fops;
63532
63533 /*
63534 @@ -927,17 +928,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
63535 spin_lock(&inode->i_lock);
63536 if (inode->i_pipe) {
63537 pipe = inode->i_pipe;
63538 - pipe->files++;
63539 + atomic_inc(&pipe->files);
63540 spin_unlock(&inode->i_lock);
63541 } else {
63542 spin_unlock(&inode->i_lock);
63543 pipe = alloc_pipe_info();
63544 if (!pipe)
63545 return -ENOMEM;
63546 - pipe->files = 1;
63547 + atomic_set(&pipe->files, 1);
63548 spin_lock(&inode->i_lock);
63549 if (unlikely(inode->i_pipe)) {
63550 - inode->i_pipe->files++;
63551 + atomic_inc(&inode->i_pipe->files);
63552 spin_unlock(&inode->i_lock);
63553 free_pipe_info(pipe);
63554 pipe = inode->i_pipe;
63555 @@ -962,10 +963,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
63556 * opened, even when there is no process writing the FIFO.
63557 */
63558 pipe->r_counter++;
63559 - if (pipe->readers++ == 0)
63560 + if (atomic_inc_return(&pipe->readers) == 1)
63561 wake_up_partner(pipe);
63562
63563 - if (!is_pipe && !pipe->writers) {
63564 + if (!is_pipe && !atomic_read(&pipe->writers)) {
63565 if ((filp->f_flags & O_NONBLOCK)) {
63566 /* suppress POLLHUP until we have
63567 * seen a writer */
63568 @@ -984,14 +985,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
63569 * errno=ENXIO when there is no process reading the FIFO.
63570 */
63571 ret = -ENXIO;
63572 - if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
63573 + if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
63574 goto err;
63575
63576 pipe->w_counter++;
63577 - if (!pipe->writers++)
63578 + if (atomic_inc_return(&pipe->writers) == 1)
63579 wake_up_partner(pipe);
63580
63581 - if (!is_pipe && !pipe->readers) {
63582 + if (!is_pipe && !atomic_read(&pipe->readers)) {
63583 if (wait_for_partner(pipe, &pipe->r_counter))
63584 goto err_wr;
63585 }
63586 @@ -1005,11 +1006,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
63587 * the process can at least talk to itself.
63588 */
63589
63590 - pipe->readers++;
63591 - pipe->writers++;
63592 + atomic_inc(&pipe->readers);
63593 + atomic_inc(&pipe->writers);
63594 pipe->r_counter++;
63595 pipe->w_counter++;
63596 - if (pipe->readers == 1 || pipe->writers == 1)
63597 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
63598 wake_up_partner(pipe);
63599 break;
63600
63601 @@ -1023,13 +1024,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
63602 return 0;
63603
63604 err_rd:
63605 - if (!--pipe->readers)
63606 + if (atomic_dec_and_test(&pipe->readers))
63607 wake_up_interruptible(&pipe->wait);
63608 ret = -ERESTARTSYS;
63609 goto err;
63610
63611 err_wr:
63612 - if (!--pipe->writers)
63613 + if (atomic_dec_and_test(&pipe->writers))
63614 wake_up_interruptible(&pipe->wait);
63615 ret = -ERESTARTSYS;
63616 goto err;
63617 diff --git a/fs/posix_acl.c b/fs/posix_acl.c
63618 index 0855f77..6787d50 100644
63619 --- a/fs/posix_acl.c
63620 +++ b/fs/posix_acl.c
63621 @@ -20,6 +20,7 @@
63622 #include <linux/xattr.h>
63623 #include <linux/export.h>
63624 #include <linux/user_namespace.h>
63625 +#include <linux/grsecurity.h>
63626
63627 struct posix_acl **acl_by_type(struct inode *inode, int type)
63628 {
63629 @@ -277,7 +278,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
63630 }
63631 }
63632 if (mode_p)
63633 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
63634 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
63635 return not_equiv;
63636 }
63637 EXPORT_SYMBOL(posix_acl_equiv_mode);
63638 @@ -427,7 +428,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
63639 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
63640 }
63641
63642 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
63643 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
63644 return not_equiv;
63645 }
63646
63647 @@ -485,6 +486,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
63648 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
63649 int err = -ENOMEM;
63650 if (clone) {
63651 + *mode_p &= ~gr_acl_umask();
63652 +
63653 err = posix_acl_create_masq(clone, mode_p);
63654 if (err < 0) {
63655 posix_acl_release(clone);
63656 @@ -659,11 +662,12 @@ struct posix_acl *
63657 posix_acl_from_xattr(struct user_namespace *user_ns,
63658 const void *value, size_t size)
63659 {
63660 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
63661 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
63662 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
63663 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
63664 int count;
63665 struct posix_acl *acl;
63666 struct posix_acl_entry *acl_e;
63667 + umode_t umask = gr_acl_umask();
63668
63669 if (!value)
63670 return NULL;
63671 @@ -689,12 +693,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
63672
63673 switch(acl_e->e_tag) {
63674 case ACL_USER_OBJ:
63675 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
63676 + break;
63677 case ACL_GROUP_OBJ:
63678 case ACL_MASK:
63679 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
63680 + break;
63681 case ACL_OTHER:
63682 + acl_e->e_perm &= ~(umask & S_IRWXO);
63683 break;
63684
63685 case ACL_USER:
63686 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
63687 acl_e->e_uid =
63688 make_kuid(user_ns,
63689 le32_to_cpu(entry->e_id));
63690 @@ -702,6 +712,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
63691 goto fail;
63692 break;
63693 case ACL_GROUP:
63694 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
63695 acl_e->e_gid =
63696 make_kgid(user_ns,
63697 le32_to_cpu(entry->e_id));
63698 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
63699 index 2183fcf..3c32a98 100644
63700 --- a/fs/proc/Kconfig
63701 +++ b/fs/proc/Kconfig
63702 @@ -30,7 +30,7 @@ config PROC_FS
63703
63704 config PROC_KCORE
63705 bool "/proc/kcore support" if !ARM
63706 - depends on PROC_FS && MMU
63707 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
63708 help
63709 Provides a virtual ELF core file of the live kernel. This can
63710 be read with gdb and other ELF tools. No modifications can be
63711 @@ -38,8 +38,8 @@ config PROC_KCORE
63712
63713 config PROC_VMCORE
63714 bool "/proc/vmcore support"
63715 - depends on PROC_FS && CRASH_DUMP
63716 - default y
63717 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
63718 + default n
63719 help
63720 Exports the dump image of crashed kernel in ELF format.
63721
63722 @@ -63,8 +63,8 @@ config PROC_SYSCTL
63723 limited in memory.
63724
63725 config PROC_PAGE_MONITOR
63726 - default y
63727 - depends on PROC_FS && MMU
63728 + default n
63729 + depends on PROC_FS && MMU && !GRKERNSEC
63730 bool "Enable /proc page monitoring" if EXPERT
63731 help
63732 Various /proc files exist to monitor process memory utilization:
63733 diff --git a/fs/proc/array.c b/fs/proc/array.c
63734 index 64db2bc..a8185d6 100644
63735 --- a/fs/proc/array.c
63736 +++ b/fs/proc/array.c
63737 @@ -60,6 +60,7 @@
63738 #include <linux/tty.h>
63739 #include <linux/string.h>
63740 #include <linux/mman.h>
63741 +#include <linux/grsecurity.h>
63742 #include <linux/proc_fs.h>
63743 #include <linux/ioport.h>
63744 #include <linux/uaccess.h>
63745 @@ -356,6 +357,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
63746 seq_putc(m, '\n');
63747 }
63748
63749 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63750 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
63751 +{
63752 + if (p->mm)
63753 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
63754 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
63755 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
63756 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
63757 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
63758 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
63759 + else
63760 + seq_printf(m, "PaX:\t-----\n");
63761 +}
63762 +#endif
63763 +
63764 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
63765 struct pid *pid, struct task_struct *task)
63766 {
63767 @@ -374,9 +390,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
63768 task_cpus_allowed(m, task);
63769 cpuset_task_status_allowed(m, task);
63770 task_context_switch_counts(m, task);
63771 +
63772 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63773 + task_pax(m, task);
63774 +#endif
63775 +
63776 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
63777 + task_grsec_rbac(m, task);
63778 +#endif
63779 +
63780 return 0;
63781 }
63782
63783 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63784 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63785 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
63786 + _mm->pax_flags & MF_PAX_SEGMEXEC))
63787 +#endif
63788 +
63789 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63790 struct pid *pid, struct task_struct *task, int whole)
63791 {
63792 @@ -398,6 +429,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63793 char tcomm[sizeof(task->comm)];
63794 unsigned long flags;
63795
63796 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63797 + if (current->exec_id != m->exec_id) {
63798 + gr_log_badprocpid("stat");
63799 + return 0;
63800 + }
63801 +#endif
63802 +
63803 state = *get_task_state(task);
63804 vsize = eip = esp = 0;
63805 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63806 @@ -468,6 +506,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63807 gtime = task_gtime(task);
63808 }
63809
63810 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63811 + if (PAX_RAND_FLAGS(mm)) {
63812 + eip = 0;
63813 + esp = 0;
63814 + wchan = 0;
63815 + }
63816 +#endif
63817 +#ifdef CONFIG_GRKERNSEC_HIDESYM
63818 + wchan = 0;
63819 + eip =0;
63820 + esp =0;
63821 +#endif
63822 +
63823 /* scale priority and nice values from timeslices to -20..20 */
63824 /* to make it look like a "normal" Unix priority/nice value */
63825 priority = task_prio(task);
63826 @@ -504,9 +555,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63827 seq_put_decimal_ull(m, ' ', vsize);
63828 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
63829 seq_put_decimal_ull(m, ' ', rsslim);
63830 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63831 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
63832 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
63833 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
63834 +#else
63835 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
63836 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
63837 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
63838 +#endif
63839 seq_put_decimal_ull(m, ' ', esp);
63840 seq_put_decimal_ull(m, ' ', eip);
63841 /* The signal information here is obsolete.
63842 @@ -528,7 +585,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63843 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
63844 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
63845
63846 - if (mm && permitted) {
63847 + if (mm && permitted
63848 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63849 + && !PAX_RAND_FLAGS(mm)
63850 +#endif
63851 + ) {
63852 seq_put_decimal_ull(m, ' ', mm->start_data);
63853 seq_put_decimal_ull(m, ' ', mm->end_data);
63854 seq_put_decimal_ull(m, ' ', mm->start_brk);
63855 @@ -566,8 +627,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63856 struct pid *pid, struct task_struct *task)
63857 {
63858 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
63859 - struct mm_struct *mm = get_task_mm(task);
63860 + struct mm_struct *mm;
63861
63862 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63863 + if (current->exec_id != m->exec_id) {
63864 + gr_log_badprocpid("statm");
63865 + return 0;
63866 + }
63867 +#endif
63868 + mm = get_task_mm(task);
63869 if (mm) {
63870 size = task_statm(mm, &shared, &text, &data, &resident);
63871 mmput(mm);
63872 @@ -590,6 +658,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63873 return 0;
63874 }
63875
63876 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63877 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
63878 +{
63879 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
63880 +}
63881 +#endif
63882 +
63883 #ifdef CONFIG_CHECKPOINT_RESTORE
63884 static struct pid *
63885 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
63886 diff --git a/fs/proc/base.c b/fs/proc/base.c
63887 index 2d696b0..b9da447 100644
63888 --- a/fs/proc/base.c
63889 +++ b/fs/proc/base.c
63890 @@ -113,6 +113,14 @@ struct pid_entry {
63891 union proc_op op;
63892 };
63893
63894 +struct getdents_callback {
63895 + struct linux_dirent __user * current_dir;
63896 + struct linux_dirent __user * previous;
63897 + struct file * file;
63898 + int count;
63899 + int error;
63900 +};
63901 +
63902 #define NOD(NAME, MODE, IOP, FOP, OP) { \
63903 .name = (NAME), \
63904 .len = sizeof(NAME) - 1, \
63905 @@ -205,12 +213,28 @@ static int proc_pid_cmdline(struct task_struct *task, char *buffer)
63906 return get_cmdline(task, buffer, PAGE_SIZE);
63907 }
63908
63909 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63910 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63911 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
63912 + _mm->pax_flags & MF_PAX_SEGMEXEC))
63913 +#endif
63914 +
63915 static int proc_pid_auxv(struct task_struct *task, char *buffer)
63916 {
63917 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
63918 int res = PTR_ERR(mm);
63919 if (mm && !IS_ERR(mm)) {
63920 unsigned int nwords = 0;
63921 +
63922 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63923 + /* allow if we're currently ptracing this task */
63924 + if (PAX_RAND_FLAGS(mm) &&
63925 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
63926 + mmput(mm);
63927 + return 0;
63928 + }
63929 +#endif
63930 +
63931 do {
63932 nwords += 2;
63933 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
63934 @@ -224,7 +248,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
63935 }
63936
63937
63938 -#ifdef CONFIG_KALLSYMS
63939 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63940 /*
63941 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
63942 * Returns the resolved symbol. If that fails, simply return the address.
63943 @@ -263,7 +287,7 @@ static void unlock_trace(struct task_struct *task)
63944 mutex_unlock(&task->signal->cred_guard_mutex);
63945 }
63946
63947 -#ifdef CONFIG_STACKTRACE
63948 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63949
63950 #define MAX_STACK_TRACE_DEPTH 64
63951
63952 @@ -486,7 +510,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
63953 return count;
63954 }
63955
63956 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63957 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63958 static int proc_pid_syscall(struct task_struct *task, char *buffer)
63959 {
63960 long nr;
63961 @@ -515,7 +539,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
63962 /************************************************************************/
63963
63964 /* permission checks */
63965 -static int proc_fd_access_allowed(struct inode *inode)
63966 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
63967 {
63968 struct task_struct *task;
63969 int allowed = 0;
63970 @@ -525,7 +549,10 @@ static int proc_fd_access_allowed(struct inode *inode)
63971 */
63972 task = get_proc_task(inode);
63973 if (task) {
63974 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63975 + if (log)
63976 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63977 + else
63978 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63979 put_task_struct(task);
63980 }
63981 return allowed;
63982 @@ -556,10 +583,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
63983 struct task_struct *task,
63984 int hide_pid_min)
63985 {
63986 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63987 + return false;
63988 +
63989 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63990 + rcu_read_lock();
63991 + {
63992 + const struct cred *tmpcred = current_cred();
63993 + const struct cred *cred = __task_cred(task);
63994 +
63995 + if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
63996 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63997 + || in_group_p(grsec_proc_gid)
63998 +#endif
63999 + ) {
64000 + rcu_read_unlock();
64001 + return true;
64002 + }
64003 + }
64004 + rcu_read_unlock();
64005 +
64006 + if (!pid->hide_pid)
64007 + return false;
64008 +#endif
64009 +
64010 if (pid->hide_pid < hide_pid_min)
64011 return true;
64012 if (in_group_p(pid->pid_gid))
64013 return true;
64014 +
64015 return ptrace_may_access(task, PTRACE_MODE_READ);
64016 }
64017
64018 @@ -577,7 +629,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
64019 put_task_struct(task);
64020
64021 if (!has_perms) {
64022 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64023 + {
64024 +#else
64025 if (pid->hide_pid == 2) {
64026 +#endif
64027 /*
64028 * Let's make getdents(), stat(), and open()
64029 * consistent with each other. If a process
64030 @@ -675,6 +731,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
64031 if (!task)
64032 return -ESRCH;
64033
64034 + if (gr_acl_handle_procpidmem(task)) {
64035 + put_task_struct(task);
64036 + return -EPERM;
64037 + }
64038 +
64039 mm = mm_access(task, mode);
64040 put_task_struct(task);
64041
64042 @@ -690,6 +751,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
64043
64044 file->private_data = mm;
64045
64046 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64047 + file->f_version = current->exec_id;
64048 +#endif
64049 +
64050 return 0;
64051 }
64052
64053 @@ -711,6 +776,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
64054 ssize_t copied;
64055 char *page;
64056
64057 +#ifdef CONFIG_GRKERNSEC
64058 + if (write)
64059 + return -EPERM;
64060 +#endif
64061 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64062 + if (file->f_version != current->exec_id) {
64063 + gr_log_badprocpid("mem");
64064 + return 0;
64065 + }
64066 +#endif
64067 +
64068 if (!mm)
64069 return 0;
64070
64071 @@ -723,7 +799,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
64072 goto free;
64073
64074 while (count > 0) {
64075 - int this_len = min_t(int, count, PAGE_SIZE);
64076 + ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
64077
64078 if (write && copy_from_user(page, buf, this_len)) {
64079 copied = -EFAULT;
64080 @@ -815,6 +891,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
64081 if (!mm)
64082 return 0;
64083
64084 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64085 + if (file->f_version != current->exec_id) {
64086 + gr_log_badprocpid("environ");
64087 + return 0;
64088 + }
64089 +#endif
64090 +
64091 page = (char *)__get_free_page(GFP_TEMPORARY);
64092 if (!page)
64093 return -ENOMEM;
64094 @@ -824,7 +907,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
64095 goto free;
64096 while (count > 0) {
64097 size_t this_len, max_len;
64098 - int retval;
64099 + ssize_t retval;
64100
64101 if (src >= (mm->env_end - mm->env_start))
64102 break;
64103 @@ -1438,7 +1521,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
64104 int error = -EACCES;
64105
64106 /* Are we allowed to snoop on the tasks file descriptors? */
64107 - if (!proc_fd_access_allowed(inode))
64108 + if (!proc_fd_access_allowed(inode, 0))
64109 goto out;
64110
64111 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
64112 @@ -1482,8 +1565,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
64113 struct path path;
64114
64115 /* Are we allowed to snoop on the tasks file descriptors? */
64116 - if (!proc_fd_access_allowed(inode))
64117 - goto out;
64118 + /* logging this is needed for learning on chromium to work properly,
64119 + but we don't want to flood the logs from 'ps' which does a readlink
64120 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
64121 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
64122 + */
64123 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
64124 + if (!proc_fd_access_allowed(inode,0))
64125 + goto out;
64126 + } else {
64127 + if (!proc_fd_access_allowed(inode,1))
64128 + goto out;
64129 + }
64130
64131 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
64132 if (error)
64133 @@ -1533,7 +1626,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
64134 rcu_read_lock();
64135 cred = __task_cred(task);
64136 inode->i_uid = cred->euid;
64137 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64138 + inode->i_gid = grsec_proc_gid;
64139 +#else
64140 inode->i_gid = cred->egid;
64141 +#endif
64142 rcu_read_unlock();
64143 }
64144 security_task_to_inode(task, inode);
64145 @@ -1569,10 +1666,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
64146 return -ENOENT;
64147 }
64148 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
64149 +#ifdef CONFIG_GRKERNSEC_PROC_USER
64150 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
64151 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64152 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
64153 +#endif
64154 task_dumpable(task)) {
64155 cred = __task_cred(task);
64156 stat->uid = cred->euid;
64157 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64158 + stat->gid = grsec_proc_gid;
64159 +#else
64160 stat->gid = cred->egid;
64161 +#endif
64162 }
64163 }
64164 rcu_read_unlock();
64165 @@ -1610,11 +1716,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
64166
64167 if (task) {
64168 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
64169 +#ifdef CONFIG_GRKERNSEC_PROC_USER
64170 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
64171 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64172 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
64173 +#endif
64174 task_dumpable(task)) {
64175 rcu_read_lock();
64176 cred = __task_cred(task);
64177 inode->i_uid = cred->euid;
64178 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64179 + inode->i_gid = grsec_proc_gid;
64180 +#else
64181 inode->i_gid = cred->egid;
64182 +#endif
64183 rcu_read_unlock();
64184 } else {
64185 inode->i_uid = GLOBAL_ROOT_UID;
64186 @@ -2149,6 +2264,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
64187 if (!task)
64188 goto out_no_task;
64189
64190 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
64191 + goto out;
64192 +
64193 /*
64194 * Yes, it does not scale. And it should not. Don't add
64195 * new entries into /proc/<tgid>/ without very good reasons.
64196 @@ -2179,6 +2297,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
64197 if (!task)
64198 return -ENOENT;
64199
64200 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
64201 + goto out;
64202 +
64203 if (!dir_emit_dots(file, ctx))
64204 goto out;
64205
64206 @@ -2568,7 +2689,7 @@ static const struct pid_entry tgid_base_stuff[] = {
64207 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
64208 #endif
64209 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
64210 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
64211 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
64212 INF("syscall", S_IRUSR, proc_pid_syscall),
64213 #endif
64214 INF("cmdline", S_IRUGO, proc_pid_cmdline),
64215 @@ -2593,10 +2714,10 @@ static const struct pid_entry tgid_base_stuff[] = {
64216 #ifdef CONFIG_SECURITY
64217 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
64218 #endif
64219 -#ifdef CONFIG_KALLSYMS
64220 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
64221 INF("wchan", S_IRUGO, proc_pid_wchan),
64222 #endif
64223 -#ifdef CONFIG_STACKTRACE
64224 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
64225 ONE("stack", S_IRUSR, proc_pid_stack),
64226 #endif
64227 #ifdef CONFIG_SCHEDSTATS
64228 @@ -2630,6 +2751,9 @@ static const struct pid_entry tgid_base_stuff[] = {
64229 #ifdef CONFIG_HARDWALL
64230 INF("hardwall", S_IRUGO, proc_pid_hardwall),
64231 #endif
64232 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
64233 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
64234 +#endif
64235 #ifdef CONFIG_USER_NS
64236 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
64237 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
64238 @@ -2760,7 +2884,14 @@ static int proc_pid_instantiate(struct inode *dir,
64239 if (!inode)
64240 goto out;
64241
64242 +#ifdef CONFIG_GRKERNSEC_PROC_USER
64243 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
64244 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64245 + inode->i_gid = grsec_proc_gid;
64246 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
64247 +#else
64248 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
64249 +#endif
64250 inode->i_op = &proc_tgid_base_inode_operations;
64251 inode->i_fop = &proc_tgid_base_operations;
64252 inode->i_flags|=S_IMMUTABLE;
64253 @@ -2798,7 +2929,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
64254 if (!task)
64255 goto out;
64256
64257 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
64258 + goto out_put_task;
64259 +
64260 result = proc_pid_instantiate(dir, dentry, task, NULL);
64261 +out_put_task:
64262 put_task_struct(task);
64263 out:
64264 return ERR_PTR(result);
64265 @@ -2904,7 +3039,7 @@ static const struct pid_entry tid_base_stuff[] = {
64266 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
64267 #endif
64268 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
64269 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
64270 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
64271 INF("syscall", S_IRUSR, proc_pid_syscall),
64272 #endif
64273 INF("cmdline", S_IRUGO, proc_pid_cmdline),
64274 @@ -2931,10 +3066,10 @@ static const struct pid_entry tid_base_stuff[] = {
64275 #ifdef CONFIG_SECURITY
64276 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
64277 #endif
64278 -#ifdef CONFIG_KALLSYMS
64279 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
64280 INF("wchan", S_IRUGO, proc_pid_wchan),
64281 #endif
64282 -#ifdef CONFIG_STACKTRACE
64283 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
64284 ONE("stack", S_IRUSR, proc_pid_stack),
64285 #endif
64286 #ifdef CONFIG_SCHEDSTATS
64287 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
64288 index cbd82df..c0407d2 100644
64289 --- a/fs/proc/cmdline.c
64290 +++ b/fs/proc/cmdline.c
64291 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
64292
64293 static int __init proc_cmdline_init(void)
64294 {
64295 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
64296 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
64297 +#else
64298 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
64299 +#endif
64300 return 0;
64301 }
64302 fs_initcall(proc_cmdline_init);
64303 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
64304 index 50493ed..248166b 100644
64305 --- a/fs/proc/devices.c
64306 +++ b/fs/proc/devices.c
64307 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
64308
64309 static int __init proc_devices_init(void)
64310 {
64311 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
64312 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
64313 +#else
64314 proc_create("devices", 0, NULL, &proc_devinfo_operations);
64315 +#endif
64316 return 0;
64317 }
64318 fs_initcall(proc_devices_init);
64319 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
64320 index 0788d09..9cc1385 100644
64321 --- a/fs/proc/fd.c
64322 +++ b/fs/proc/fd.c
64323 @@ -26,7 +26,8 @@ static int seq_show(struct seq_file *m, void *v)
64324 if (!task)
64325 return -ENOENT;
64326
64327 - files = get_files_struct(task);
64328 + if (!gr_acl_handle_procpidmem(task))
64329 + files = get_files_struct(task);
64330 put_task_struct(task);
64331
64332 if (files) {
64333 @@ -285,11 +286,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
64334 */
64335 int proc_fd_permission(struct inode *inode, int mask)
64336 {
64337 + struct task_struct *task;
64338 int rv = generic_permission(inode, mask);
64339 - if (rv == 0)
64340 - return 0;
64341 +
64342 if (task_tgid(current) == proc_pid(inode))
64343 rv = 0;
64344 +
64345 + task = get_proc_task(inode);
64346 + if (task == NULL)
64347 + return rv;
64348 +
64349 + if (gr_acl_handle_procpidmem(task))
64350 + rv = -EACCES;
64351 +
64352 + put_task_struct(task);
64353 +
64354 return rv;
64355 }
64356
64357 diff --git a/fs/proc/generic.c b/fs/proc/generic.c
64358 index b7f268e..3bea6b7 100644
64359 --- a/fs/proc/generic.c
64360 +++ b/fs/proc/generic.c
64361 @@ -23,6 +23,7 @@
64362 #include <linux/bitops.h>
64363 #include <linux/spinlock.h>
64364 #include <linux/completion.h>
64365 +#include <linux/grsecurity.h>
64366 #include <asm/uaccess.h>
64367
64368 #include "internal.h"
64369 @@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
64370 return proc_lookup_de(PDE(dir), dir, dentry);
64371 }
64372
64373 +struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
64374 + unsigned int flags)
64375 +{
64376 + if (gr_proc_is_restricted())
64377 + return ERR_PTR(-EACCES);
64378 +
64379 + return proc_lookup_de(PDE(dir), dir, dentry);
64380 +}
64381 +
64382 /*
64383 * This returns non-zero if at EOF, so that the /proc
64384 * root directory can use this and check if it should
64385 @@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
64386 return proc_readdir_de(PDE(inode), file, ctx);
64387 }
64388
64389 +int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
64390 +{
64391 + struct inode *inode = file_inode(file);
64392 +
64393 + if (gr_proc_is_restricted())
64394 + return -EACCES;
64395 +
64396 + return proc_readdir_de(PDE(inode), file, ctx);
64397 +}
64398 +
64399 /*
64400 * These are the generic /proc directory operations. They
64401 * use the in-memory "struct proc_dir_entry" tree to parse
64402 @@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
64403 .iterate = proc_readdir,
64404 };
64405
64406 +static const struct file_operations proc_dir_restricted_operations = {
64407 + .llseek = generic_file_llseek,
64408 + .read = generic_read_dir,
64409 + .iterate = proc_readdir_restrict,
64410 +};
64411 +
64412 /*
64413 * proc directories can do almost nothing..
64414 */
64415 @@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
64416 .setattr = proc_notify_change,
64417 };
64418
64419 +static const struct inode_operations proc_dir_restricted_inode_operations = {
64420 + .lookup = proc_lookup_restrict,
64421 + .getattr = proc_getattr,
64422 + .setattr = proc_notify_change,
64423 +};
64424 +
64425 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
64426 {
64427 struct proc_dir_entry *tmp;
64428 @@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
64429 return ret;
64430
64431 if (S_ISDIR(dp->mode)) {
64432 - dp->proc_fops = &proc_dir_operations;
64433 - dp->proc_iops = &proc_dir_inode_operations;
64434 + if (dp->restricted) {
64435 + dp->proc_fops = &proc_dir_restricted_operations;
64436 + dp->proc_iops = &proc_dir_restricted_inode_operations;
64437 + } else {
64438 + dp->proc_fops = &proc_dir_operations;
64439 + dp->proc_iops = &proc_dir_inode_operations;
64440 + }
64441 dir->nlink++;
64442 } else if (S_ISLNK(dp->mode)) {
64443 dp->proc_iops = &proc_link_inode_operations;
64444 @@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
64445 }
64446 EXPORT_SYMBOL_GPL(proc_mkdir_data);
64447
64448 +struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
64449 + struct proc_dir_entry *parent, void *data)
64450 +{
64451 + struct proc_dir_entry *ent;
64452 +
64453 + if (mode == 0)
64454 + mode = S_IRUGO | S_IXUGO;
64455 +
64456 + ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
64457 + if (ent) {
64458 + ent->data = data;
64459 + ent->restricted = 1;
64460 + if (proc_register(parent, ent) < 0) {
64461 + kfree(ent);
64462 + ent = NULL;
64463 + }
64464 + }
64465 + return ent;
64466 +}
64467 +EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
64468 +
64469 struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
64470 struct proc_dir_entry *parent)
64471 {
64472 @@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
64473 }
64474 EXPORT_SYMBOL(proc_mkdir);
64475
64476 +struct proc_dir_entry *proc_mkdir_restrict(const char *name,
64477 + struct proc_dir_entry *parent)
64478 +{
64479 + return proc_mkdir_data_restrict(name, 0, parent, NULL);
64480 +}
64481 +EXPORT_SYMBOL(proc_mkdir_restrict);
64482 +
64483 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
64484 struct proc_dir_entry *parent,
64485 const struct file_operations *proc_fops,
64486 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
64487 index 0adbc02..bee4d0b 100644
64488 --- a/fs/proc/inode.c
64489 +++ b/fs/proc/inode.c
64490 @@ -23,11 +23,17 @@
64491 #include <linux/slab.h>
64492 #include <linux/mount.h>
64493 #include <linux/magic.h>
64494 +#include <linux/grsecurity.h>
64495
64496 #include <asm/uaccess.h>
64497
64498 #include "internal.h"
64499
64500 +#ifdef CONFIG_PROC_SYSCTL
64501 +extern const struct inode_operations proc_sys_inode_operations;
64502 +extern const struct inode_operations proc_sys_dir_operations;
64503 +#endif
64504 +
64505 static void proc_evict_inode(struct inode *inode)
64506 {
64507 struct proc_dir_entry *de;
64508 @@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
64509 ns = PROC_I(inode)->ns.ns;
64510 if (ns_ops && ns)
64511 ns_ops->put(ns);
64512 +
64513 +#ifdef CONFIG_PROC_SYSCTL
64514 + if (inode->i_op == &proc_sys_inode_operations ||
64515 + inode->i_op == &proc_sys_dir_operations)
64516 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
64517 +#endif
64518 +
64519 }
64520
64521 static struct kmem_cache * proc_inode_cachep;
64522 @@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
64523 if (de->mode) {
64524 inode->i_mode = de->mode;
64525 inode->i_uid = de->uid;
64526 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64527 + inode->i_gid = grsec_proc_gid;
64528 +#else
64529 inode->i_gid = de->gid;
64530 +#endif
64531 }
64532 if (de->size)
64533 inode->i_size = de->size;
64534 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
64535 index 3ab6d14..b26174e 100644
64536 --- a/fs/proc/internal.h
64537 +++ b/fs/proc/internal.h
64538 @@ -46,9 +46,10 @@ struct proc_dir_entry {
64539 struct completion *pde_unload_completion;
64540 struct list_head pde_openers; /* who did ->open, but not ->release */
64541 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
64542 + u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
64543 u8 namelen;
64544 char name[];
64545 -};
64546 +} __randomize_layout;
64547
64548 union proc_op {
64549 int (*proc_get_link)(struct dentry *, struct path *);
64550 @@ -67,7 +68,7 @@ struct proc_inode {
64551 struct ctl_table *sysctl_entry;
64552 struct proc_ns ns;
64553 struct inode vfs_inode;
64554 -};
64555 +} __randomize_layout;
64556
64557 /*
64558 * General functions
64559 @@ -155,6 +156,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
64560 struct pid *, struct task_struct *);
64561 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
64562 struct pid *, struct task_struct *);
64563 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
64564 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
64565 +#endif
64566
64567 /*
64568 * base.c
64569 @@ -181,9 +185,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
64570 extern spinlock_t proc_subdir_lock;
64571
64572 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
64573 +extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
64574 extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
64575 struct dentry *);
64576 extern int proc_readdir(struct file *, struct dir_context *);
64577 +extern int proc_readdir_restrict(struct file *, struct dir_context *);
64578 extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
64579
64580 static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
64581 diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
64582 index a352d57..cb94a5c 100644
64583 --- a/fs/proc/interrupts.c
64584 +++ b/fs/proc/interrupts.c
64585 @@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
64586
64587 static int __init proc_interrupts_init(void)
64588 {
64589 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
64590 + proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
64591 +#else
64592 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
64593 +#endif
64594 return 0;
64595 }
64596 fs_initcall(proc_interrupts_init);
64597 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
64598 index 39e6ef3..2f9cb5e 100644
64599 --- a/fs/proc/kcore.c
64600 +++ b/fs/proc/kcore.c
64601 @@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
64602 * the addresses in the elf_phdr on our list.
64603 */
64604 start = kc_offset_to_vaddr(*fpos - elf_buflen);
64605 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
64606 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
64607 + if (tsz > buflen)
64608 tsz = buflen;
64609 -
64610 +
64611 while (buflen) {
64612 struct kcore_list *m;
64613
64614 @@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
64615 kfree(elf_buf);
64616 } else {
64617 if (kern_addr_valid(start)) {
64618 - unsigned long n;
64619 + char *elf_buf;
64620 + mm_segment_t oldfs;
64621
64622 - n = copy_to_user(buffer, (char *)start, tsz);
64623 - /*
64624 - * We cannot distinguish between fault on source
64625 - * and fault on destination. When this happens
64626 - * we clear too and hope it will trigger the
64627 - * EFAULT again.
64628 - */
64629 - if (n) {
64630 - if (clear_user(buffer + tsz - n,
64631 - n))
64632 + elf_buf = kmalloc(tsz, GFP_KERNEL);
64633 + if (!elf_buf)
64634 + return -ENOMEM;
64635 + oldfs = get_fs();
64636 + set_fs(KERNEL_DS);
64637 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
64638 + set_fs(oldfs);
64639 + if (copy_to_user(buffer, elf_buf, tsz)) {
64640 + kfree(elf_buf);
64641 return -EFAULT;
64642 + }
64643 }
64644 + set_fs(oldfs);
64645 + kfree(elf_buf);
64646 } else {
64647 if (clear_user(buffer, tsz))
64648 return -EFAULT;
64649 @@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
64650
64651 static int open_kcore(struct inode *inode, struct file *filp)
64652 {
64653 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
64654 + return -EPERM;
64655 +#endif
64656 if (!capable(CAP_SYS_RAWIO))
64657 return -EPERM;
64658 if (kcore_need_update)
64659 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
64660 index 7445af0..7c5113c 100644
64661 --- a/fs/proc/meminfo.c
64662 +++ b/fs/proc/meminfo.c
64663 @@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
64664 vmi.used >> 10,
64665 vmi.largest_chunk >> 10
64666 #ifdef CONFIG_MEMORY_FAILURE
64667 - ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
64668 + ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
64669 #endif
64670 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
64671 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
64672 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
64673 index d4a3574..b421ce9 100644
64674 --- a/fs/proc/nommu.c
64675 +++ b/fs/proc/nommu.c
64676 @@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
64677
64678 if (file) {
64679 seq_pad(m, ' ');
64680 - seq_path(m, &file->f_path, "");
64681 + seq_path(m, &file->f_path, "\n\\");
64682 }
64683
64684 seq_putc(m, '\n');
64685 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
64686 index 4677bb7..dad3045 100644
64687 --- a/fs/proc/proc_net.c
64688 +++ b/fs/proc/proc_net.c
64689 @@ -23,9 +23,27 @@
64690 #include <linux/nsproxy.h>
64691 #include <net/net_namespace.h>
64692 #include <linux/seq_file.h>
64693 +#include <linux/grsecurity.h>
64694
64695 #include "internal.h"
64696
64697 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
64698 +static struct seq_operations *ipv6_seq_ops_addr;
64699 +
64700 +void register_ipv6_seq_ops_addr(struct seq_operations *addr)
64701 +{
64702 + ipv6_seq_ops_addr = addr;
64703 +}
64704 +
64705 +void unregister_ipv6_seq_ops_addr(void)
64706 +{
64707 + ipv6_seq_ops_addr = NULL;
64708 +}
64709 +
64710 +EXPORT_SYMBOL_GPL(register_ipv6_seq_ops_addr);
64711 +EXPORT_SYMBOL_GPL(unregister_ipv6_seq_ops_addr);
64712 +#endif
64713 +
64714 static inline struct net *PDE_NET(struct proc_dir_entry *pde)
64715 {
64716 return pde->parent->data;
64717 @@ -36,6 +54,8 @@ static struct net *get_proc_net(const struct inode *inode)
64718 return maybe_get_net(PDE_NET(PDE(inode)));
64719 }
64720
64721 +extern const struct seq_operations dev_seq_ops;
64722 +
64723 int seq_open_net(struct inode *ino, struct file *f,
64724 const struct seq_operations *ops, int size)
64725 {
64726 @@ -44,6 +64,14 @@ int seq_open_net(struct inode *ino, struct file *f,
64727
64728 BUG_ON(size < sizeof(*p));
64729
64730 + /* only permit access to /proc/net/dev */
64731 + if (
64732 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
64733 + ops != ipv6_seq_ops_addr &&
64734 +#endif
64735 + ops != &dev_seq_ops && gr_proc_is_restricted())
64736 + return -EACCES;
64737 +
64738 net = get_proc_net(ino);
64739 if (net == NULL)
64740 return -ENXIO;
64741 @@ -66,6 +94,9 @@ int single_open_net(struct inode *inode, struct file *file,
64742 int err;
64743 struct net *net;
64744
64745 + if (gr_proc_is_restricted())
64746 + return -EACCES;
64747 +
64748 err = -ENXIO;
64749 net = get_proc_net(inode);
64750 if (net == NULL)
64751 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
64752 index 7129046..6914844 100644
64753 --- a/fs/proc/proc_sysctl.c
64754 +++ b/fs/proc/proc_sysctl.c
64755 @@ -11,13 +11,21 @@
64756 #include <linux/namei.h>
64757 #include <linux/mm.h>
64758 #include <linux/module.h>
64759 +#include <linux/nsproxy.h>
64760 +#ifdef CONFIG_GRKERNSEC
64761 +#include <net/net_namespace.h>
64762 +#endif
64763 #include "internal.h"
64764
64765 +extern int gr_handle_chroot_sysctl(const int op);
64766 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
64767 + const int op);
64768 +
64769 static const struct dentry_operations proc_sys_dentry_operations;
64770 static const struct file_operations proc_sys_file_operations;
64771 -static const struct inode_operations proc_sys_inode_operations;
64772 +const struct inode_operations proc_sys_inode_operations;
64773 static const struct file_operations proc_sys_dir_file_operations;
64774 -static const struct inode_operations proc_sys_dir_operations;
64775 +const struct inode_operations proc_sys_dir_operations;
64776
64777 void proc_sys_poll_notify(struct ctl_table_poll *poll)
64778 {
64779 @@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
64780
64781 err = NULL;
64782 d_set_d_op(dentry, &proc_sys_dentry_operations);
64783 +
64784 + gr_handle_proc_create(dentry, inode);
64785 +
64786 d_add(dentry, inode);
64787
64788 out:
64789 @@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64790 struct inode *inode = file_inode(filp);
64791 struct ctl_table_header *head = grab_header(inode);
64792 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
64793 + int op = write ? MAY_WRITE : MAY_READ;
64794 ssize_t error;
64795 size_t res;
64796
64797 @@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64798 * and won't be until we finish.
64799 */
64800 error = -EPERM;
64801 - if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
64802 + if (sysctl_perm(head, table, op))
64803 goto out;
64804
64805 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
64806 @@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64807 if (!table->proc_handler)
64808 goto out;
64809
64810 +#ifdef CONFIG_GRKERNSEC
64811 + error = -EPERM;
64812 + if (gr_handle_chroot_sysctl(op))
64813 + goto out;
64814 + dget(filp->f_path.dentry);
64815 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
64816 + dput(filp->f_path.dentry);
64817 + goto out;
64818 + }
64819 + dput(filp->f_path.dentry);
64820 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
64821 + goto out;
64822 + if (write) {
64823 + if (current->nsproxy->net_ns != table->extra2) {
64824 + if (!capable(CAP_SYS_ADMIN))
64825 + goto out;
64826 + } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
64827 + goto out;
64828 + }
64829 +#endif
64830 +
64831 /* careful: calling conventions are nasty here */
64832 res = count;
64833 error = table->proc_handler(table, write, buf, &res, ppos);
64834 @@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
64835 return false;
64836 } else {
64837 d_set_d_op(child, &proc_sys_dentry_operations);
64838 +
64839 + gr_handle_proc_create(child, inode);
64840 +
64841 d_add(child, inode);
64842 }
64843 } else {
64844 @@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
64845 if ((*pos)++ < ctx->pos)
64846 return true;
64847
64848 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
64849 + return 0;
64850 +
64851 if (unlikely(S_ISLNK(table->mode)))
64852 res = proc_sys_link_fill_cache(file, ctx, head, table);
64853 else
64854 @@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
64855 if (IS_ERR(head))
64856 return PTR_ERR(head);
64857
64858 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
64859 + return -ENOENT;
64860 +
64861 generic_fillattr(inode, stat);
64862 if (table)
64863 stat->mode = (stat->mode & S_IFMT) | table->mode;
64864 @@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
64865 .llseek = generic_file_llseek,
64866 };
64867
64868 -static const struct inode_operations proc_sys_inode_operations = {
64869 +const struct inode_operations proc_sys_inode_operations = {
64870 .permission = proc_sys_permission,
64871 .setattr = proc_sys_setattr,
64872 .getattr = proc_sys_getattr,
64873 };
64874
64875 -static const struct inode_operations proc_sys_dir_operations = {
64876 +const struct inode_operations proc_sys_dir_operations = {
64877 .lookup = proc_sys_lookup,
64878 .permission = proc_sys_permission,
64879 .setattr = proc_sys_setattr,
64880 @@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
64881 static struct ctl_dir *new_dir(struct ctl_table_set *set,
64882 const char *name, int namelen)
64883 {
64884 - struct ctl_table *table;
64885 + ctl_table_no_const *table;
64886 struct ctl_dir *new;
64887 struct ctl_node *node;
64888 char *new_name;
64889 @@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
64890 return NULL;
64891
64892 node = (struct ctl_node *)(new + 1);
64893 - table = (struct ctl_table *)(node + 1);
64894 + table = (ctl_table_no_const *)(node + 1);
64895 new_name = (char *)(table + 2);
64896 memcpy(new_name, name, namelen);
64897 new_name[namelen] = '\0';
64898 @@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
64899 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
64900 struct ctl_table_root *link_root)
64901 {
64902 - struct ctl_table *link_table, *entry, *link;
64903 + ctl_table_no_const *link_table, *link;
64904 + struct ctl_table *entry;
64905 struct ctl_table_header *links;
64906 struct ctl_node *node;
64907 char *link_name;
64908 @@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
64909 return NULL;
64910
64911 node = (struct ctl_node *)(links + 1);
64912 - link_table = (struct ctl_table *)(node + nr_entries);
64913 + link_table = (ctl_table_no_const *)(node + nr_entries);
64914 link_name = (char *)&link_table[nr_entries + 1];
64915
64916 for (link = link_table, entry = table; entry->procname; link++, entry++) {
64917 @@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64918 struct ctl_table_header ***subheader, struct ctl_table_set *set,
64919 struct ctl_table *table)
64920 {
64921 - struct ctl_table *ctl_table_arg = NULL;
64922 - struct ctl_table *entry, *files;
64923 + ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
64924 + struct ctl_table *entry;
64925 int nr_files = 0;
64926 int nr_dirs = 0;
64927 int err = -ENOMEM;
64928 @@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64929 nr_files++;
64930 }
64931
64932 - files = table;
64933 /* If there are mixed files and directories we need a new table */
64934 if (nr_dirs && nr_files) {
64935 - struct ctl_table *new;
64936 + ctl_table_no_const *new;
64937 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
64938 GFP_KERNEL);
64939 if (!files)
64940 @@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64941 /* Register everything except a directory full of subdirectories */
64942 if (nr_files || !nr_dirs) {
64943 struct ctl_table_header *header;
64944 - header = __register_sysctl_table(set, path, files);
64945 + header = __register_sysctl_table(set, path, files ? files : table);
64946 if (!header) {
64947 kfree(ctl_table_arg);
64948 goto out;
64949 diff --git a/fs/proc/root.c b/fs/proc/root.c
64950 index 5dbadec..473af2f 100644
64951 --- a/fs/proc/root.c
64952 +++ b/fs/proc/root.c
64953 @@ -185,7 +185,15 @@ void __init proc_root_init(void)
64954 proc_mkdir("openprom", NULL);
64955 #endif
64956 proc_tty_init();
64957 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
64958 +#ifdef CONFIG_GRKERNSEC_PROC_USER
64959 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
64960 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64961 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
64962 +#endif
64963 +#else
64964 proc_mkdir("bus", NULL);
64965 +#endif
64966 proc_sys_init();
64967 }
64968
64969 diff --git a/fs/proc/stat.c b/fs/proc/stat.c
64970 index 9d231e9..2e1b51a 100644
64971 --- a/fs/proc/stat.c
64972 +++ b/fs/proc/stat.c
64973 @@ -11,6 +11,7 @@
64974 #include <linux/irqnr.h>
64975 #include <linux/cputime.h>
64976 #include <linux/tick.h>
64977 +#include <linux/grsecurity.h>
64978
64979 #ifndef arch_irq_stat_cpu
64980 #define arch_irq_stat_cpu(cpu) 0
64981 @@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
64982 u64 sum_softirq = 0;
64983 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
64984 struct timespec boottime;
64985 + int unrestricted = 1;
64986 +
64987 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
64988 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64989 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
64990 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64991 + && !in_group_p(grsec_proc_gid)
64992 +#endif
64993 + )
64994 + unrestricted = 0;
64995 +#endif
64996 +#endif
64997
64998 user = nice = system = idle = iowait =
64999 irq = softirq = steal = 0;
65000 @@ -99,23 +112,25 @@ static int show_stat(struct seq_file *p, void *v)
65001 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
65002 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
65003 idle += get_idle_time(i);
65004 - iowait += get_iowait_time(i);
65005 - irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
65006 - softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
65007 - steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
65008 - guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
65009 - guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
65010 - sum += kstat_cpu_irqs_sum(i);
65011 - sum += arch_irq_stat_cpu(i);
65012 + if (unrestricted) {
65013 + iowait += get_iowait_time(i);
65014 + irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
65015 + softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
65016 + steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
65017 + guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
65018 + guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
65019 + sum += kstat_cpu_irqs_sum(i);
65020 + sum += arch_irq_stat_cpu(i);
65021 + for (j = 0; j < NR_SOFTIRQS; j++) {
65022 + unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
65023
65024 - for (j = 0; j < NR_SOFTIRQS; j++) {
65025 - unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
65026 -
65027 - per_softirq_sums[j] += softirq_stat;
65028 - sum_softirq += softirq_stat;
65029 + per_softirq_sums[j] += softirq_stat;
65030 + sum_softirq += softirq_stat;
65031 + }
65032 }
65033 }
65034 - sum += arch_irq_stat();
65035 + if (unrestricted)
65036 + sum += arch_irq_stat();
65037
65038 seq_puts(p, "cpu ");
65039 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
65040 @@ -136,12 +151,14 @@ static int show_stat(struct seq_file *p, void *v)
65041 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
65042 system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
65043 idle = get_idle_time(i);
65044 - iowait = get_iowait_time(i);
65045 - irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
65046 - softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
65047 - steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
65048 - guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
65049 - guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
65050 + if (unrestricted) {
65051 + iowait = get_iowait_time(i);
65052 + irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
65053 + softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
65054 + steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
65055 + guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
65056 + guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
65057 + }
65058 seq_printf(p, "cpu%d", i);
65059 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
65060 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
65061 @@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
65062
65063 /* sum again ? it could be updated? */
65064 for_each_irq_nr(j)
65065 - seq_put_decimal_ull(p, ' ', kstat_irqs(j));
65066 + seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
65067
65068 seq_printf(p,
65069 "\nctxt %llu\n"
65070 @@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
65071 "processes %lu\n"
65072 "procs_running %lu\n"
65073 "procs_blocked %lu\n",
65074 - nr_context_switches(),
65075 + unrestricted ? nr_context_switches() : 0ULL,
65076 (unsigned long)jif,
65077 - total_forks,
65078 - nr_running(),
65079 - nr_iowait());
65080 + unrestricted ? total_forks : 0UL,
65081 + unrestricted ? nr_running() : 0UL,
65082 + unrestricted ? nr_iowait() : 0UL);
65083
65084 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
65085
65086 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
65087 index c4b2646..84f0d7b 100644
65088 --- a/fs/proc/task_mmu.c
65089 +++ b/fs/proc/task_mmu.c
65090 @@ -13,12 +13,19 @@
65091 #include <linux/swap.h>
65092 #include <linux/swapops.h>
65093 #include <linux/mmu_notifier.h>
65094 +#include <linux/grsecurity.h>
65095
65096 #include <asm/elf.h>
65097 #include <asm/uaccess.h>
65098 #include <asm/tlbflush.h>
65099 #include "internal.h"
65100
65101 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65102 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
65103 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
65104 + _mm->pax_flags & MF_PAX_SEGMEXEC))
65105 +#endif
65106 +
65107 void task_mem(struct seq_file *m, struct mm_struct *mm)
65108 {
65109 unsigned long data, text, lib, swap;
65110 @@ -54,8 +61,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
65111 "VmExe:\t%8lu kB\n"
65112 "VmLib:\t%8lu kB\n"
65113 "VmPTE:\t%8lu kB\n"
65114 - "VmSwap:\t%8lu kB\n",
65115 - hiwater_vm << (PAGE_SHIFT-10),
65116 + "VmSwap:\t%8lu kB\n"
65117 +
65118 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
65119 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
65120 +#endif
65121 +
65122 + ,hiwater_vm << (PAGE_SHIFT-10),
65123 total_vm << (PAGE_SHIFT-10),
65124 mm->locked_vm << (PAGE_SHIFT-10),
65125 mm->pinned_vm << (PAGE_SHIFT-10),
65126 @@ -65,7 +77,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
65127 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
65128 (PTRS_PER_PTE * sizeof(pte_t) *
65129 atomic_long_read(&mm->nr_ptes)) >> 10,
65130 - swap << (PAGE_SHIFT-10));
65131 + swap << (PAGE_SHIFT-10)
65132 +
65133 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
65134 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65135 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
65136 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
65137 +#else
65138 + , mm->context.user_cs_base
65139 + , mm->context.user_cs_limit
65140 +#endif
65141 +#endif
65142 +
65143 + );
65144 }
65145
65146 unsigned long task_vsize(struct mm_struct *mm)
65147 @@ -271,13 +295,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
65148 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
65149 }
65150
65151 - /* We don't show the stack guard page in /proc/maps */
65152 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65153 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
65154 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
65155 +#else
65156 start = vma->vm_start;
65157 - if (stack_guard_page_start(vma, start))
65158 - start += PAGE_SIZE;
65159 end = vma->vm_end;
65160 - if (stack_guard_page_end(vma, end))
65161 - end -= PAGE_SIZE;
65162 +#endif
65163
65164 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
65165 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
65166 @@ -287,7 +311,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
65167 flags & VM_WRITE ? 'w' : '-',
65168 flags & VM_EXEC ? 'x' : '-',
65169 flags & VM_MAYSHARE ? 's' : 'p',
65170 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65171 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
65172 +#else
65173 pgoff,
65174 +#endif
65175 MAJOR(dev), MINOR(dev), ino);
65176
65177 /*
65178 @@ -296,7 +324,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
65179 */
65180 if (file) {
65181 seq_pad(m, ' ');
65182 - seq_path(m, &file->f_path, "\n");
65183 + seq_path(m, &file->f_path, "\n\\");
65184 goto done;
65185 }
65186
65187 @@ -322,8 +350,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
65188 * Thread stack in /proc/PID/task/TID/maps or
65189 * the main process stack.
65190 */
65191 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
65192 - vma->vm_end >= mm->start_stack)) {
65193 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
65194 + (vma->vm_start <= mm->start_stack &&
65195 + vma->vm_end >= mm->start_stack)) {
65196 name = "[stack]";
65197 } else {
65198 /* Thread stack in /proc/PID/maps */
65199 @@ -347,6 +376,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
65200 struct proc_maps_private *priv = m->private;
65201 struct task_struct *task = priv->task;
65202
65203 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65204 + if (current->exec_id != m->exec_id) {
65205 + gr_log_badprocpid("maps");
65206 + return 0;
65207 + }
65208 +#endif
65209 +
65210 show_map_vma(m, vma, is_pid);
65211
65212 if (m->count < m->size) /* vma is copied successfully */
65213 @@ -587,12 +623,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
65214 .private = &mss,
65215 };
65216
65217 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65218 + if (current->exec_id != m->exec_id) {
65219 + gr_log_badprocpid("smaps");
65220 + return 0;
65221 + }
65222 +#endif
65223 memset(&mss, 0, sizeof mss);
65224 - mss.vma = vma;
65225 - /* mmap_sem is held in m_start */
65226 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
65227 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
65228 -
65229 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65230 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
65231 +#endif
65232 + mss.vma = vma;
65233 + /* mmap_sem is held in m_start */
65234 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
65235 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
65236 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65237 + }
65238 +#endif
65239 show_map_vma(m, vma, is_pid);
65240
65241 seq_printf(m,
65242 @@ -610,7 +657,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
65243 "KernelPageSize: %8lu kB\n"
65244 "MMUPageSize: %8lu kB\n"
65245 "Locked: %8lu kB\n",
65246 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65247 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
65248 +#else
65249 (vma->vm_end - vma->vm_start) >> 10,
65250 +#endif
65251 mss.resident >> 10,
65252 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
65253 mss.shared_clean >> 10,
65254 @@ -1388,6 +1439,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
65255 char buffer[64];
65256 int nid;
65257
65258 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65259 + if (current->exec_id != m->exec_id) {
65260 + gr_log_badprocpid("numa_maps");
65261 + return 0;
65262 + }
65263 +#endif
65264 +
65265 if (!mm)
65266 return 0;
65267
65268 @@ -1405,11 +1463,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
65269 mpol_to_str(buffer, sizeof(buffer), pol);
65270 mpol_cond_put(pol);
65271
65272 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65273 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
65274 +#else
65275 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
65276 +#endif
65277
65278 if (file) {
65279 seq_printf(m, " file=");
65280 - seq_path(m, &file->f_path, "\n\t= ");
65281 + seq_path(m, &file->f_path, "\n\t\\= ");
65282 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
65283 seq_printf(m, " heap");
65284 } else {
65285 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
65286 index 678455d..ebd3245 100644
65287 --- a/fs/proc/task_nommu.c
65288 +++ b/fs/proc/task_nommu.c
65289 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
65290 else
65291 bytes += kobjsize(mm);
65292
65293 - if (current->fs && current->fs->users > 1)
65294 + if (current->fs && atomic_read(&current->fs->users) > 1)
65295 sbytes += kobjsize(current->fs);
65296 else
65297 bytes += kobjsize(current->fs);
65298 @@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
65299
65300 if (file) {
65301 seq_pad(m, ' ');
65302 - seq_path(m, &file->f_path, "");
65303 + seq_path(m, &file->f_path, "\n\\");
65304 } else if (mm) {
65305 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
65306
65307 diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
65308 index 6a8e785..41f2a6c 100644
65309 --- a/fs/proc/vmcore.c
65310 +++ b/fs/proc/vmcore.c
65311 @@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
65312 nr_bytes = count;
65313
65314 /* If pfn is not ram, return zeros for sparse dump files */
65315 - if (pfn_is_ram(pfn) == 0)
65316 - memset(buf, 0, nr_bytes);
65317 - else {
65318 + if (pfn_is_ram(pfn) == 0) {
65319 + if (userbuf) {
65320 + if (clear_user((char __force_user *)buf, nr_bytes))
65321 + return -EFAULT;
65322 + } else
65323 + memset(buf, 0, nr_bytes);
65324 + } else {
65325 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
65326 offset, userbuf);
65327 if (tmp < 0)
65328 @@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
65329 static int copy_to(void *target, void *src, size_t size, int userbuf)
65330 {
65331 if (userbuf) {
65332 - if (copy_to_user((char __user *) target, src, size))
65333 + if (copy_to_user((char __force_user *) target, src, size))
65334 return -EFAULT;
65335 } else {
65336 memcpy(target, src, size);
65337 @@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
65338 if (*fpos < m->offset + m->size) {
65339 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
65340 start = m->paddr + *fpos - m->offset;
65341 - tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
65342 + tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
65343 if (tmp < 0)
65344 return tmp;
65345 buflen -= tsz;
65346 @@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
65347 static ssize_t read_vmcore(struct file *file, char __user *buffer,
65348 size_t buflen, loff_t *fpos)
65349 {
65350 - return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
65351 + return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
65352 }
65353
65354 /*
65355 diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
65356 index b00fcc9..e0c6381 100644
65357 --- a/fs/qnx6/qnx6.h
65358 +++ b/fs/qnx6/qnx6.h
65359 @@ -74,7 +74,7 @@ enum {
65360 BYTESEX_BE,
65361 };
65362
65363 -static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
65364 +static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
65365 {
65366 if (sbi->s_bytesex == BYTESEX_LE)
65367 return le64_to_cpu((__force __le64)n);
65368 @@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
65369 return (__force __fs64)cpu_to_be64(n);
65370 }
65371
65372 -static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
65373 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
65374 {
65375 if (sbi->s_bytesex == BYTESEX_LE)
65376 return le32_to_cpu((__force __le32)n);
65377 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
65378 index 72d2917..c917c12 100644
65379 --- a/fs/quota/netlink.c
65380 +++ b/fs/quota/netlink.c
65381 @@ -45,7 +45,7 @@ static struct genl_family quota_genl_family = {
65382 void quota_send_warning(struct kqid qid, dev_t dev,
65383 const char warntype)
65384 {
65385 - static atomic_t seq;
65386 + static atomic_unchecked_t seq;
65387 struct sk_buff *skb;
65388 void *msg_head;
65389 int ret;
65390 @@ -61,7 +61,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
65391 "VFS: Not enough memory to send quota warning.\n");
65392 return;
65393 }
65394 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
65395 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
65396 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
65397 if (!msg_head) {
65398 printk(KERN_ERR
65399 diff --git a/fs/read_write.c b/fs/read_write.c
65400 index 31c6efa..a068805 100644
65401 --- a/fs/read_write.c
65402 +++ b/fs/read_write.c
65403 @@ -450,7 +450,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
65404
65405 old_fs = get_fs();
65406 set_fs(get_ds());
65407 - p = (__force const char __user *)buf;
65408 + p = (const char __force_user *)buf;
65409 if (count > MAX_RW_COUNT)
65410 count = MAX_RW_COUNT;
65411 if (file->f_op->write)
65412 diff --git a/fs/readdir.c b/fs/readdir.c
65413 index 5b53d99..a6c3049 100644
65414 --- a/fs/readdir.c
65415 +++ b/fs/readdir.c
65416 @@ -17,6 +17,7 @@
65417 #include <linux/security.h>
65418 #include <linux/syscalls.h>
65419 #include <linux/unistd.h>
65420 +#include <linux/namei.h>
65421
65422 #include <asm/uaccess.h>
65423
65424 @@ -69,6 +70,7 @@ struct old_linux_dirent {
65425 struct readdir_callback {
65426 struct dir_context ctx;
65427 struct old_linux_dirent __user * dirent;
65428 + struct file * file;
65429 int result;
65430 };
65431
65432 @@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
65433 buf->result = -EOVERFLOW;
65434 return -EOVERFLOW;
65435 }
65436 +
65437 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
65438 + return 0;
65439 +
65440 buf->result++;
65441 dirent = buf->dirent;
65442 if (!access_ok(VERIFY_WRITE, dirent,
65443 @@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
65444 if (!f.file)
65445 return -EBADF;
65446
65447 + buf.file = f.file;
65448 error = iterate_dir(f.file, &buf.ctx);
65449 if (buf.result)
65450 error = buf.result;
65451 @@ -142,6 +149,7 @@ struct getdents_callback {
65452 struct dir_context ctx;
65453 struct linux_dirent __user * current_dir;
65454 struct linux_dirent __user * previous;
65455 + struct file * file;
65456 int count;
65457 int error;
65458 };
65459 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
65460 buf->error = -EOVERFLOW;
65461 return -EOVERFLOW;
65462 }
65463 +
65464 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
65465 + return 0;
65466 +
65467 dirent = buf->previous;
65468 if (dirent) {
65469 if (__put_user(offset, &dirent->d_off))
65470 @@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
65471 if (!f.file)
65472 return -EBADF;
65473
65474 + buf.file = f.file;
65475 error = iterate_dir(f.file, &buf.ctx);
65476 if (error >= 0)
65477 error = buf.error;
65478 @@ -226,6 +239,7 @@ struct getdents_callback64 {
65479 struct dir_context ctx;
65480 struct linux_dirent64 __user * current_dir;
65481 struct linux_dirent64 __user * previous;
65482 + struct file *file;
65483 int count;
65484 int error;
65485 };
65486 @@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
65487 buf->error = -EINVAL; /* only used if we fail.. */
65488 if (reclen > buf->count)
65489 return -EINVAL;
65490 +
65491 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
65492 + return 0;
65493 +
65494 dirent = buf->previous;
65495 if (dirent) {
65496 if (__put_user(offset, &dirent->d_off))
65497 @@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
65498 if (!f.file)
65499 return -EBADF;
65500
65501 + buf.file = f.file;
65502 error = iterate_dir(f.file, &buf.ctx);
65503 if (error >= 0)
65504 error = buf.error;
65505 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
65506 index 9a3c68c..767933e 100644
65507 --- a/fs/reiserfs/do_balan.c
65508 +++ b/fs/reiserfs/do_balan.c
65509 @@ -1546,7 +1546,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
65510 return;
65511 }
65512
65513 - atomic_inc(&(fs_generation(tb->tb_sb)));
65514 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
65515 do_balance_starts(tb);
65516
65517 /* balance leaf returns 0 except if combining L R and S into
65518 diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
65519 index ee382ef..f4eb6eb5 100644
65520 --- a/fs/reiserfs/item_ops.c
65521 +++ b/fs/reiserfs/item_ops.c
65522 @@ -725,18 +725,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
65523 }
65524
65525 static struct item_operations errcatch_ops = {
65526 - errcatch_bytes_number,
65527 - errcatch_decrement_key,
65528 - errcatch_is_left_mergeable,
65529 - errcatch_print_item,
65530 - errcatch_check_item,
65531 + .bytes_number = errcatch_bytes_number,
65532 + .decrement_key = errcatch_decrement_key,
65533 + .is_left_mergeable = errcatch_is_left_mergeable,
65534 + .print_item = errcatch_print_item,
65535 + .check_item = errcatch_check_item,
65536
65537 - errcatch_create_vi,
65538 - errcatch_check_left,
65539 - errcatch_check_right,
65540 - errcatch_part_size,
65541 - errcatch_unit_num,
65542 - errcatch_print_vi
65543 + .create_vi = errcatch_create_vi,
65544 + .check_left = errcatch_check_left,
65545 + .check_right = errcatch_check_right,
65546 + .part_size = errcatch_part_size,
65547 + .unit_num = errcatch_unit_num,
65548 + .print_vi = errcatch_print_vi
65549 };
65550
65551 //////////////////////////////////////////////////////////////////////////////
65552 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
65553 index 02b0b7d..c85018b 100644
65554 --- a/fs/reiserfs/procfs.c
65555 +++ b/fs/reiserfs/procfs.c
65556 @@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
65557 "SMALL_TAILS " : "NO_TAILS ",
65558 replay_only(sb) ? "REPLAY_ONLY " : "",
65559 convert_reiserfs(sb) ? "CONV " : "",
65560 - atomic_read(&r->s_generation_counter),
65561 + atomic_read_unchecked(&r->s_generation_counter),
65562 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
65563 SF(s_do_balance), SF(s_unneeded_left_neighbor),
65564 SF(s_good_search_by_key_reada), SF(s_bmaps),
65565 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
65566 index 83d4eac..04e39a7 100644
65567 --- a/fs/reiserfs/reiserfs.h
65568 +++ b/fs/reiserfs/reiserfs.h
65569 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
65570 /* Comment? -Hans */
65571 wait_queue_head_t s_wait;
65572 /* To be obsoleted soon by per buffer seals.. -Hans */
65573 - atomic_t s_generation_counter; // increased by one every time the
65574 + atomic_unchecked_t s_generation_counter; // increased by one every time the
65575 // tree gets re-balanced
65576 unsigned long s_properties; /* File system properties. Currently holds
65577 on-disk FS format */
65578 @@ -1972,7 +1972,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
65579 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
65580
65581 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
65582 -#define get_generation(s) atomic_read (&fs_generation(s))
65583 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
65584 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
65585 #define __fs_changed(gen,s) (gen != get_generation (s))
65586 #define fs_changed(gen,s) \
65587 diff --git a/fs/select.c b/fs/select.c
65588 index 467bb1c..cf9d65a 100644
65589 --- a/fs/select.c
65590 +++ b/fs/select.c
65591 @@ -20,6 +20,7 @@
65592 #include <linux/export.h>
65593 #include <linux/slab.h>
65594 #include <linux/poll.h>
65595 +#include <linux/security.h>
65596 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
65597 #include <linux/file.h>
65598 #include <linux/fdtable.h>
65599 @@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
65600 struct poll_list *walk = head;
65601 unsigned long todo = nfds;
65602
65603 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
65604 if (nfds > rlimit(RLIMIT_NOFILE))
65605 return -EINVAL;
65606
65607 diff --git a/fs/seq_file.c b/fs/seq_file.c
65608 index 1d641bb..c2f4743 100644
65609 --- a/fs/seq_file.c
65610 +++ b/fs/seq_file.c
65611 @@ -10,6 +10,8 @@
65612 #include <linux/seq_file.h>
65613 #include <linux/slab.h>
65614 #include <linux/cred.h>
65615 +#include <linux/sched.h>
65616 +#include <linux/grsecurity.h>
65617
65618 #include <asm/uaccess.h>
65619 #include <asm/page.h>
65620 @@ -60,6 +62,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
65621 #ifdef CONFIG_USER_NS
65622 p->user_ns = file->f_cred->user_ns;
65623 #endif
65624 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65625 + p->exec_id = current->exec_id;
65626 +#endif
65627
65628 /*
65629 * Wrappers around seq_open(e.g. swaps_open) need to be
65630 @@ -82,6 +87,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
65631 }
65632 EXPORT_SYMBOL(seq_open);
65633
65634 +
65635 +int seq_open_restrict(struct file *file, const struct seq_operations *op)
65636 +{
65637 + if (gr_proc_is_restricted())
65638 + return -EACCES;
65639 +
65640 + return seq_open(file, op);
65641 +}
65642 +EXPORT_SYMBOL(seq_open_restrict);
65643 +
65644 static int traverse(struct seq_file *m, loff_t offset)
65645 {
65646 loff_t pos = 0, index;
65647 @@ -96,7 +111,7 @@ static int traverse(struct seq_file *m, loff_t offset)
65648 return 0;
65649 }
65650 if (!m->buf) {
65651 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
65652 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
65653 if (!m->buf)
65654 return -ENOMEM;
65655 }
65656 @@ -137,7 +152,7 @@ Eoverflow:
65657 m->op->stop(m, p);
65658 kfree(m->buf);
65659 m->count = 0;
65660 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
65661 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
65662 return !m->buf ? -ENOMEM : -EAGAIN;
65663 }
65664
65665 @@ -153,7 +168,7 @@ Eoverflow:
65666 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65667 {
65668 struct seq_file *m = file->private_data;
65669 - size_t copied = 0;
65670 + ssize_t copied = 0;
65671 loff_t pos;
65672 size_t n;
65673 void *p;
65674 @@ -192,7 +207,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65675
65676 /* grab buffer if we didn't have one */
65677 if (!m->buf) {
65678 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
65679 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
65680 if (!m->buf)
65681 goto Enomem;
65682 }
65683 @@ -234,7 +249,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65684 m->op->stop(m, p);
65685 kfree(m->buf);
65686 m->count = 0;
65687 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
65688 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
65689 if (!m->buf)
65690 goto Enomem;
65691 m->version = 0;
65692 @@ -584,7 +599,7 @@ static void single_stop(struct seq_file *p, void *v)
65693 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
65694 void *data)
65695 {
65696 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
65697 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
65698 int res = -ENOMEM;
65699
65700 if (op) {
65701 @@ -620,6 +635,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
65702 }
65703 EXPORT_SYMBOL(single_open_size);
65704
65705 +int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
65706 + void *data)
65707 +{
65708 + if (gr_proc_is_restricted())
65709 + return -EACCES;
65710 +
65711 + return single_open(file, show, data);
65712 +}
65713 +EXPORT_SYMBOL(single_open_restrict);
65714 +
65715 +
65716 int single_release(struct inode *inode, struct file *file)
65717 {
65718 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
65719 diff --git a/fs/splice.c b/fs/splice.c
65720 index e246954..bd4f5b5 100644
65721 --- a/fs/splice.c
65722 +++ b/fs/splice.c
65723 @@ -192,7 +192,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65724 pipe_lock(pipe);
65725
65726 for (;;) {
65727 - if (!pipe->readers) {
65728 + if (!atomic_read(&pipe->readers)) {
65729 send_sig(SIGPIPE, current, 0);
65730 if (!ret)
65731 ret = -EPIPE;
65732 @@ -215,7 +215,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65733 page_nr++;
65734 ret += buf->len;
65735
65736 - if (pipe->files)
65737 + if (atomic_read(&pipe->files))
65738 do_wakeup = 1;
65739
65740 if (!--spd->nr_pages)
65741 @@ -246,9 +246,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65742 do_wakeup = 0;
65743 }
65744
65745 - pipe->waiting_writers++;
65746 + atomic_inc(&pipe->waiting_writers);
65747 pipe_wait(pipe);
65748 - pipe->waiting_writers--;
65749 + atomic_dec(&pipe->waiting_writers);
65750 }
65751
65752 pipe_unlock(pipe);
65753 @@ -575,7 +575,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
65754 old_fs = get_fs();
65755 set_fs(get_ds());
65756 /* The cast to a user pointer is valid due to the set_fs() */
65757 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
65758 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
65759 set_fs(old_fs);
65760
65761 return res;
65762 @@ -590,7 +590,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
65763 old_fs = get_fs();
65764 set_fs(get_ds());
65765 /* The cast to a user pointer is valid due to the set_fs() */
65766 - res = vfs_write(file, (__force const char __user *)buf, count, &pos);
65767 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
65768 set_fs(old_fs);
65769
65770 return res;
65771 @@ -643,7 +643,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
65772 goto err;
65773
65774 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
65775 - vec[i].iov_base = (void __user *) page_address(page);
65776 + vec[i].iov_base = (void __force_user *) page_address(page);
65777 vec[i].iov_len = this_len;
65778 spd.pages[i] = page;
65779 spd.nr_pages++;
65780 @@ -839,7 +839,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
65781 ops->release(pipe, buf);
65782 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
65783 pipe->nrbufs--;
65784 - if (pipe->files)
65785 + if (atomic_read(&pipe->files))
65786 sd->need_wakeup = true;
65787 }
65788
65789 @@ -864,10 +864,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
65790 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
65791 {
65792 while (!pipe->nrbufs) {
65793 - if (!pipe->writers)
65794 + if (!atomic_read(&pipe->writers))
65795 return 0;
65796
65797 - if (!pipe->waiting_writers && sd->num_spliced)
65798 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
65799 return 0;
65800
65801 if (sd->flags & SPLICE_F_NONBLOCK)
65802 @@ -1189,7 +1189,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
65803 * out of the pipe right after the splice_to_pipe(). So set
65804 * PIPE_READERS appropriately.
65805 */
65806 - pipe->readers = 1;
65807 + atomic_set(&pipe->readers, 1);
65808
65809 current->splice_pipe = pipe;
65810 }
65811 @@ -1485,6 +1485,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
65812
65813 partial[buffers].offset = off;
65814 partial[buffers].len = plen;
65815 + partial[buffers].private = 0;
65816
65817 off = 0;
65818 len -= plen;
65819 @@ -1721,9 +1722,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65820 ret = -ERESTARTSYS;
65821 break;
65822 }
65823 - if (!pipe->writers)
65824 + if (!atomic_read(&pipe->writers))
65825 break;
65826 - if (!pipe->waiting_writers) {
65827 + if (!atomic_read(&pipe->waiting_writers)) {
65828 if (flags & SPLICE_F_NONBLOCK) {
65829 ret = -EAGAIN;
65830 break;
65831 @@ -1755,7 +1756,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65832 pipe_lock(pipe);
65833
65834 while (pipe->nrbufs >= pipe->buffers) {
65835 - if (!pipe->readers) {
65836 + if (!atomic_read(&pipe->readers)) {
65837 send_sig(SIGPIPE, current, 0);
65838 ret = -EPIPE;
65839 break;
65840 @@ -1768,9 +1769,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65841 ret = -ERESTARTSYS;
65842 break;
65843 }
65844 - pipe->waiting_writers++;
65845 + atomic_inc(&pipe->waiting_writers);
65846 pipe_wait(pipe);
65847 - pipe->waiting_writers--;
65848 + atomic_dec(&pipe->waiting_writers);
65849 }
65850
65851 pipe_unlock(pipe);
65852 @@ -1806,14 +1807,14 @@ retry:
65853 pipe_double_lock(ipipe, opipe);
65854
65855 do {
65856 - if (!opipe->readers) {
65857 + if (!atomic_read(&opipe->readers)) {
65858 send_sig(SIGPIPE, current, 0);
65859 if (!ret)
65860 ret = -EPIPE;
65861 break;
65862 }
65863
65864 - if (!ipipe->nrbufs && !ipipe->writers)
65865 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
65866 break;
65867
65868 /*
65869 @@ -1910,7 +1911,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
65870 pipe_double_lock(ipipe, opipe);
65871
65872 do {
65873 - if (!opipe->readers) {
65874 + if (!atomic_read(&opipe->readers)) {
65875 send_sig(SIGPIPE, current, 0);
65876 if (!ret)
65877 ret = -EPIPE;
65878 @@ -1955,7 +1956,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
65879 * return EAGAIN if we have the potential of some data in the
65880 * future, otherwise just return 0
65881 */
65882 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
65883 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
65884 ret = -EAGAIN;
65885
65886 pipe_unlock(ipipe);
65887 diff --git a/fs/stat.c b/fs/stat.c
65888 index ae0c3ce..9ee641c 100644
65889 --- a/fs/stat.c
65890 +++ b/fs/stat.c
65891 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
65892 stat->gid = inode->i_gid;
65893 stat->rdev = inode->i_rdev;
65894 stat->size = i_size_read(inode);
65895 - stat->atime = inode->i_atime;
65896 - stat->mtime = inode->i_mtime;
65897 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
65898 + stat->atime = inode->i_ctime;
65899 + stat->mtime = inode->i_ctime;
65900 + } else {
65901 + stat->atime = inode->i_atime;
65902 + stat->mtime = inode->i_mtime;
65903 + }
65904 stat->ctime = inode->i_ctime;
65905 stat->blksize = (1 << inode->i_blkbits);
65906 stat->blocks = inode->i_blocks;
65907 @@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
65908 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
65909 {
65910 struct inode *inode = path->dentry->d_inode;
65911 + int retval;
65912
65913 - if (inode->i_op->getattr)
65914 - return inode->i_op->getattr(path->mnt, path->dentry, stat);
65915 + if (inode->i_op->getattr) {
65916 + retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
65917 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
65918 + stat->atime = stat->ctime;
65919 + stat->mtime = stat->ctime;
65920 + }
65921 + return retval;
65922 + }
65923
65924 generic_fillattr(inode, stat);
65925 return 0;
65926 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
65927 index 0b45ff4..847de5b 100644
65928 --- a/fs/sysfs/dir.c
65929 +++ b/fs/sysfs/dir.c
65930 @@ -41,9 +41,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
65931 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
65932 {
65933 struct kernfs_node *parent, *kn;
65934 + const char *name;
65935 + umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
65936 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
65937 + const char *parent_name;
65938 +#endif
65939
65940 BUG_ON(!kobj);
65941
65942 + name = kobject_name(kobj);
65943 +
65944 if (kobj->parent)
65945 parent = kobj->parent->sd;
65946 else
65947 @@ -52,11 +59,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
65948 if (!parent)
65949 return -ENOENT;
65950
65951 - kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
65952 - S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
65953 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
65954 + parent_name = parent->name;
65955 + mode = S_IRWXU;
65956 +
65957 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
65958 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
65959 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
65960 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
65961 + mode = S_IRWXU | S_IRUGO | S_IXUGO;
65962 +#endif
65963 +
65964 + kn = kernfs_create_dir_ns(parent, name,
65965 + mode, kobj, ns);
65966 if (IS_ERR(kn)) {
65967 if (PTR_ERR(kn) == -EEXIST)
65968 - sysfs_warn_dup(parent, kobject_name(kobj));
65969 + sysfs_warn_dup(parent, name);
65970 return PTR_ERR(kn);
65971 }
65972
65973 diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
65974 index 69d4889..a810bd4 100644
65975 --- a/fs/sysv/sysv.h
65976 +++ b/fs/sysv/sysv.h
65977 @@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
65978 #endif
65979 }
65980
65981 -static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
65982 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
65983 {
65984 if (sbi->s_bytesex == BYTESEX_PDP)
65985 return PDP_swab((__force __u32)n);
65986 diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
65987 index e18b988..f1d4ad0f 100644
65988 --- a/fs/ubifs/io.c
65989 +++ b/fs/ubifs/io.c
65990 @@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
65991 return err;
65992 }
65993
65994 -int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
65995 +int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
65996 {
65997 int err;
65998
65999 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
66000 index c175b4d..8f36a16 100644
66001 --- a/fs/udf/misc.c
66002 +++ b/fs/udf/misc.c
66003 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
66004
66005 u8 udf_tag_checksum(const struct tag *t)
66006 {
66007 - u8 *data = (u8 *)t;
66008 + const u8 *data = (const u8 *)t;
66009 u8 checksum = 0;
66010 int i;
66011 for (i = 0; i < sizeof(struct tag); ++i)
66012 diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
66013 index 8d974c4..b82f6ec 100644
66014 --- a/fs/ufs/swab.h
66015 +++ b/fs/ufs/swab.h
66016 @@ -22,7 +22,7 @@ enum {
66017 BYTESEX_BE
66018 };
66019
66020 -static inline u64
66021 +static inline u64 __intentional_overflow(-1)
66022 fs64_to_cpu(struct super_block *sbp, __fs64 n)
66023 {
66024 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
66025 @@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
66026 return (__force __fs64)cpu_to_be64(n);
66027 }
66028
66029 -static inline u32
66030 +static inline u32 __intentional_overflow(-1)
66031 fs32_to_cpu(struct super_block *sbp, __fs32 n)
66032 {
66033 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
66034 diff --git a/fs/utimes.c b/fs/utimes.c
66035 index aa138d6..5f3a811 100644
66036 --- a/fs/utimes.c
66037 +++ b/fs/utimes.c
66038 @@ -1,6 +1,7 @@
66039 #include <linux/compiler.h>
66040 #include <linux/file.h>
66041 #include <linux/fs.h>
66042 +#include <linux/security.h>
66043 #include <linux/linkage.h>
66044 #include <linux/mount.h>
66045 #include <linux/namei.h>
66046 @@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
66047 }
66048 }
66049 retry_deleg:
66050 +
66051 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
66052 + error = -EACCES;
66053 + goto mnt_drop_write_and_out;
66054 + }
66055 +
66056 mutex_lock(&inode->i_mutex);
66057 error = notify_change(path->dentry, &newattrs, &delegated_inode);
66058 mutex_unlock(&inode->i_mutex);
66059 diff --git a/fs/xattr.c b/fs/xattr.c
66060 index 3377dff..f394815 100644
66061 --- a/fs/xattr.c
66062 +++ b/fs/xattr.c
66063 @@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
66064 return rc;
66065 }
66066
66067 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
66068 +ssize_t
66069 +pax_getxattr(struct dentry *dentry, void *value, size_t size)
66070 +{
66071 + struct inode *inode = dentry->d_inode;
66072 + ssize_t error;
66073 +
66074 + error = inode_permission(inode, MAY_EXEC);
66075 + if (error)
66076 + return error;
66077 +
66078 + if (inode->i_op->getxattr)
66079 + error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
66080 + else
66081 + error = -EOPNOTSUPP;
66082 +
66083 + return error;
66084 +}
66085 +EXPORT_SYMBOL(pax_getxattr);
66086 +#endif
66087 +
66088 ssize_t
66089 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
66090 {
66091 @@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
66092 * Extended attribute SET operations
66093 */
66094 static long
66095 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
66096 +setxattr(struct path *path, const char __user *name, const void __user *value,
66097 size_t size, int flags)
66098 {
66099 int error;
66100 @@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
66101 posix_acl_fix_xattr_from_user(kvalue, size);
66102 }
66103
66104 - error = vfs_setxattr(d, kname, kvalue, size, flags);
66105 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
66106 + error = -EACCES;
66107 + goto out;
66108 + }
66109 +
66110 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
66111 out:
66112 if (vvalue)
66113 vfree(vvalue);
66114 @@ -377,7 +403,7 @@ retry:
66115 return error;
66116 error = mnt_want_write(path.mnt);
66117 if (!error) {
66118 - error = setxattr(path.dentry, name, value, size, flags);
66119 + error = setxattr(&path, name, value, size, flags);
66120 mnt_drop_write(path.mnt);
66121 }
66122 path_put(&path);
66123 @@ -401,7 +427,7 @@ retry:
66124 return error;
66125 error = mnt_want_write(path.mnt);
66126 if (!error) {
66127 - error = setxattr(path.dentry, name, value, size, flags);
66128 + error = setxattr(&path, name, value, size, flags);
66129 mnt_drop_write(path.mnt);
66130 }
66131 path_put(&path);
66132 @@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
66133 const void __user *,value, size_t, size, int, flags)
66134 {
66135 struct fd f = fdget(fd);
66136 - struct dentry *dentry;
66137 int error = -EBADF;
66138
66139 if (!f.file)
66140 return error;
66141 - dentry = f.file->f_path.dentry;
66142 - audit_inode(NULL, dentry, 0);
66143 + audit_inode(NULL, f.file->f_path.dentry, 0);
66144 error = mnt_want_write_file(f.file);
66145 if (!error) {
66146 - error = setxattr(dentry, name, value, size, flags);
66147 + error = setxattr(&f.file->f_path, name, value, size, flags);
66148 mnt_drop_write_file(f.file);
66149 }
66150 fdput(f);
66151 @@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
66152 * Extended attribute REMOVE operations
66153 */
66154 static long
66155 -removexattr(struct dentry *d, const char __user *name)
66156 +removexattr(struct path *path, const char __user *name)
66157 {
66158 int error;
66159 char kname[XATTR_NAME_MAX + 1];
66160 @@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
66161 if (error < 0)
66162 return error;
66163
66164 - return vfs_removexattr(d, kname);
66165 + if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
66166 + return -EACCES;
66167 +
66168 + return vfs_removexattr(path->dentry, kname);
66169 }
66170
66171 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
66172 @@ -652,7 +679,7 @@ retry:
66173 return error;
66174 error = mnt_want_write(path.mnt);
66175 if (!error) {
66176 - error = removexattr(path.dentry, name);
66177 + error = removexattr(&path, name);
66178 mnt_drop_write(path.mnt);
66179 }
66180 path_put(&path);
66181 @@ -675,7 +702,7 @@ retry:
66182 return error;
66183 error = mnt_want_write(path.mnt);
66184 if (!error) {
66185 - error = removexattr(path.dentry, name);
66186 + error = removexattr(&path, name);
66187 mnt_drop_write(path.mnt);
66188 }
66189 path_put(&path);
66190 @@ -689,16 +716,16 @@ retry:
66191 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
66192 {
66193 struct fd f = fdget(fd);
66194 - struct dentry *dentry;
66195 + struct path *path;
66196 int error = -EBADF;
66197
66198 if (!f.file)
66199 return error;
66200 - dentry = f.file->f_path.dentry;
66201 - audit_inode(NULL, dentry, 0);
66202 + path = &f.file->f_path;
66203 + audit_inode(NULL, path->dentry, 0);
66204 error = mnt_want_write_file(f.file);
66205 if (!error) {
66206 - error = removexattr(dentry, name);
66207 + error = removexattr(path, name);
66208 mnt_drop_write_file(f.file);
66209 }
66210 fdput(f);
66211 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
66212 index f0efc7e..ba72910 100644
66213 --- a/fs/xfs/xfs_bmap.c
66214 +++ b/fs/xfs/xfs_bmap.c
66215 @@ -584,7 +584,7 @@ xfs_bmap_validate_ret(
66216
66217 #else
66218 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
66219 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
66220 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
66221 #endif /* DEBUG */
66222
66223 /*
66224 diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
66225 index aead369..0dfecfd 100644
66226 --- a/fs/xfs/xfs_dir2_readdir.c
66227 +++ b/fs/xfs/xfs_dir2_readdir.c
66228 @@ -160,7 +160,12 @@ xfs_dir2_sf_getdents(
66229 ino = dp->d_ops->sf_get_ino(sfp, sfep);
66230 filetype = dp->d_ops->sf_get_ftype(sfep);
66231 ctx->pos = off & 0x7fffffff;
66232 - if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
66233 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
66234 + char name[sfep->namelen];
66235 + memcpy(name, sfep->name, sfep->namelen);
66236 + if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(mp, filetype)))
66237 + return 0;
66238 + } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
66239 xfs_dir3_get_dtype(mp, filetype)))
66240 return 0;
66241 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
66242 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
66243 index 6152cbe..f0f9eaa 100644
66244 --- a/fs/xfs/xfs_ioctl.c
66245 +++ b/fs/xfs/xfs_ioctl.c
66246 @@ -122,7 +122,7 @@ xfs_find_handle(
66247 }
66248
66249 error = -EFAULT;
66250 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
66251 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
66252 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
66253 goto out_put;
66254
66255 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
66256 new file mode 100644
66257 index 0000000..27cec32
66258 --- /dev/null
66259 +++ b/grsecurity/Kconfig
66260 @@ -0,0 +1,1166 @@
66261 +#
66262 +# grecurity configuration
66263 +#
66264 +menu "Memory Protections"
66265 +depends on GRKERNSEC
66266 +
66267 +config GRKERNSEC_KMEM
66268 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
66269 + default y if GRKERNSEC_CONFIG_AUTO
66270 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
66271 + help
66272 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
66273 + be written to or read from to modify or leak the contents of the running
66274 + kernel. /dev/port will also not be allowed to be opened, writing to
66275 + /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
66276 + If you have module support disabled, enabling this will close up several
66277 + ways that are currently used to insert malicious code into the running
66278 + kernel.
66279 +
66280 + Even with this feature enabled, we still highly recommend that
66281 + you use the RBAC system, as it is still possible for an attacker to
66282 + modify the running kernel through other more obscure methods.
66283 +
66284 + It is highly recommended that you say Y here if you meet all the
66285 + conditions above.
66286 +
66287 +config GRKERNSEC_VM86
66288 + bool "Restrict VM86 mode"
66289 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
66290 + depends on X86_32
66291 +
66292 + help
66293 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
66294 + make use of a special execution mode on 32bit x86 processors called
66295 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
66296 + video cards and will still work with this option enabled. The purpose
66297 + of the option is to prevent exploitation of emulation errors in
66298 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
66299 + Nearly all users should be able to enable this option.
66300 +
66301 +config GRKERNSEC_IO
66302 + bool "Disable privileged I/O"
66303 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
66304 + depends on X86
66305 + select RTC_CLASS
66306 + select RTC_INTF_DEV
66307 + select RTC_DRV_CMOS
66308 +
66309 + help
66310 + If you say Y here, all ioperm and iopl calls will return an error.
66311 + Ioperm and iopl can be used to modify the running kernel.
66312 + Unfortunately, some programs need this access to operate properly,
66313 + the most notable of which are XFree86 and hwclock. hwclock can be
66314 + remedied by having RTC support in the kernel, so real-time
66315 + clock support is enabled if this option is enabled, to ensure
66316 + that hwclock operates correctly. If hwclock still does not work,
66317 + either update udev or symlink /dev/rtc to /dev/rtc0.
66318 +
66319 + If you're using XFree86 or a version of Xorg from 2012 or earlier,
66320 + you may not be able to boot into a graphical environment with this
66321 + option enabled. In this case, you should use the RBAC system instead.
66322 +
66323 +config GRKERNSEC_JIT_HARDEN
66324 + bool "Harden BPF JIT against spray attacks"
66325 + default y if GRKERNSEC_CONFIG_AUTO
66326 + depends on BPF_JIT && X86
66327 + help
66328 + If you say Y here, the native code generated by the kernel's Berkeley
66329 + Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
66330 + attacks that attempt to fit attacker-beneficial instructions in
66331 + 32bit immediate fields of JIT-generated native instructions. The
66332 + attacker will generally aim to cause an unintended instruction sequence
66333 + of JIT-generated native code to execute by jumping into the middle of
66334 + a generated instruction. This feature effectively randomizes the 32bit
66335 + immediate constants present in the generated code to thwart such attacks.
66336 +
66337 + If you're using KERNEXEC, it's recommended that you enable this option
66338 + to supplement the hardening of the kernel.
66339 +
66340 +config GRKERNSEC_PERF_HARDEN
66341 + bool "Disable unprivileged PERF_EVENTS usage by default"
66342 + default y if GRKERNSEC_CONFIG_AUTO
66343 + depends on PERF_EVENTS
66344 + help
66345 + If you say Y here, the range of acceptable values for the
66346 + /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
66347 + default to a new value: 3. When the sysctl is set to this value, no
66348 + unprivileged use of the PERF_EVENTS syscall interface will be permitted.
66349 +
66350 + Though PERF_EVENTS can be used legitimately for performance monitoring
66351 + and low-level application profiling, it is forced on regardless of
66352 + configuration, has been at fault for several vulnerabilities, and
66353 + creates new opportunities for side channels and other information leaks.
66354 +
66355 + This feature puts PERF_EVENTS into a secure default state and permits
66356 + the administrator to change out of it temporarily if unprivileged
66357 + application profiling is needed.
66358 +
66359 +config GRKERNSEC_RAND_THREADSTACK
66360 + bool "Insert random gaps between thread stacks"
66361 + default y if GRKERNSEC_CONFIG_AUTO
66362 + depends on PAX_RANDMMAP && !PPC
66363 + help
66364 + If you say Y here, a random-sized gap will be enforced between allocated
66365 + thread stacks. Glibc's NPTL and other threading libraries that
66366 + pass MAP_STACK to the kernel for thread stack allocation are supported.
66367 + The implementation currently provides 8 bits of entropy for the gap.
66368 +
66369 + Many distributions do not compile threaded remote services with the
66370 + -fstack-check argument to GCC, causing the variable-sized stack-based
66371 + allocator, alloca(), to not probe the stack on allocation. This
66372 + permits an unbounded alloca() to skip over any guard page and potentially
66373 + modify another thread's stack reliably. An enforced random gap
66374 + reduces the reliability of such an attack and increases the chance
66375 + that such a read/write to another thread's stack instead lands in
66376 + an unmapped area, causing a crash and triggering grsecurity's
66377 + anti-bruteforcing logic.
66378 +
66379 +config GRKERNSEC_PROC_MEMMAP
66380 + bool "Harden ASLR against information leaks and entropy reduction"
66381 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
66382 + depends on PAX_NOEXEC || PAX_ASLR
66383 + help
66384 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
66385 + give no information about the addresses of its mappings if
66386 + PaX features that rely on random addresses are enabled on the task.
66387 + In addition to sanitizing this information and disabling other
66388 + dangerous sources of information, this option causes reads of sensitive
66389 + /proc/<pid> entries where the file descriptor was opened in a different
66390 + task than the one performing the read. Such attempts are logged.
66391 + This option also limits argv/env strings for suid/sgid binaries
66392 + to 512KB to prevent a complete exhaustion of the stack entropy provided
66393 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
66394 + binaries to prevent alternative mmap layouts from being abused.
66395 +
66396 + If you use PaX it is essential that you say Y here as it closes up
66397 + several holes that make full ASLR useless locally.
66398 +
66399 +
66400 +config GRKERNSEC_KSTACKOVERFLOW
66401 + bool "Prevent kernel stack overflows"
66402 + default y if GRKERNSEC_CONFIG_AUTO
66403 + depends on !IA64 && 64BIT
66404 + help
66405 + If you say Y here, the kernel's process stacks will be allocated
66406 + with vmalloc instead of the kernel's default allocator. This
66407 + introduces guard pages that in combination with the alloca checking
66408 + of the STACKLEAK feature prevents all forms of kernel process stack
66409 + overflow abuse. Note that this is different from kernel stack
66410 + buffer overflows.
66411 +
66412 +config GRKERNSEC_BRUTE
66413 + bool "Deter exploit bruteforcing"
66414 + default y if GRKERNSEC_CONFIG_AUTO
66415 + help
66416 + If you say Y here, attempts to bruteforce exploits against forking
66417 + daemons such as apache or sshd, as well as against suid/sgid binaries
66418 + will be deterred. When a child of a forking daemon is killed by PaX
66419 + or crashes due to an illegal instruction or other suspicious signal,
66420 + the parent process will be delayed 30 seconds upon every subsequent
66421 + fork until the administrator is able to assess the situation and
66422 + restart the daemon.
66423 + In the suid/sgid case, the attempt is logged, the user has all their
66424 + existing instances of the suid/sgid binary terminated and will
66425 + be unable to execute any suid/sgid binaries for 15 minutes.
66426 +
66427 + It is recommended that you also enable signal logging in the auditing
66428 + section so that logs are generated when a process triggers a suspicious
66429 + signal.
66430 + If the sysctl option is enabled, a sysctl option with name
66431 + "deter_bruteforce" is created.
66432 +
66433 +config GRKERNSEC_MODHARDEN
66434 + bool "Harden module auto-loading"
66435 + default y if GRKERNSEC_CONFIG_AUTO
66436 + depends on MODULES
66437 + help
66438 + If you say Y here, module auto-loading in response to use of some
66439 + feature implemented by an unloaded module will be restricted to
66440 + root users. Enabling this option helps defend against attacks
66441 + by unprivileged users who abuse the auto-loading behavior to
66442 + cause a vulnerable module to load that is then exploited.
66443 +
66444 + If this option prevents a legitimate use of auto-loading for a
66445 + non-root user, the administrator can execute modprobe manually
66446 + with the exact name of the module mentioned in the alert log.
66447 + Alternatively, the administrator can add the module to the list
66448 + of modules loaded at boot by modifying init scripts.
66449 +
66450 + Modification of init scripts will most likely be needed on
66451 + Ubuntu servers with encrypted home directory support enabled,
66452 + as the first non-root user logging in will cause the ecb(aes),
66453 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
66454 +
66455 +config GRKERNSEC_HIDESYM
66456 + bool "Hide kernel symbols"
66457 + default y if GRKERNSEC_CONFIG_AUTO
66458 + select PAX_USERCOPY_SLABS
66459 + help
66460 + If you say Y here, getting information on loaded modules, and
66461 + displaying all kernel symbols through a syscall will be restricted
66462 + to users with CAP_SYS_MODULE. For software compatibility reasons,
66463 + /proc/kallsyms will be restricted to the root user. The RBAC
66464 + system can hide that entry even from root.
66465 +
66466 + This option also prevents leaking of kernel addresses through
66467 + several /proc entries.
66468 +
66469 + Note that this option is only effective provided the following
66470 + conditions are met:
66471 + 1) The kernel using grsecurity is not precompiled by some distribution
66472 + 2) You have also enabled GRKERNSEC_DMESG
66473 + 3) You are using the RBAC system and hiding other files such as your
66474 + kernel image and System.map. Alternatively, enabling this option
66475 + causes the permissions on /boot, /lib/modules, and the kernel
66476 + source directory to change at compile time to prevent
66477 + reading by non-root users.
66478 + If the above conditions are met, this option will aid in providing a
66479 + useful protection against local kernel exploitation of overflows
66480 + and arbitrary read/write vulnerabilities.
66481 +
66482 + It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
66483 + in addition to this feature.
66484 +
66485 +config GRKERNSEC_RANDSTRUCT
66486 + bool "Randomize layout of sensitive kernel structures"
66487 + default y if GRKERNSEC_CONFIG_AUTO
66488 + select GRKERNSEC_HIDESYM
66489 + select MODVERSIONS if MODULES
66490 + help
66491 + If you say Y here, the layouts of a number of sensitive kernel
66492 + structures (task, fs, cred, etc) and all structures composed entirely
66493 + of function pointers (aka "ops" structs) will be randomized at compile-time.
66494 + This can introduce the requirement of an additional infoleak
66495 + vulnerability for exploits targeting these structure types.
66496 +
66497 + Enabling this feature will introduce some performance impact, slightly
66498 + increase memory usage, and prevent the use of forensic tools like
66499 + Volatility against the system (unless the kernel source tree isn't
66500 + cleaned after kernel installation).
66501 +
66502 + The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
66503 + It remains after a make clean to allow for external modules to be compiled
66504 + with the existing seed and will be removed by a make mrproper or
66505 + make distclean.
66506 +
66507 + Note that the implementation requires gcc 4.6.4. or newer. You may need
66508 + to install the supporting headers explicitly in addition to the normal
66509 + gcc package.
66510 +
66511 +config GRKERNSEC_RANDSTRUCT_PERFORMANCE
66512 + bool "Use cacheline-aware structure randomization"
66513 + depends on GRKERNSEC_RANDSTRUCT
66514 + default y if GRKERNSEC_CONFIG_PRIORITY_PERF
66515 + help
66516 + If you say Y here, the RANDSTRUCT randomization will make a best effort
66517 + at restricting randomization to cacheline-sized groups of elements. It
66518 + will further not randomize bitfields in structures. This reduces the
66519 + performance hit of RANDSTRUCT at the cost of weakened randomization.
66520 +
66521 +config GRKERNSEC_KERN_LOCKOUT
66522 + bool "Active kernel exploit response"
66523 + default y if GRKERNSEC_CONFIG_AUTO
66524 + depends on X86 || ARM || PPC || SPARC
66525 + help
66526 + If you say Y here, when a PaX alert is triggered due to suspicious
66527 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
66528 + or an OOPS occurs due to bad memory accesses, instead of just
66529 + terminating the offending process (and potentially allowing
66530 + a subsequent exploit from the same user), we will take one of two
66531 + actions:
66532 + If the user was root, we will panic the system
66533 + If the user was non-root, we will log the attempt, terminate
66534 + all processes owned by the user, then prevent them from creating
66535 + any new processes until the system is restarted
66536 + This deters repeated kernel exploitation/bruteforcing attempts
66537 + and is useful for later forensics.
66538 +
66539 +config GRKERNSEC_OLD_ARM_USERLAND
66540 + bool "Old ARM userland compatibility"
66541 + depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
66542 + help
66543 + If you say Y here, stubs of executable code to perform such operations
66544 + as "compare-exchange" will be placed at fixed locations in the ARM vector
66545 + table. This is unfortunately needed for old ARM userland meant to run
66546 + across a wide range of processors. Without this option enabled,
66547 + the get_tls and data memory barrier stubs will be emulated by the kernel,
66548 + which is enough for Linaro userlands or other userlands designed for v6
66549 + and newer ARM CPUs. It's recommended that you try without this option enabled
66550 + first, and only enable it if your userland does not boot (it will likely fail
66551 + at init time).
66552 +
66553 +endmenu
66554 +menu "Role Based Access Control Options"
66555 +depends on GRKERNSEC
66556 +
66557 +config GRKERNSEC_RBAC_DEBUG
66558 + bool
66559 +
66560 +config GRKERNSEC_NO_RBAC
66561 + bool "Disable RBAC system"
66562 + help
66563 + If you say Y here, the /dev/grsec device will be removed from the kernel,
66564 + preventing the RBAC system from being enabled. You should only say Y
66565 + here if you have no intention of using the RBAC system, so as to prevent
66566 + an attacker with root access from misusing the RBAC system to hide files
66567 + and processes when loadable module support and /dev/[k]mem have been
66568 + locked down.
66569 +
66570 +config GRKERNSEC_ACL_HIDEKERN
66571 + bool "Hide kernel processes"
66572 + help
66573 + If you say Y here, all kernel threads will be hidden to all
66574 + processes but those whose subject has the "view hidden processes"
66575 + flag.
66576 +
66577 +config GRKERNSEC_ACL_MAXTRIES
66578 + int "Maximum tries before password lockout"
66579 + default 3
66580 + help
66581 + This option enforces the maximum number of times a user can attempt
66582 + to authorize themselves with the grsecurity RBAC system before being
66583 + denied the ability to attempt authorization again for a specified time.
66584 + The lower the number, the harder it will be to brute-force a password.
66585 +
66586 +config GRKERNSEC_ACL_TIMEOUT
66587 + int "Time to wait after max password tries, in seconds"
66588 + default 30
66589 + help
66590 + This option specifies the time the user must wait after attempting to
66591 + authorize to the RBAC system with the maximum number of invalid
66592 + passwords. The higher the number, the harder it will be to brute-force
66593 + a password.
66594 +
66595 +endmenu
66596 +menu "Filesystem Protections"
66597 +depends on GRKERNSEC
66598 +
66599 +config GRKERNSEC_PROC
66600 + bool "Proc restrictions"
66601 + default y if GRKERNSEC_CONFIG_AUTO
66602 + help
66603 + If you say Y here, the permissions of the /proc filesystem
66604 + will be altered to enhance system security and privacy. You MUST
66605 + choose either a user only restriction or a user and group restriction.
66606 + Depending upon the option you choose, you can either restrict users to
66607 + see only the processes they themselves run, or choose a group that can
66608 + view all processes and files normally restricted to root if you choose
66609 + the "restrict to user only" option. NOTE: If you're running identd or
66610 + ntpd as a non-root user, you will have to run it as the group you
66611 + specify here.
66612 +
66613 +config GRKERNSEC_PROC_USER
66614 + bool "Restrict /proc to user only"
66615 + depends on GRKERNSEC_PROC
66616 + help
66617 + If you say Y here, non-root users will only be able to view their own
66618 + processes, and restricts them from viewing network-related information,
66619 + and viewing kernel symbol and module information.
66620 +
66621 +config GRKERNSEC_PROC_USERGROUP
66622 + bool "Allow special group"
66623 + default y if GRKERNSEC_CONFIG_AUTO
66624 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
66625 + help
66626 + If you say Y here, you will be able to select a group that will be
66627 + able to view all processes and network-related information. If you've
66628 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
66629 + remain hidden. This option is useful if you want to run identd as
66630 + a non-root user. The group you select may also be chosen at boot time
66631 + via "grsec_proc_gid=" on the kernel commandline.
66632 +
66633 +config GRKERNSEC_PROC_GID
66634 + int "GID for special group"
66635 + depends on GRKERNSEC_PROC_USERGROUP
66636 + default 1001
66637 +
66638 +config GRKERNSEC_PROC_ADD
66639 + bool "Additional restrictions"
66640 + default y if GRKERNSEC_CONFIG_AUTO
66641 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
66642 + help
66643 + If you say Y here, additional restrictions will be placed on
66644 + /proc that keep normal users from viewing device information and
66645 + slabinfo information that could be useful for exploits.
66646 +
66647 +config GRKERNSEC_LINK
66648 + bool "Linking restrictions"
66649 + default y if GRKERNSEC_CONFIG_AUTO
66650 + help
66651 + If you say Y here, /tmp race exploits will be prevented, since users
66652 + will no longer be able to follow symlinks owned by other users in
66653 + world-writable +t directories (e.g. /tmp), unless the owner of the
66654 + symlink is the owner of the directory. users will also not be
66655 + able to hardlink to files they do not own. If the sysctl option is
66656 + enabled, a sysctl option with name "linking_restrictions" is created.
66657 +
66658 +config GRKERNSEC_SYMLINKOWN
66659 + bool "Kernel-enforced SymlinksIfOwnerMatch"
66660 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
66661 + help
66662 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
66663 + that prevents it from being used as a security feature. As Apache
66664 + verifies the symlink by performing a stat() against the target of
66665 + the symlink before it is followed, an attacker can setup a symlink
66666 + to point to a same-owned file, then replace the symlink with one
66667 + that targets another user's file just after Apache "validates" the
66668 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
66669 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
66670 + will be in place for the group you specify. If the sysctl option
66671 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
66672 + created.
66673 +
66674 +config GRKERNSEC_SYMLINKOWN_GID
66675 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
66676 + depends on GRKERNSEC_SYMLINKOWN
66677 + default 1006
66678 + help
66679 + Setting this GID determines what group kernel-enforced
66680 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
66681 + is enabled, a sysctl option with name "symlinkown_gid" is created.
66682 +
66683 +config GRKERNSEC_FIFO
66684 + bool "FIFO restrictions"
66685 + default y if GRKERNSEC_CONFIG_AUTO
66686 + help
66687 + If you say Y here, users will not be able to write to FIFOs they don't
66688 + own in world-writable +t directories (e.g. /tmp), unless the owner of
66689 + the FIFO is the same owner of the directory it's held in. If the sysctl
66690 + option is enabled, a sysctl option with name "fifo_restrictions" is
66691 + created.
66692 +
66693 +config GRKERNSEC_SYSFS_RESTRICT
66694 + bool "Sysfs/debugfs restriction"
66695 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
66696 + depends on SYSFS
66697 + help
66698 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
66699 + any filesystem normally mounted under it (e.g. debugfs) will be
66700 + mostly accessible only by root. These filesystems generally provide access
66701 + to hardware and debug information that isn't appropriate for unprivileged
66702 + users of the system. Sysfs and debugfs have also become a large source
66703 + of new vulnerabilities, ranging from infoleaks to local compromise.
66704 + There has been very little oversight with an eye toward security involved
66705 + in adding new exporters of information to these filesystems, so their
66706 + use is discouraged.
66707 + For reasons of compatibility, a few directories have been whitelisted
66708 + for access by non-root users:
66709 + /sys/fs/selinux
66710 + /sys/fs/fuse
66711 + /sys/devices/system/cpu
66712 +
66713 +config GRKERNSEC_ROFS
66714 + bool "Runtime read-only mount protection"
66715 + depends on SYSCTL
66716 + help
66717 + If you say Y here, a sysctl option with name "romount_protect" will
66718 + be created. By setting this option to 1 at runtime, filesystems
66719 + will be protected in the following ways:
66720 + * No new writable mounts will be allowed
66721 + * Existing read-only mounts won't be able to be remounted read/write
66722 + * Write operations will be denied on all block devices
66723 + This option acts independently of grsec_lock: once it is set to 1,
66724 + it cannot be turned off. Therefore, please be mindful of the resulting
66725 + behavior if this option is enabled in an init script on a read-only
66726 + filesystem.
66727 + Also be aware that as with other root-focused features, GRKERNSEC_KMEM
66728 + and GRKERNSEC_IO should be enabled and module loading disabled via
66729 + config or at runtime.
66730 + This feature is mainly intended for secure embedded systems.
66731 +
66732 +
66733 +config GRKERNSEC_DEVICE_SIDECHANNEL
66734 + bool "Eliminate stat/notify-based device sidechannels"
66735 + default y if GRKERNSEC_CONFIG_AUTO
66736 + help
66737 + If you say Y here, timing analyses on block or character
66738 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
66739 + will be thwarted for unprivileged users. If a process without
66740 + CAP_MKNOD stats such a device, the last access and last modify times
66741 + will match the device's create time. No access or modify events
66742 + will be triggered through inotify/dnotify/fanotify for such devices.
66743 + This feature will prevent attacks that may at a minimum
66744 + allow an attacker to determine the administrator's password length.
66745 +
66746 +config GRKERNSEC_CHROOT
66747 + bool "Chroot jail restrictions"
66748 + default y if GRKERNSEC_CONFIG_AUTO
66749 + help
66750 + If you say Y here, you will be able to choose several options that will
66751 + make breaking out of a chrooted jail much more difficult. If you
66752 + encounter no software incompatibilities with the following options, it
66753 + is recommended that you enable each one.
66754 +
66755 + Note that the chroot restrictions are not intended to apply to "chroots"
66756 + to directories that are simple bind mounts of the global root filesystem.
66757 + For several other reasons, a user shouldn't expect any significant
66758 + security by performing such a chroot.
66759 +
66760 +config GRKERNSEC_CHROOT_MOUNT
66761 + bool "Deny mounts"
66762 + default y if GRKERNSEC_CONFIG_AUTO
66763 + depends on GRKERNSEC_CHROOT
66764 + help
66765 + If you say Y here, processes inside a chroot will not be able to
66766 + mount or remount filesystems. If the sysctl option is enabled, a
66767 + sysctl option with name "chroot_deny_mount" is created.
66768 +
66769 +config GRKERNSEC_CHROOT_DOUBLE
66770 + bool "Deny double-chroots"
66771 + default y if GRKERNSEC_CONFIG_AUTO
66772 + depends on GRKERNSEC_CHROOT
66773 + help
66774 + If you say Y here, processes inside a chroot will not be able to chroot
66775 + again outside the chroot. This is a widely used method of breaking
66776 + out of a chroot jail and should not be allowed. If the sysctl
66777 + option is enabled, a sysctl option with name
66778 + "chroot_deny_chroot" is created.
66779 +
66780 +config GRKERNSEC_CHROOT_PIVOT
66781 + bool "Deny pivot_root in chroot"
66782 + default y if GRKERNSEC_CONFIG_AUTO
66783 + depends on GRKERNSEC_CHROOT
66784 + help
66785 + If you say Y here, processes inside a chroot will not be able to use
66786 + a function called pivot_root() that was introduced in Linux 2.3.41. It
66787 + works similar to chroot in that it changes the root filesystem. This
66788 + function could be misused in a chrooted process to attempt to break out
66789 + of the chroot, and therefore should not be allowed. If the sysctl
66790 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
66791 + created.
66792 +
66793 +config GRKERNSEC_CHROOT_CHDIR
66794 + bool "Enforce chdir(\"/\") on all chroots"
66795 + default y if GRKERNSEC_CONFIG_AUTO
66796 + depends on GRKERNSEC_CHROOT
66797 + help
66798 + If you say Y here, the current working directory of all newly-chrooted
66799 + applications will be set to the the root directory of the chroot.
66800 + The man page on chroot(2) states:
66801 + Note that this call does not change the current working
66802 + directory, so that `.' can be outside the tree rooted at
66803 + `/'. In particular, the super-user can escape from a
66804 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
66805 +
66806 + It is recommended that you say Y here, since it's not known to break
66807 + any software. If the sysctl option is enabled, a sysctl option with
66808 + name "chroot_enforce_chdir" is created.
66809 +
66810 +config GRKERNSEC_CHROOT_CHMOD
66811 + bool "Deny (f)chmod +s"
66812 + default y if GRKERNSEC_CONFIG_AUTO
66813 + depends on GRKERNSEC_CHROOT
66814 + help
66815 + If you say Y here, processes inside a chroot will not be able to chmod
66816 + or fchmod files to make them have suid or sgid bits. This protects
66817 + against another published method of breaking a chroot. If the sysctl
66818 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
66819 + created.
66820 +
66821 +config GRKERNSEC_CHROOT_FCHDIR
66822 + bool "Deny fchdir and fhandle out of chroot"
66823 + default y if GRKERNSEC_CONFIG_AUTO
66824 + depends on GRKERNSEC_CHROOT
66825 + help
66826 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
66827 + to a file descriptor of the chrooting process that points to a directory
66828 + outside the filesystem will be stopped. Additionally, this option prevents
66829 + use of the recently-created syscall for opening files by a guessable "file
66830 + handle" inside a chroot. If the sysctl option is enabled, a sysctl option
66831 + with name "chroot_deny_fchdir" is created.
66832 +
66833 +config GRKERNSEC_CHROOT_MKNOD
66834 + bool "Deny mknod"
66835 + default y if GRKERNSEC_CONFIG_AUTO
66836 + depends on GRKERNSEC_CHROOT
66837 + help
66838 + If you say Y here, processes inside a chroot will not be allowed to
66839 + mknod. The problem with using mknod inside a chroot is that it
66840 + would allow an attacker to create a device entry that is the same
66841 + as one on the physical root of your system, which could range from
66842 + anything from the console device to a device for your harddrive (which
66843 + they could then use to wipe the drive or steal data). It is recommended
66844 + that you say Y here, unless you run into software incompatibilities.
66845 + If the sysctl option is enabled, a sysctl option with name
66846 + "chroot_deny_mknod" is created.
66847 +
66848 +config GRKERNSEC_CHROOT_SHMAT
66849 + bool "Deny shmat() out of chroot"
66850 + default y if GRKERNSEC_CONFIG_AUTO
66851 + depends on GRKERNSEC_CHROOT
66852 + help
66853 + If you say Y here, processes inside a chroot will not be able to attach
66854 + to shared memory segments that were created outside of the chroot jail.
66855 + It is recommended that you say Y here. If the sysctl option is enabled,
66856 + a sysctl option with name "chroot_deny_shmat" is created.
66857 +
66858 +config GRKERNSEC_CHROOT_UNIX
66859 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
66860 + default y if GRKERNSEC_CONFIG_AUTO
66861 + depends on GRKERNSEC_CHROOT
66862 + help
66863 + If you say Y here, processes inside a chroot will not be able to
66864 + connect to abstract (meaning not belonging to a filesystem) Unix
66865 + domain sockets that were bound outside of a chroot. It is recommended
66866 + that you say Y here. If the sysctl option is enabled, a sysctl option
66867 + with name "chroot_deny_unix" is created.
66868 +
66869 +config GRKERNSEC_CHROOT_FINDTASK
66870 + bool "Protect outside processes"
66871 + default y if GRKERNSEC_CONFIG_AUTO
66872 + depends on GRKERNSEC_CHROOT
66873 + help
66874 + If you say Y here, processes inside a chroot will not be able to
66875 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
66876 + getsid, or view any process outside of the chroot. If the sysctl
66877 + option is enabled, a sysctl option with name "chroot_findtask" is
66878 + created.
66879 +
66880 +config GRKERNSEC_CHROOT_NICE
66881 + bool "Restrict priority changes"
66882 + default y if GRKERNSEC_CONFIG_AUTO
66883 + depends on GRKERNSEC_CHROOT
66884 + help
66885 + If you say Y here, processes inside a chroot will not be able to raise
66886 + the priority of processes in the chroot, or alter the priority of
66887 + processes outside the chroot. This provides more security than simply
66888 + removing CAP_SYS_NICE from the process' capability set. If the
66889 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
66890 + is created.
66891 +
66892 +config GRKERNSEC_CHROOT_SYSCTL
66893 + bool "Deny sysctl writes"
66894 + default y if GRKERNSEC_CONFIG_AUTO
66895 + depends on GRKERNSEC_CHROOT
66896 + help
66897 + If you say Y here, an attacker in a chroot will not be able to
66898 + write to sysctl entries, either by sysctl(2) or through a /proc
66899 + interface. It is strongly recommended that you say Y here. If the
66900 + sysctl option is enabled, a sysctl option with name
66901 + "chroot_deny_sysctl" is created.
66902 +
66903 +config GRKERNSEC_CHROOT_CAPS
66904 + bool "Capability restrictions"
66905 + default y if GRKERNSEC_CONFIG_AUTO
66906 + depends on GRKERNSEC_CHROOT
66907 + help
66908 + If you say Y here, the capabilities on all processes within a
66909 + chroot jail will be lowered to stop module insertion, raw i/o,
66910 + system and net admin tasks, rebooting the system, modifying immutable
66911 + files, modifying IPC owned by another, and changing the system time.
66912 + This is left an option because it can break some apps. Disable this
66913 + if your chrooted apps are having problems performing those kinds of
66914 + tasks. If the sysctl option is enabled, a sysctl option with
66915 + name "chroot_caps" is created.
66916 +
66917 +config GRKERNSEC_CHROOT_INITRD
66918 + bool "Exempt initrd tasks from restrictions"
66919 + default y if GRKERNSEC_CONFIG_AUTO
66920 + depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
66921 + help
66922 + If you say Y here, tasks started prior to init will be exempted from
66923 + grsecurity's chroot restrictions. This option is mainly meant to
66924 + resolve Plymouth's performing privileged operations unnecessarily
66925 + in a chroot.
66926 +
66927 +endmenu
66928 +menu "Kernel Auditing"
66929 +depends on GRKERNSEC
66930 +
66931 +config GRKERNSEC_AUDIT_GROUP
66932 + bool "Single group for auditing"
66933 + help
66934 + If you say Y here, the exec and chdir logging features will only operate
66935 + on a group you specify. This option is recommended if you only want to
66936 + watch certain users instead of having a large amount of logs from the
66937 + entire system. If the sysctl option is enabled, a sysctl option with
66938 + name "audit_group" is created.
66939 +
66940 +config GRKERNSEC_AUDIT_GID
66941 + int "GID for auditing"
66942 + depends on GRKERNSEC_AUDIT_GROUP
66943 + default 1007
66944 +
66945 +config GRKERNSEC_EXECLOG
66946 + bool "Exec logging"
66947 + help
66948 + If you say Y here, all execve() calls will be logged (since the
66949 + other exec*() calls are frontends to execve(), all execution
66950 + will be logged). Useful for shell-servers that like to keep track
66951 + of their users. If the sysctl option is enabled, a sysctl option with
66952 + name "exec_logging" is created.
66953 + WARNING: This option when enabled will produce a LOT of logs, especially
66954 + on an active system.
66955 +
66956 +config GRKERNSEC_RESLOG
66957 + bool "Resource logging"
66958 + default y if GRKERNSEC_CONFIG_AUTO
66959 + help
66960 + If you say Y here, all attempts to overstep resource limits will
66961 + be logged with the resource name, the requested size, and the current
66962 + limit. It is highly recommended that you say Y here. If the sysctl
66963 + option is enabled, a sysctl option with name "resource_logging" is
66964 + created. If the RBAC system is enabled, the sysctl value is ignored.
66965 +
66966 +config GRKERNSEC_CHROOT_EXECLOG
66967 + bool "Log execs within chroot"
66968 + help
66969 + If you say Y here, all executions inside a chroot jail will be logged
66970 + to syslog. This can cause a large amount of logs if certain
66971 + applications (eg. djb's daemontools) are installed on the system, and
66972 + is therefore left as an option. If the sysctl option is enabled, a
66973 + sysctl option with name "chroot_execlog" is created.
66974 +
66975 +config GRKERNSEC_AUDIT_PTRACE
66976 + bool "Ptrace logging"
66977 + help
66978 + If you say Y here, all attempts to attach to a process via ptrace
66979 + will be logged. If the sysctl option is enabled, a sysctl option
66980 + with name "audit_ptrace" is created.
66981 +
66982 +config GRKERNSEC_AUDIT_CHDIR
66983 + bool "Chdir logging"
66984 + help
66985 + If you say Y here, all chdir() calls will be logged. If the sysctl
66986 + option is enabled, a sysctl option with name "audit_chdir" is created.
66987 +
66988 +config GRKERNSEC_AUDIT_MOUNT
66989 + bool "(Un)Mount logging"
66990 + help
66991 + If you say Y here, all mounts and unmounts will be logged. If the
66992 + sysctl option is enabled, a sysctl option with name "audit_mount" is
66993 + created.
66994 +
66995 +config GRKERNSEC_SIGNAL
66996 + bool "Signal logging"
66997 + default y if GRKERNSEC_CONFIG_AUTO
66998 + help
66999 + If you say Y here, certain important signals will be logged, such as
67000 + SIGSEGV, which will as a result inform you of when a error in a program
67001 + occurred, which in some cases could mean a possible exploit attempt.
67002 + If the sysctl option is enabled, a sysctl option with name
67003 + "signal_logging" is created.
67004 +
67005 +config GRKERNSEC_FORKFAIL
67006 + bool "Fork failure logging"
67007 + help
67008 + If you say Y here, all failed fork() attempts will be logged.
67009 + This could suggest a fork bomb, or someone attempting to overstep
67010 + their process limit. If the sysctl option is enabled, a sysctl option
67011 + with name "forkfail_logging" is created.
67012 +
67013 +config GRKERNSEC_TIME
67014 + bool "Time change logging"
67015 + default y if GRKERNSEC_CONFIG_AUTO
67016 + help
67017 + If you say Y here, any changes of the system clock will be logged.
67018 + If the sysctl option is enabled, a sysctl option with name
67019 + "timechange_logging" is created.
67020 +
67021 +config GRKERNSEC_PROC_IPADDR
67022 + bool "/proc/<pid>/ipaddr support"
67023 + default y if GRKERNSEC_CONFIG_AUTO
67024 + help
67025 + If you say Y here, a new entry will be added to each /proc/<pid>
67026 + directory that contains the IP address of the person using the task.
67027 + The IP is carried across local TCP and AF_UNIX stream sockets.
67028 + This information can be useful for IDS/IPSes to perform remote response
67029 + to a local attack. The entry is readable by only the owner of the
67030 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
67031 + the RBAC system), and thus does not create privacy concerns.
67032 +
67033 +config GRKERNSEC_RWXMAP_LOG
67034 + bool 'Denied RWX mmap/mprotect logging'
67035 + default y if GRKERNSEC_CONFIG_AUTO
67036 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
67037 + help
67038 + If you say Y here, calls to mmap() and mprotect() with explicit
67039 + usage of PROT_WRITE and PROT_EXEC together will be logged when
67040 + denied by the PAX_MPROTECT feature. This feature will also
67041 + log other problematic scenarios that can occur when PAX_MPROTECT
67042 + is enabled on a binary, like textrels and PT_GNU_STACK. If the
67043 + sysctl option is enabled, a sysctl option with name "rwxmap_logging"
67044 + is created.
67045 +
67046 +endmenu
67047 +
67048 +menu "Executable Protections"
67049 +depends on GRKERNSEC
67050 +
67051 +config GRKERNSEC_DMESG
67052 + bool "Dmesg(8) restriction"
67053 + default y if GRKERNSEC_CONFIG_AUTO
67054 + help
67055 + If you say Y here, non-root users will not be able to use dmesg(8)
67056 + to view the contents of the kernel's circular log buffer.
67057 + The kernel's log buffer often contains kernel addresses and other
67058 + identifying information useful to an attacker in fingerprinting a
67059 + system for a targeted exploit.
67060 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
67061 + created.
67062 +
67063 +config GRKERNSEC_HARDEN_PTRACE
67064 + bool "Deter ptrace-based process snooping"
67065 + default y if GRKERNSEC_CONFIG_AUTO
67066 + help
67067 + If you say Y here, TTY sniffers and other malicious monitoring
67068 + programs implemented through ptrace will be defeated. If you
67069 + have been using the RBAC system, this option has already been
67070 + enabled for several years for all users, with the ability to make
67071 + fine-grained exceptions.
67072 +
67073 + This option only affects the ability of non-root users to ptrace
67074 + processes that are not a descendent of the ptracing process.
67075 + This means that strace ./binary and gdb ./binary will still work,
67076 + but attaching to arbitrary processes will not. If the sysctl
67077 + option is enabled, a sysctl option with name "harden_ptrace" is
67078 + created.
67079 +
67080 +config GRKERNSEC_PTRACE_READEXEC
67081 + bool "Require read access to ptrace sensitive binaries"
67082 + default y if GRKERNSEC_CONFIG_AUTO
67083 + help
67084 + If you say Y here, unprivileged users will not be able to ptrace unreadable
67085 + binaries. This option is useful in environments that
67086 + remove the read bits (e.g. file mode 4711) from suid binaries to
67087 + prevent infoleaking of their contents. This option adds
67088 + consistency to the use of that file mode, as the binary could normally
67089 + be read out when run without privileges while ptracing.
67090 +
67091 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
67092 + is created.
67093 +
67094 +config GRKERNSEC_SETXID
67095 + bool "Enforce consistent multithreaded privileges"
67096 + default y if GRKERNSEC_CONFIG_AUTO
67097 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
67098 + help
67099 + If you say Y here, a change from a root uid to a non-root uid
67100 + in a multithreaded application will cause the resulting uids,
67101 + gids, supplementary groups, and capabilities in that thread
67102 + to be propagated to the other threads of the process. In most
67103 + cases this is unnecessary, as glibc will emulate this behavior
67104 + on behalf of the application. Other libcs do not act in the
67105 + same way, allowing the other threads of the process to continue
67106 + running with root privileges. If the sysctl option is enabled,
67107 + a sysctl option with name "consistent_setxid" is created.
67108 +
67109 +config GRKERNSEC_HARDEN_IPC
67110 + bool "Disallow access to overly-permissive IPC objects"
67111 + default y if GRKERNSEC_CONFIG_AUTO
67112 + depends on SYSVIPC
67113 + help
67114 + If you say Y here, access to overly-permissive IPC objects (shared
67115 + memory, message queues, and semaphores) will be denied for processes
67116 + given the following criteria beyond normal permission checks:
67117 + 1) If the IPC object is world-accessible and the euid doesn't match
67118 + that of the creator or current uid for the IPC object
67119 + 2) If the IPC object is group-accessible and the egid doesn't
67120 + match that of the creator or current gid for the IPC object
67121 + It's a common error to grant too much permission to these objects,
67122 + with impact ranging from denial of service and information leaking to
67123 + privilege escalation. This feature was developed in response to
67124 + research by Tim Brown:
67125 + http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
67126 + who found hundreds of such insecure usages. Processes with
67127 + CAP_IPC_OWNER are still permitted to access these IPC objects.
67128 + If the sysctl option is enabled, a sysctl option with name
67129 + "harden_ipc" is created.
67130 +
67131 +config GRKERNSEC_TPE
67132 + bool "Trusted Path Execution (TPE)"
67133 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
67134 + help
67135 + If you say Y here, you will be able to choose a gid to add to the
67136 + supplementary groups of users you want to mark as "untrusted."
67137 + These users will not be able to execute any files that are not in
67138 + root-owned directories writable only by root. If the sysctl option
67139 + is enabled, a sysctl option with name "tpe" is created.
67140 +
67141 +config GRKERNSEC_TPE_ALL
67142 + bool "Partially restrict all non-root users"
67143 + depends on GRKERNSEC_TPE
67144 + help
67145 + If you say Y here, all non-root users will be covered under
67146 + a weaker TPE restriction. This is separate from, and in addition to,
67147 + the main TPE options that you have selected elsewhere. Thus, if a
67148 + "trusted" GID is chosen, this restriction applies to even that GID.
67149 + Under this restriction, all non-root users will only be allowed to
67150 + execute files in directories they own that are not group or
67151 + world-writable, or in directories owned by root and writable only by
67152 + root. If the sysctl option is enabled, a sysctl option with name
67153 + "tpe_restrict_all" is created.
67154 +
67155 +config GRKERNSEC_TPE_INVERT
67156 + bool "Invert GID option"
67157 + depends on GRKERNSEC_TPE
67158 + help
67159 + If you say Y here, the group you specify in the TPE configuration will
67160 + decide what group TPE restrictions will be *disabled* for. This
67161 + option is useful if you want TPE restrictions to be applied to most
67162 + users on the system. If the sysctl option is enabled, a sysctl option
67163 + with name "tpe_invert" is created. Unlike other sysctl options, this
67164 + entry will default to on for backward-compatibility.
67165 +
67166 +config GRKERNSEC_TPE_GID
67167 + int
67168 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
67169 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
67170 +
67171 +config GRKERNSEC_TPE_UNTRUSTED_GID
67172 + int "GID for TPE-untrusted users"
67173 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
67174 + default 1005
67175 + help
67176 + Setting this GID determines what group TPE restrictions will be
67177 + *enabled* for. If the sysctl option is enabled, a sysctl option
67178 + with name "tpe_gid" is created.
67179 +
67180 +config GRKERNSEC_TPE_TRUSTED_GID
67181 + int "GID for TPE-trusted users"
67182 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
67183 + default 1005
67184 + help
67185 + Setting this GID determines what group TPE restrictions will be
67186 + *disabled* for. If the sysctl option is enabled, a sysctl option
67187 + with name "tpe_gid" is created.
67188 +
67189 +endmenu
67190 +menu "Network Protections"
67191 +depends on GRKERNSEC
67192 +
67193 +config GRKERNSEC_BLACKHOLE
67194 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
67195 + default y if GRKERNSEC_CONFIG_AUTO
67196 + depends on NET
67197 + help
67198 + If you say Y here, neither TCP resets nor ICMP
67199 + destination-unreachable packets will be sent in response to packets
67200 + sent to ports for which no associated listening process exists.
67201 + This feature supports both IPV4 and IPV6 and exempts the
67202 + loopback interface from blackholing. Enabling this feature
67203 + makes a host more resilient to DoS attacks and reduces network
67204 + visibility against scanners.
67205 +
67206 + The blackhole feature as-implemented is equivalent to the FreeBSD
67207 + blackhole feature, as it prevents RST responses to all packets, not
67208 + just SYNs. Under most application behavior this causes no
67209 + problems, but applications (like haproxy) may not close certain
67210 + connections in a way that cleanly terminates them on the remote
67211 + end, leaving the remote host in LAST_ACK state. Because of this
67212 + side-effect and to prevent intentional LAST_ACK DoSes, this
67213 + feature also adds automatic mitigation against such attacks.
67214 + The mitigation drastically reduces the amount of time a socket
67215 + can spend in LAST_ACK state. If you're using haproxy and not
67216 + all servers it connects to have this option enabled, consider
67217 + disabling this feature on the haproxy host.
67218 +
67219 + If the sysctl option is enabled, two sysctl options with names
67220 + "ip_blackhole" and "lastack_retries" will be created.
67221 + While "ip_blackhole" takes the standard zero/non-zero on/off
67222 + toggle, "lastack_retries" uses the same kinds of values as
67223 + "tcp_retries1" and "tcp_retries2". The default value of 4
67224 + prevents a socket from lasting more than 45 seconds in LAST_ACK
67225 + state.
67226 +
67227 +config GRKERNSEC_NO_SIMULT_CONNECT
67228 + bool "Disable TCP Simultaneous Connect"
67229 + default y if GRKERNSEC_CONFIG_AUTO
67230 + depends on NET
67231 + help
67232 + If you say Y here, a feature by Willy Tarreau will be enabled that
67233 + removes a weakness in Linux's strict implementation of TCP that
67234 + allows two clients to connect to each other without either entering
67235 + a listening state. The weakness allows an attacker to easily prevent
67236 + a client from connecting to a known server provided the source port
67237 + for the connection is guessed correctly.
67238 +
67239 + As the weakness could be used to prevent an antivirus or IPS from
67240 + fetching updates, or prevent an SSL gateway from fetching a CRL,
67241 + it should be eliminated by enabling this option. Though Linux is
67242 + one of few operating systems supporting simultaneous connect, it
67243 + has no legitimate use in practice and is rarely supported by firewalls.
67244 +
67245 +config GRKERNSEC_SOCKET
67246 + bool "Socket restrictions"
67247 + depends on NET
67248 + help
67249 + If you say Y here, you will be able to choose from several options.
67250 + If you assign a GID on your system and add it to the supplementary
67251 + groups of users you want to restrict socket access to, this patch
67252 + will perform up to three things, based on the option(s) you choose.
67253 +
67254 +config GRKERNSEC_SOCKET_ALL
67255 + bool "Deny any sockets to group"
67256 + depends on GRKERNSEC_SOCKET
67257 + help
67258 + If you say Y here, you will be able to choose a GID of whose users will
67259 + be unable to connect to other hosts from your machine or run server
67260 + applications from your machine. If the sysctl option is enabled, a
67261 + sysctl option with name "socket_all" is created.
67262 +
67263 +config GRKERNSEC_SOCKET_ALL_GID
67264 + int "GID to deny all sockets for"
67265 + depends on GRKERNSEC_SOCKET_ALL
67266 + default 1004
67267 + help
67268 + Here you can choose the GID to disable socket access for. Remember to
67269 + add the users you want socket access disabled for to the GID
67270 + specified here. If the sysctl option is enabled, a sysctl option
67271 + with name "socket_all_gid" is created.
67272 +
67273 +config GRKERNSEC_SOCKET_CLIENT
67274 + bool "Deny client sockets to group"
67275 + depends on GRKERNSEC_SOCKET
67276 + help
67277 + If you say Y here, you will be able to choose a GID of whose users will
67278 + be unable to connect to other hosts from your machine, but will be
67279 + able to run servers. If this option is enabled, all users in the group
67280 + you specify will have to use passive mode when initiating ftp transfers
67281 + from the shell on your machine. If the sysctl option is enabled, a
67282 + sysctl option with name "socket_client" is created.
67283 +
67284 +config GRKERNSEC_SOCKET_CLIENT_GID
67285 + int "GID to deny client sockets for"
67286 + depends on GRKERNSEC_SOCKET_CLIENT
67287 + default 1003
67288 + help
67289 + Here you can choose the GID to disable client socket access for.
67290 + Remember to add the users you want client socket access disabled for to
67291 + the GID specified here. If the sysctl option is enabled, a sysctl
67292 + option with name "socket_client_gid" is created.
67293 +
67294 +config GRKERNSEC_SOCKET_SERVER
67295 + bool "Deny server sockets to group"
67296 + depends on GRKERNSEC_SOCKET
67297 + help
67298 + If you say Y here, you will be able to choose a GID of whose users will
67299 + be unable to run server applications from your machine. If the sysctl
67300 + option is enabled, a sysctl option with name "socket_server" is created.
67301 +
67302 +config GRKERNSEC_SOCKET_SERVER_GID
67303 + int "GID to deny server sockets for"
67304 + depends on GRKERNSEC_SOCKET_SERVER
67305 + default 1002
67306 + help
67307 + Here you can choose the GID to disable server socket access for.
67308 + Remember to add the users you want server socket access disabled for to
67309 + the GID specified here. If the sysctl option is enabled, a sysctl
67310 + option with name "socket_server_gid" is created.
67311 +
67312 +endmenu
67313 +
67314 +menu "Physical Protections"
67315 +depends on GRKERNSEC
67316 +
67317 +config GRKERNSEC_DENYUSB
67318 + bool "Deny new USB connections after toggle"
67319 + default y if GRKERNSEC_CONFIG_AUTO
67320 + depends on SYSCTL && USB_SUPPORT
67321 + help
67322 + If you say Y here, a new sysctl option with name "deny_new_usb"
67323 + will be created. Setting its value to 1 will prevent any new
67324 + USB devices from being recognized by the OS. Any attempted USB
67325 + device insertion will be logged. This option is intended to be
67326 + used against custom USB devices designed to exploit vulnerabilities
67327 + in various USB device drivers.
67328 +
67329 + For greatest effectiveness, this sysctl should be set after any
67330 + relevant init scripts. This option is safe to enable in distros
67331 + as each user can choose whether or not to toggle the sysctl.
67332 +
67333 +config GRKERNSEC_DENYUSB_FORCE
67334 + bool "Reject all USB devices not connected at boot"
67335 + select USB
67336 + depends on GRKERNSEC_DENYUSB
67337 + help
67338 + If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
67339 + that doesn't involve a sysctl entry. This option should only be
67340 + enabled if you're sure you want to deny all new USB connections
67341 + at runtime and don't want to modify init scripts. This should not
67342 + be enabled by distros. It forces the core USB code to be built
67343 + into the kernel image so that all devices connected at boot time
67344 + can be recognized and new USB device connections can be prevented
67345 + prior to init running.
67346 +
67347 +endmenu
67348 +
67349 +menu "Sysctl Support"
67350 +depends on GRKERNSEC && SYSCTL
67351 +
67352 +config GRKERNSEC_SYSCTL
67353 + bool "Sysctl support"
67354 + default y if GRKERNSEC_CONFIG_AUTO
67355 + help
67356 + If you say Y here, you will be able to change the options that
67357 + grsecurity runs with at bootup, without having to recompile your
67358 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
67359 + to enable (1) or disable (0) various features. All the sysctl entries
67360 + are mutable until the "grsec_lock" entry is set to a non-zero value.
67361 + All features enabled in the kernel configuration are disabled at boot
67362 + if you do not say Y to the "Turn on features by default" option.
67363 + All options should be set at startup, and the grsec_lock entry should
67364 + be set to a non-zero value after all the options are set.
67365 + *THIS IS EXTREMELY IMPORTANT*
67366 +
67367 +config GRKERNSEC_SYSCTL_DISTRO
67368 + bool "Extra sysctl support for distro makers (READ HELP)"
67369 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
67370 + help
67371 + If you say Y here, additional sysctl options will be created
67372 + for features that affect processes running as root. Therefore,
67373 + it is critical when using this option that the grsec_lock entry be
67374 + enabled after boot. Only distros with prebuilt kernel packages
67375 + with this option enabled that can ensure grsec_lock is enabled
67376 + after boot should use this option.
67377 + *Failure to set grsec_lock after boot makes all grsec features
67378 + this option covers useless*
67379 +
67380 + Currently this option creates the following sysctl entries:
67381 + "Disable Privileged I/O": "disable_priv_io"
67382 +
67383 +config GRKERNSEC_SYSCTL_ON
67384 + bool "Turn on features by default"
67385 + default y if GRKERNSEC_CONFIG_AUTO
67386 + depends on GRKERNSEC_SYSCTL
67387 + help
67388 + If you say Y here, instead of having all features enabled in the
67389 + kernel configuration disabled at boot time, the features will be
67390 + enabled at boot time. It is recommended you say Y here unless
67391 + there is some reason you would want all sysctl-tunable features to
67392 + be disabled by default. As mentioned elsewhere, it is important
67393 + to enable the grsec_lock entry once you have finished modifying
67394 + the sysctl entries.
67395 +
67396 +endmenu
67397 +menu "Logging Options"
67398 +depends on GRKERNSEC
67399 +
67400 +config GRKERNSEC_FLOODTIME
67401 + int "Seconds in between log messages (minimum)"
67402 + default 10
67403 + help
67404 + This option allows you to enforce the number of seconds between
67405 + grsecurity log messages. The default should be suitable for most
67406 + people, however, if you choose to change it, choose a value small enough
67407 + to allow informative logs to be produced, but large enough to
67408 + prevent flooding.
67409 +
67410 + Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
67411 + any rate limiting on grsecurity log messages.
67412 +
67413 +config GRKERNSEC_FLOODBURST
67414 + int "Number of messages in a burst (maximum)"
67415 + default 6
67416 + help
67417 + This option allows you to choose the maximum number of messages allowed
67418 + within the flood time interval you chose in a separate option. The
67419 + default should be suitable for most people, however if you find that
67420 + many of your logs are being interpreted as flooding, you may want to
67421 + raise this value.
67422 +
67423 + Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
67424 + any rate limiting on grsecurity log messages.
67425 +
67426 +endmenu
67427 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
67428 new file mode 100644
67429 index 0000000..30ababb
67430 --- /dev/null
67431 +++ b/grsecurity/Makefile
67432 @@ -0,0 +1,54 @@
67433 +# grsecurity – access control and security hardening for Linux
67434 +# All code in this directory and various hooks located throughout the Linux kernel are
67435 +# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
67436 +# http://www.grsecurity.net spender@grsecurity.net
67437 +#
67438 +# This program is free software; you can redistribute it and/or
67439 +# modify it under the terms of the GNU General Public License version 2
67440 +# as published by the Free Software Foundation.
67441 +#
67442 +# This program is distributed in the hope that it will be useful,
67443 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
67444 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
67445 +# GNU General Public License for more details.
67446 +#
67447 +# You should have received a copy of the GNU General Public License
67448 +# along with this program; if not, write to the Free Software
67449 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
67450 +
67451 +KBUILD_CFLAGS += -Werror
67452 +
67453 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
67454 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
67455 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
67456 + grsec_usb.o grsec_ipc.o grsec_proc.o
67457 +
67458 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
67459 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
67460 + gracl_learn.o grsec_log.o gracl_policy.o
67461 +ifdef CONFIG_COMPAT
67462 +obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
67463 +endif
67464 +
67465 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
67466 +
67467 +ifdef CONFIG_NET
67468 +obj-y += grsec_sock.o
67469 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
67470 +endif
67471 +
67472 +ifndef CONFIG_GRKERNSEC
67473 +obj-y += grsec_disabled.o
67474 +endif
67475 +
67476 +ifdef CONFIG_GRKERNSEC_HIDESYM
67477 +extra-y := grsec_hidesym.o
67478 +$(obj)/grsec_hidesym.o:
67479 + @-chmod -f 500 /boot
67480 + @-chmod -f 500 /lib/modules
67481 + @-chmod -f 500 /lib64/modules
67482 + @-chmod -f 500 /lib32/modules
67483 + @-chmod -f 700 .
67484 + @-chmod -f 700 $(objtree)
67485 + @echo ' grsec: protected kernel image paths'
67486 +endif
67487 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
67488 new file mode 100644
67489 index 0000000..58223f6
67490 --- /dev/null
67491 +++ b/grsecurity/gracl.c
67492 @@ -0,0 +1,2702 @@
67493 +#include <linux/kernel.h>
67494 +#include <linux/module.h>
67495 +#include <linux/sched.h>
67496 +#include <linux/mm.h>
67497 +#include <linux/file.h>
67498 +#include <linux/fs.h>
67499 +#include <linux/namei.h>
67500 +#include <linux/mount.h>
67501 +#include <linux/tty.h>
67502 +#include <linux/proc_fs.h>
67503 +#include <linux/lglock.h>
67504 +#include <linux/slab.h>
67505 +#include <linux/vmalloc.h>
67506 +#include <linux/types.h>
67507 +#include <linux/sysctl.h>
67508 +#include <linux/netdevice.h>
67509 +#include <linux/ptrace.h>
67510 +#include <linux/gracl.h>
67511 +#include <linux/gralloc.h>
67512 +#include <linux/security.h>
67513 +#include <linux/grinternal.h>
67514 +#include <linux/pid_namespace.h>
67515 +#include <linux/stop_machine.h>
67516 +#include <linux/fdtable.h>
67517 +#include <linux/percpu.h>
67518 +#include <linux/lglock.h>
67519 +#include <linux/hugetlb.h>
67520 +#include <linux/posix-timers.h>
67521 +#include <linux/prefetch.h>
67522 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
67523 +#include <linux/magic.h>
67524 +#include <linux/pagemap.h>
67525 +#include "../fs/btrfs/async-thread.h"
67526 +#include "../fs/btrfs/ctree.h"
67527 +#include "../fs/btrfs/btrfs_inode.h"
67528 +#endif
67529 +#include "../fs/mount.h"
67530 +
67531 +#include <asm/uaccess.h>
67532 +#include <asm/errno.h>
67533 +#include <asm/mman.h>
67534 +
67535 +#define FOR_EACH_ROLE_START(role) \
67536 + role = running_polstate.role_list; \
67537 + while (role) {
67538 +
67539 +#define FOR_EACH_ROLE_END(role) \
67540 + role = role->prev; \
67541 + }
67542 +
67543 +extern struct path gr_real_root;
67544 +
67545 +static struct gr_policy_state running_polstate;
67546 +struct gr_policy_state *polstate = &running_polstate;
67547 +extern struct gr_alloc_state *current_alloc_state;
67548 +
67549 +extern char *gr_shared_page[4];
67550 +DEFINE_RWLOCK(gr_inode_lock);
67551 +
67552 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
67553 +
67554 +#ifdef CONFIG_NET
67555 +extern struct vfsmount *sock_mnt;
67556 +#endif
67557 +
67558 +extern struct vfsmount *pipe_mnt;
67559 +extern struct vfsmount *shm_mnt;
67560 +
67561 +#ifdef CONFIG_HUGETLBFS
67562 +extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
67563 +#endif
67564 +
67565 +extern u16 acl_sp_role_value;
67566 +extern struct acl_object_label *fakefs_obj_rw;
67567 +extern struct acl_object_label *fakefs_obj_rwx;
67568 +
67569 +int gr_acl_is_enabled(void)
67570 +{
67571 + return (gr_status & GR_READY);
67572 +}
67573 +
67574 +void gr_enable_rbac_system(void)
67575 +{
67576 + pax_open_kernel();
67577 + gr_status |= GR_READY;
67578 + pax_close_kernel();
67579 +}
67580 +
67581 +int gr_rbac_disable(void *unused)
67582 +{
67583 + pax_open_kernel();
67584 + gr_status &= ~GR_READY;
67585 + pax_close_kernel();
67586 +
67587 + return 0;
67588 +}
67589 +
67590 +static inline dev_t __get_dev(const struct dentry *dentry)
67591 +{
67592 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
67593 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
67594 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
67595 + else
67596 +#endif
67597 + return dentry->d_sb->s_dev;
67598 +}
67599 +
67600 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
67601 +{
67602 + return __get_dev(dentry);
67603 +}
67604 +
67605 +static char gr_task_roletype_to_char(struct task_struct *task)
67606 +{
67607 + switch (task->role->roletype &
67608 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
67609 + GR_ROLE_SPECIAL)) {
67610 + case GR_ROLE_DEFAULT:
67611 + return 'D';
67612 + case GR_ROLE_USER:
67613 + return 'U';
67614 + case GR_ROLE_GROUP:
67615 + return 'G';
67616 + case GR_ROLE_SPECIAL:
67617 + return 'S';
67618 + }
67619 +
67620 + return 'X';
67621 +}
67622 +
67623 +char gr_roletype_to_char(void)
67624 +{
67625 + return gr_task_roletype_to_char(current);
67626 +}
67627 +
67628 +__inline__ int
67629 +gr_acl_tpe_check(void)
67630 +{
67631 + if (unlikely(!(gr_status & GR_READY)))
67632 + return 0;
67633 + if (current->role->roletype & GR_ROLE_TPE)
67634 + return 1;
67635 + else
67636 + return 0;
67637 +}
67638 +
67639 +int
67640 +gr_handle_rawio(const struct inode *inode)
67641 +{
67642 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
67643 + if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
67644 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
67645 + !capable(CAP_SYS_RAWIO))
67646 + return 1;
67647 +#endif
67648 + return 0;
67649 +}
67650 +
67651 +int
67652 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
67653 +{
67654 + if (likely(lena != lenb))
67655 + return 0;
67656 +
67657 + return !memcmp(a, b, lena);
67658 +}
67659 +
67660 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
67661 +{
67662 + *buflen -= namelen;
67663 + if (*buflen < 0)
67664 + return -ENAMETOOLONG;
67665 + *buffer -= namelen;
67666 + memcpy(*buffer, str, namelen);
67667 + return 0;
67668 +}
67669 +
67670 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
67671 +{
67672 + return prepend(buffer, buflen, name->name, name->len);
67673 +}
67674 +
67675 +static int prepend_path(const struct path *path, struct path *root,
67676 + char **buffer, int *buflen)
67677 +{
67678 + struct dentry *dentry = path->dentry;
67679 + struct vfsmount *vfsmnt = path->mnt;
67680 + struct mount *mnt = real_mount(vfsmnt);
67681 + bool slash = false;
67682 + int error = 0;
67683 +
67684 + while (dentry != root->dentry || vfsmnt != root->mnt) {
67685 + struct dentry * parent;
67686 +
67687 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
67688 + /* Global root? */
67689 + if (!mnt_has_parent(mnt)) {
67690 + goto out;
67691 + }
67692 + dentry = mnt->mnt_mountpoint;
67693 + mnt = mnt->mnt_parent;
67694 + vfsmnt = &mnt->mnt;
67695 + continue;
67696 + }
67697 + parent = dentry->d_parent;
67698 + prefetch(parent);
67699 + spin_lock(&dentry->d_lock);
67700 + error = prepend_name(buffer, buflen, &dentry->d_name);
67701 + spin_unlock(&dentry->d_lock);
67702 + if (!error)
67703 + error = prepend(buffer, buflen, "/", 1);
67704 + if (error)
67705 + break;
67706 +
67707 + slash = true;
67708 + dentry = parent;
67709 + }
67710 +
67711 +out:
67712 + if (!error && !slash)
67713 + error = prepend(buffer, buflen, "/", 1);
67714 +
67715 + return error;
67716 +}
67717 +
67718 +/* this must be called with mount_lock and rename_lock held */
67719 +
67720 +static char *__our_d_path(const struct path *path, struct path *root,
67721 + char *buf, int buflen)
67722 +{
67723 + char *res = buf + buflen;
67724 + int error;
67725 +
67726 + prepend(&res, &buflen, "\0", 1);
67727 + error = prepend_path(path, root, &res, &buflen);
67728 + if (error)
67729 + return ERR_PTR(error);
67730 +
67731 + return res;
67732 +}
67733 +
67734 +static char *
67735 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
67736 +{
67737 + char *retval;
67738 +
67739 + retval = __our_d_path(path, root, buf, buflen);
67740 + if (unlikely(IS_ERR(retval)))
67741 + retval = strcpy(buf, "<path too long>");
67742 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
67743 + retval[1] = '\0';
67744 +
67745 + return retval;
67746 +}
67747 +
67748 +static char *
67749 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
67750 + char *buf, int buflen)
67751 +{
67752 + struct path path;
67753 + char *res;
67754 +
67755 + path.dentry = (struct dentry *)dentry;
67756 + path.mnt = (struct vfsmount *)vfsmnt;
67757 +
67758 + /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
67759 + by the RBAC system */
67760 + res = gen_full_path(&path, &gr_real_root, buf, buflen);
67761 +
67762 + return res;
67763 +}
67764 +
67765 +static char *
67766 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
67767 + char *buf, int buflen)
67768 +{
67769 + char *res;
67770 + struct path path;
67771 + struct path root;
67772 + struct task_struct *reaper = init_pid_ns.child_reaper;
67773 +
67774 + path.dentry = (struct dentry *)dentry;
67775 + path.mnt = (struct vfsmount *)vfsmnt;
67776 +
67777 + /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
67778 + get_fs_root(reaper->fs, &root);
67779 +
67780 + read_seqlock_excl(&mount_lock);
67781 + write_seqlock(&rename_lock);
67782 + res = gen_full_path(&path, &root, buf, buflen);
67783 + write_sequnlock(&rename_lock);
67784 + read_sequnlock_excl(&mount_lock);
67785 +
67786 + path_put(&root);
67787 + return res;
67788 +}
67789 +
67790 +char *
67791 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
67792 +{
67793 + char *ret;
67794 + read_seqlock_excl(&mount_lock);
67795 + write_seqlock(&rename_lock);
67796 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
67797 + PAGE_SIZE);
67798 + write_sequnlock(&rename_lock);
67799 + read_sequnlock_excl(&mount_lock);
67800 + return ret;
67801 +}
67802 +
67803 +static char *
67804 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
67805 +{
67806 + char *ret;
67807 + char *buf;
67808 + int buflen;
67809 +
67810 + read_seqlock_excl(&mount_lock);
67811 + write_seqlock(&rename_lock);
67812 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
67813 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
67814 + buflen = (int)(ret - buf);
67815 + if (buflen >= 5)
67816 + prepend(&ret, &buflen, "/proc", 5);
67817 + else
67818 + ret = strcpy(buf, "<path too long>");
67819 + write_sequnlock(&rename_lock);
67820 + read_sequnlock_excl(&mount_lock);
67821 + return ret;
67822 +}
67823 +
67824 +char *
67825 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
67826 +{
67827 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
67828 + PAGE_SIZE);
67829 +}
67830 +
67831 +char *
67832 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
67833 +{
67834 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
67835 + PAGE_SIZE);
67836 +}
67837 +
67838 +char *
67839 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
67840 +{
67841 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
67842 + PAGE_SIZE);
67843 +}
67844 +
67845 +char *
67846 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
67847 +{
67848 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
67849 + PAGE_SIZE);
67850 +}
67851 +
67852 +char *
67853 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
67854 +{
67855 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
67856 + PAGE_SIZE);
67857 +}
67858 +
67859 +__inline__ __u32
67860 +to_gr_audit(const __u32 reqmode)
67861 +{
67862 + /* masks off auditable permission flags, then shifts them to create
67863 + auditing flags, and adds the special case of append auditing if
67864 + we're requesting write */
67865 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
67866 +}
67867 +
67868 +struct acl_role_label *
67869 +__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
67870 + const gid_t gid)
67871 +{
67872 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
67873 + struct acl_role_label *match;
67874 + struct role_allowed_ip *ipp;
67875 + unsigned int x;
67876 + u32 curr_ip = task->signal->saved_ip;
67877 +
67878 + match = state->acl_role_set.r_hash[index];
67879 +
67880 + while (match) {
67881 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
67882 + for (x = 0; x < match->domain_child_num; x++) {
67883 + if (match->domain_children[x] == uid)
67884 + goto found;
67885 + }
67886 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
67887 + break;
67888 + match = match->next;
67889 + }
67890 +found:
67891 + if (match == NULL) {
67892 + try_group:
67893 + index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
67894 + match = state->acl_role_set.r_hash[index];
67895 +
67896 + while (match) {
67897 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
67898 + for (x = 0; x < match->domain_child_num; x++) {
67899 + if (match->domain_children[x] == gid)
67900 + goto found2;
67901 + }
67902 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
67903 + break;
67904 + match = match->next;
67905 + }
67906 +found2:
67907 + if (match == NULL)
67908 + match = state->default_role;
67909 + if (match->allowed_ips == NULL)
67910 + return match;
67911 + else {
67912 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
67913 + if (likely
67914 + ((ntohl(curr_ip) & ipp->netmask) ==
67915 + (ntohl(ipp->addr) & ipp->netmask)))
67916 + return match;
67917 + }
67918 + match = state->default_role;
67919 + }
67920 + } else if (match->allowed_ips == NULL) {
67921 + return match;
67922 + } else {
67923 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
67924 + if (likely
67925 + ((ntohl(curr_ip) & ipp->netmask) ==
67926 + (ntohl(ipp->addr) & ipp->netmask)))
67927 + return match;
67928 + }
67929 + goto try_group;
67930 + }
67931 +
67932 + return match;
67933 +}
67934 +
67935 +static struct acl_role_label *
67936 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
67937 + const gid_t gid)
67938 +{
67939 + return __lookup_acl_role_label(&running_polstate, task, uid, gid);
67940 +}
67941 +
67942 +struct acl_subject_label *
67943 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
67944 + const struct acl_role_label *role)
67945 +{
67946 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
67947 + struct acl_subject_label *match;
67948 +
67949 + match = role->subj_hash[index];
67950 +
67951 + while (match && (match->inode != ino || match->device != dev ||
67952 + (match->mode & GR_DELETED))) {
67953 + match = match->next;
67954 + }
67955 +
67956 + if (match && !(match->mode & GR_DELETED))
67957 + return match;
67958 + else
67959 + return NULL;
67960 +}
67961 +
67962 +struct acl_subject_label *
67963 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
67964 + const struct acl_role_label *role)
67965 +{
67966 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
67967 + struct acl_subject_label *match;
67968 +
67969 + match = role->subj_hash[index];
67970 +
67971 + while (match && (match->inode != ino || match->device != dev ||
67972 + !(match->mode & GR_DELETED))) {
67973 + match = match->next;
67974 + }
67975 +
67976 + if (match && (match->mode & GR_DELETED))
67977 + return match;
67978 + else
67979 + return NULL;
67980 +}
67981 +
67982 +static struct acl_object_label *
67983 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
67984 + const struct acl_subject_label *subj)
67985 +{
67986 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
67987 + struct acl_object_label *match;
67988 +
67989 + match = subj->obj_hash[index];
67990 +
67991 + while (match && (match->inode != ino || match->device != dev ||
67992 + (match->mode & GR_DELETED))) {
67993 + match = match->next;
67994 + }
67995 +
67996 + if (match && !(match->mode & GR_DELETED))
67997 + return match;
67998 + else
67999 + return NULL;
68000 +}
68001 +
68002 +static struct acl_object_label *
68003 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
68004 + const struct acl_subject_label *subj)
68005 +{
68006 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
68007 + struct acl_object_label *match;
68008 +
68009 + match = subj->obj_hash[index];
68010 +
68011 + while (match && (match->inode != ino || match->device != dev ||
68012 + !(match->mode & GR_DELETED))) {
68013 + match = match->next;
68014 + }
68015 +
68016 + if (match && (match->mode & GR_DELETED))
68017 + return match;
68018 +
68019 + match = subj->obj_hash[index];
68020 +
68021 + while (match && (match->inode != ino || match->device != dev ||
68022 + (match->mode & GR_DELETED))) {
68023 + match = match->next;
68024 + }
68025 +
68026 + if (match && !(match->mode & GR_DELETED))
68027 + return match;
68028 + else
68029 + return NULL;
68030 +}
68031 +
68032 +struct name_entry *
68033 +__lookup_name_entry(const struct gr_policy_state *state, const char *name)
68034 +{
68035 + unsigned int len = strlen(name);
68036 + unsigned int key = full_name_hash(name, len);
68037 + unsigned int index = key % state->name_set.n_size;
68038 + struct name_entry *match;
68039 +
68040 + match = state->name_set.n_hash[index];
68041 +
68042 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
68043 + match = match->next;
68044 +
68045 + return match;
68046 +}
68047 +
68048 +static struct name_entry *
68049 +lookup_name_entry(const char *name)
68050 +{
68051 + return __lookup_name_entry(&running_polstate, name);
68052 +}
68053 +
68054 +static struct name_entry *
68055 +lookup_name_entry_create(const char *name)
68056 +{
68057 + unsigned int len = strlen(name);
68058 + unsigned int key = full_name_hash(name, len);
68059 + unsigned int index = key % running_polstate.name_set.n_size;
68060 + struct name_entry *match;
68061 +
68062 + match = running_polstate.name_set.n_hash[index];
68063 +
68064 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
68065 + !match->deleted))
68066 + match = match->next;
68067 +
68068 + if (match && match->deleted)
68069 + return match;
68070 +
68071 + match = running_polstate.name_set.n_hash[index];
68072 +
68073 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
68074 + match->deleted))
68075 + match = match->next;
68076 +
68077 + if (match && !match->deleted)
68078 + return match;
68079 + else
68080 + return NULL;
68081 +}
68082 +
68083 +static struct inodev_entry *
68084 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
68085 +{
68086 + unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
68087 + struct inodev_entry *match;
68088 +
68089 + match = running_polstate.inodev_set.i_hash[index];
68090 +
68091 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
68092 + match = match->next;
68093 +
68094 + return match;
68095 +}
68096 +
68097 +void
68098 +__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
68099 +{
68100 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
68101 + state->inodev_set.i_size);
68102 + struct inodev_entry **curr;
68103 +
68104 + entry->prev = NULL;
68105 +
68106 + curr = &state->inodev_set.i_hash[index];
68107 + if (*curr != NULL)
68108 + (*curr)->prev = entry;
68109 +
68110 + entry->next = *curr;
68111 + *curr = entry;
68112 +
68113 + return;
68114 +}
68115 +
68116 +static void
68117 +insert_inodev_entry(struct inodev_entry *entry)
68118 +{
68119 + __insert_inodev_entry(&running_polstate, entry);
68120 +}
68121 +
68122 +void
68123 +insert_acl_obj_label(struct acl_object_label *obj,
68124 + struct acl_subject_label *subj)
68125 +{
68126 + unsigned int index =
68127 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
68128 + struct acl_object_label **curr;
68129 +
68130 + obj->prev = NULL;
68131 +
68132 + curr = &subj->obj_hash[index];
68133 + if (*curr != NULL)
68134 + (*curr)->prev = obj;
68135 +
68136 + obj->next = *curr;
68137 + *curr = obj;
68138 +
68139 + return;
68140 +}
68141 +
68142 +void
68143 +insert_acl_subj_label(struct acl_subject_label *obj,
68144 + struct acl_role_label *role)
68145 +{
68146 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
68147 + struct acl_subject_label **curr;
68148 +
68149 + obj->prev = NULL;
68150 +
68151 + curr = &role->subj_hash[index];
68152 + if (*curr != NULL)
68153 + (*curr)->prev = obj;
68154 +
68155 + obj->next = *curr;
68156 + *curr = obj;
68157 +
68158 + return;
68159 +}
68160 +
68161 +/* derived from glibc fnmatch() 0: match, 1: no match*/
68162 +
68163 +static int
68164 +glob_match(const char *p, const char *n)
68165 +{
68166 + char c;
68167 +
68168 + while ((c = *p++) != '\0') {
68169 + switch (c) {
68170 + case '?':
68171 + if (*n == '\0')
68172 + return 1;
68173 + else if (*n == '/')
68174 + return 1;
68175 + break;
68176 + case '\\':
68177 + if (*n != c)
68178 + return 1;
68179 + break;
68180 + case '*':
68181 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
68182 + if (*n == '/')
68183 + return 1;
68184 + else if (c == '?') {
68185 + if (*n == '\0')
68186 + return 1;
68187 + else
68188 + ++n;
68189 + }
68190 + }
68191 + if (c == '\0') {
68192 + return 0;
68193 + } else {
68194 + const char *endp;
68195 +
68196 + if ((endp = strchr(n, '/')) == NULL)
68197 + endp = n + strlen(n);
68198 +
68199 + if (c == '[') {
68200 + for (--p; n < endp; ++n)
68201 + if (!glob_match(p, n))
68202 + return 0;
68203 + } else if (c == '/') {
68204 + while (*n != '\0' && *n != '/')
68205 + ++n;
68206 + if (*n == '/' && !glob_match(p, n + 1))
68207 + return 0;
68208 + } else {
68209 + for (--p; n < endp; ++n)
68210 + if (*n == c && !glob_match(p, n))
68211 + return 0;
68212 + }
68213 +
68214 + return 1;
68215 + }
68216 + case '[':
68217 + {
68218 + int not;
68219 + char cold;
68220 +
68221 + if (*n == '\0' || *n == '/')
68222 + return 1;
68223 +
68224 + not = (*p == '!' || *p == '^');
68225 + if (not)
68226 + ++p;
68227 +
68228 + c = *p++;
68229 + for (;;) {
68230 + unsigned char fn = (unsigned char)*n;
68231 +
68232 + if (c == '\0')
68233 + return 1;
68234 + else {
68235 + if (c == fn)
68236 + goto matched;
68237 + cold = c;
68238 + c = *p++;
68239 +
68240 + if (c == '-' && *p != ']') {
68241 + unsigned char cend = *p++;
68242 +
68243 + if (cend == '\0')
68244 + return 1;
68245 +
68246 + if (cold <= fn && fn <= cend)
68247 + goto matched;
68248 +
68249 + c = *p++;
68250 + }
68251 + }
68252 +
68253 + if (c == ']')
68254 + break;
68255 + }
68256 + if (!not)
68257 + return 1;
68258 + break;
68259 + matched:
68260 + while (c != ']') {
68261 + if (c == '\0')
68262 + return 1;
68263 +
68264 + c = *p++;
68265 + }
68266 + if (not)
68267 + return 1;
68268 + }
68269 + break;
68270 + default:
68271 + if (c != *n)
68272 + return 1;
68273 + }
68274 +
68275 + ++n;
68276 + }
68277 +
68278 + if (*n == '\0')
68279 + return 0;
68280 +
68281 + if (*n == '/')
68282 + return 0;
68283 +
68284 + return 1;
68285 +}
68286 +
68287 +static struct acl_object_label *
68288 +chk_glob_label(struct acl_object_label *globbed,
68289 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
68290 +{
68291 + struct acl_object_label *tmp;
68292 +
68293 + if (*path == NULL)
68294 + *path = gr_to_filename_nolock(dentry, mnt);
68295 +
68296 + tmp = globbed;
68297 +
68298 + while (tmp) {
68299 + if (!glob_match(tmp->filename, *path))
68300 + return tmp;
68301 + tmp = tmp->next;
68302 + }
68303 +
68304 + return NULL;
68305 +}
68306 +
68307 +static struct acl_object_label *
68308 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
68309 + const ino_t curr_ino, const dev_t curr_dev,
68310 + const struct acl_subject_label *subj, char **path, const int checkglob)
68311 +{
68312 + struct acl_subject_label *tmpsubj;
68313 + struct acl_object_label *retval;
68314 + struct acl_object_label *retval2;
68315 +
68316 + tmpsubj = (struct acl_subject_label *) subj;
68317 + read_lock(&gr_inode_lock);
68318 + do {
68319 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
68320 + if (retval) {
68321 + if (checkglob && retval->globbed) {
68322 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
68323 + if (retval2)
68324 + retval = retval2;
68325 + }
68326 + break;
68327 + }
68328 + } while ((tmpsubj = tmpsubj->parent_subject));
68329 + read_unlock(&gr_inode_lock);
68330 +
68331 + return retval;
68332 +}
68333 +
68334 +static __inline__ struct acl_object_label *
68335 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
68336 + struct dentry *curr_dentry,
68337 + const struct acl_subject_label *subj, char **path, const int checkglob)
68338 +{
68339 + int newglob = checkglob;
68340 + ino_t inode;
68341 + dev_t device;
68342 +
68343 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
68344 + as we don't want a / * rule to match instead of the / object
68345 + don't do this for create lookups that call this function though, since they're looking up
68346 + on the parent and thus need globbing checks on all paths
68347 + */
68348 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
68349 + newglob = GR_NO_GLOB;
68350 +
68351 + spin_lock(&curr_dentry->d_lock);
68352 + inode = curr_dentry->d_inode->i_ino;
68353 + device = __get_dev(curr_dentry);
68354 + spin_unlock(&curr_dentry->d_lock);
68355 +
68356 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
68357 +}
68358 +
68359 +#ifdef CONFIG_HUGETLBFS
68360 +static inline bool
68361 +is_hugetlbfs_mnt(const struct vfsmount *mnt)
68362 +{
68363 + int i;
68364 + for (i = 0; i < HUGE_MAX_HSTATE; i++) {
68365 + if (unlikely(hugetlbfs_vfsmount[i] == mnt))
68366 + return true;
68367 + }
68368 +
68369 + return false;
68370 +}
68371 +#endif
68372 +
68373 +static struct acl_object_label *
68374 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68375 + const struct acl_subject_label *subj, char *path, const int checkglob)
68376 +{
68377 + struct dentry *dentry = (struct dentry *) l_dentry;
68378 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
68379 + struct mount *real_mnt = real_mount(mnt);
68380 + struct acl_object_label *retval;
68381 + struct dentry *parent;
68382 +
68383 + read_seqlock_excl(&mount_lock);
68384 + write_seqlock(&rename_lock);
68385 +
68386 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
68387 +#ifdef CONFIG_NET
68388 + mnt == sock_mnt ||
68389 +#endif
68390 +#ifdef CONFIG_HUGETLBFS
68391 + (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
68392 +#endif
68393 + /* ignore Eric Biederman */
68394 + IS_PRIVATE(l_dentry->d_inode))) {
68395 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
68396 + goto out;
68397 + }
68398 +
68399 + for (;;) {
68400 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
68401 + break;
68402 +
68403 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
68404 + if (!mnt_has_parent(real_mnt))
68405 + break;
68406 +
68407 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
68408 + if (retval != NULL)
68409 + goto out;
68410 +
68411 + dentry = real_mnt->mnt_mountpoint;
68412 + real_mnt = real_mnt->mnt_parent;
68413 + mnt = &real_mnt->mnt;
68414 + continue;
68415 + }
68416 +
68417 + parent = dentry->d_parent;
68418 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
68419 + if (retval != NULL)
68420 + goto out;
68421 +
68422 + dentry = parent;
68423 + }
68424 +
68425 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
68426 +
68427 + /* gr_real_root is pinned so we don't have to hold a reference */
68428 + if (retval == NULL)
68429 + retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
68430 +out:
68431 + write_sequnlock(&rename_lock);
68432 + read_sequnlock_excl(&mount_lock);
68433 +
68434 + BUG_ON(retval == NULL);
68435 +
68436 + return retval;
68437 +}
68438 +
68439 +static __inline__ struct acl_object_label *
68440 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68441 + const struct acl_subject_label *subj)
68442 +{
68443 + char *path = NULL;
68444 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
68445 +}
68446 +
68447 +static __inline__ struct acl_object_label *
68448 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68449 + const struct acl_subject_label *subj)
68450 +{
68451 + char *path = NULL;
68452 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
68453 +}
68454 +
68455 +static __inline__ struct acl_object_label *
68456 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68457 + const struct acl_subject_label *subj, char *path)
68458 +{
68459 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
68460 +}
68461 +
68462 +struct acl_subject_label *
68463 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68464 + const struct acl_role_label *role)
68465 +{
68466 + struct dentry *dentry = (struct dentry *) l_dentry;
68467 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
68468 + struct mount *real_mnt = real_mount(mnt);
68469 + struct acl_subject_label *retval;
68470 + struct dentry *parent;
68471 +
68472 + read_seqlock_excl(&mount_lock);
68473 + write_seqlock(&rename_lock);
68474 +
68475 + for (;;) {
68476 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
68477 + break;
68478 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
68479 + if (!mnt_has_parent(real_mnt))
68480 + break;
68481 +
68482 + spin_lock(&dentry->d_lock);
68483 + read_lock(&gr_inode_lock);
68484 + retval =
68485 + lookup_acl_subj_label(dentry->d_inode->i_ino,
68486 + __get_dev(dentry), role);
68487 + read_unlock(&gr_inode_lock);
68488 + spin_unlock(&dentry->d_lock);
68489 + if (retval != NULL)
68490 + goto out;
68491 +
68492 + dentry = real_mnt->mnt_mountpoint;
68493 + real_mnt = real_mnt->mnt_parent;
68494 + mnt = &real_mnt->mnt;
68495 + continue;
68496 + }
68497 +
68498 + spin_lock(&dentry->d_lock);
68499 + read_lock(&gr_inode_lock);
68500 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
68501 + __get_dev(dentry), role);
68502 + read_unlock(&gr_inode_lock);
68503 + parent = dentry->d_parent;
68504 + spin_unlock(&dentry->d_lock);
68505 +
68506 + if (retval != NULL)
68507 + goto out;
68508 +
68509 + dentry = parent;
68510 + }
68511 +
68512 + spin_lock(&dentry->d_lock);
68513 + read_lock(&gr_inode_lock);
68514 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
68515 + __get_dev(dentry), role);
68516 + read_unlock(&gr_inode_lock);
68517 + spin_unlock(&dentry->d_lock);
68518 +
68519 + if (unlikely(retval == NULL)) {
68520 + /* gr_real_root is pinned, we don't need to hold a reference */
68521 + read_lock(&gr_inode_lock);
68522 + retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
68523 + __get_dev(gr_real_root.dentry), role);
68524 + read_unlock(&gr_inode_lock);
68525 + }
68526 +out:
68527 + write_sequnlock(&rename_lock);
68528 + read_sequnlock_excl(&mount_lock);
68529 +
68530 + BUG_ON(retval == NULL);
68531 +
68532 + return retval;
68533 +}
68534 +
68535 +void
68536 +assign_special_role(const char *rolename)
68537 +{
68538 + struct acl_object_label *obj;
68539 + struct acl_role_label *r;
68540 + struct acl_role_label *assigned = NULL;
68541 + struct task_struct *tsk;
68542 + struct file *filp;
68543 +
68544 + FOR_EACH_ROLE_START(r)
68545 + if (!strcmp(rolename, r->rolename) &&
68546 + (r->roletype & GR_ROLE_SPECIAL)) {
68547 + assigned = r;
68548 + break;
68549 + }
68550 + FOR_EACH_ROLE_END(r)
68551 +
68552 + if (!assigned)
68553 + return;
68554 +
68555 + read_lock(&tasklist_lock);
68556 + read_lock(&grsec_exec_file_lock);
68557 +
68558 + tsk = current->real_parent;
68559 + if (tsk == NULL)
68560 + goto out_unlock;
68561 +
68562 + filp = tsk->exec_file;
68563 + if (filp == NULL)
68564 + goto out_unlock;
68565 +
68566 + tsk->is_writable = 0;
68567 + tsk->inherited = 0;
68568 +
68569 + tsk->acl_sp_role = 1;
68570 + tsk->acl_role_id = ++acl_sp_role_value;
68571 + tsk->role = assigned;
68572 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
68573 +
68574 + /* ignore additional mmap checks for processes that are writable
68575 + by the default ACL */
68576 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68577 + if (unlikely(obj->mode & GR_WRITE))
68578 + tsk->is_writable = 1;
68579 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
68580 + if (unlikely(obj->mode & GR_WRITE))
68581 + tsk->is_writable = 1;
68582 +
68583 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68584 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
68585 + tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
68586 +#endif
68587 +
68588 +out_unlock:
68589 + read_unlock(&grsec_exec_file_lock);
68590 + read_unlock(&tasklist_lock);
68591 + return;
68592 +}
68593 +
68594 +
68595 +static void
68596 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
68597 +{
68598 + struct task_struct *task = current;
68599 + const struct cred *cred = current_cred();
68600 +
68601 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
68602 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
68603 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
68604 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
68605 +
68606 + return;
68607 +}
68608 +
68609 +static void
68610 +gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
68611 +{
68612 + struct task_struct *task = current;
68613 + const struct cred *cred = current_cred();
68614 +
68615 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
68616 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
68617 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
68618 + 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
68619 +
68620 + return;
68621 +}
68622 +
68623 +static void
68624 +gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
68625 +{
68626 + struct task_struct *task = current;
68627 + const struct cred *cred = current_cred();
68628 +
68629 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
68630 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
68631 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
68632 + 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
68633 +
68634 + return;
68635 +}
68636 +
68637 +static void
68638 +gr_set_proc_res(struct task_struct *task)
68639 +{
68640 + struct acl_subject_label *proc;
68641 + unsigned short i;
68642 +
68643 + proc = task->acl;
68644 +
68645 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
68646 + return;
68647 +
68648 + for (i = 0; i < RLIM_NLIMITS; i++) {
68649 + if (!(proc->resmask & (1U << i)))
68650 + continue;
68651 +
68652 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
68653 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
68654 +
68655 + if (i == RLIMIT_CPU)
68656 + update_rlimit_cpu(task, proc->res[i].rlim_cur);
68657 + }
68658 +
68659 + return;
68660 +}
68661 +
68662 +/* both of the below must be called with
68663 + rcu_read_lock();
68664 + read_lock(&tasklist_lock);
68665 + read_lock(&grsec_exec_file_lock);
68666 +*/
68667 +
68668 +struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
68669 +{
68670 + char *tmpname;
68671 + struct acl_subject_label *tmpsubj;
68672 + struct file *filp;
68673 + struct name_entry *nmatch;
68674 +
68675 + filp = task->exec_file;
68676 + if (filp == NULL)
68677 + return NULL;
68678 +
68679 + /* the following is to apply the correct subject
68680 + on binaries running when the RBAC system
68681 + is enabled, when the binaries have been
68682 + replaced or deleted since their execution
68683 + -----
68684 + when the RBAC system starts, the inode/dev
68685 + from exec_file will be one the RBAC system
68686 + is unaware of. It only knows the inode/dev
68687 + of the present file on disk, or the absence
68688 + of it.
68689 + */
68690 +
68691 + if (filename)
68692 + nmatch = __lookup_name_entry(state, filename);
68693 + else {
68694 + preempt_disable();
68695 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
68696 +
68697 + nmatch = __lookup_name_entry(state, tmpname);
68698 + preempt_enable();
68699 + }
68700 + tmpsubj = NULL;
68701 + if (nmatch) {
68702 + if (nmatch->deleted)
68703 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
68704 + else
68705 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
68706 + }
68707 + /* this also works for the reload case -- if we don't match a potentially inherited subject
68708 + then we fall back to a normal lookup based on the binary's ino/dev
68709 + */
68710 + if (tmpsubj == NULL)
68711 + tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
68712 +
68713 + return tmpsubj;
68714 +}
68715 +
68716 +static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
68717 +{
68718 + return __gr_get_subject_for_task(&running_polstate, task, filename);
68719 +}
68720 +
68721 +void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
68722 +{
68723 + struct acl_object_label *obj;
68724 + struct file *filp;
68725 +
68726 + filp = task->exec_file;
68727 +
68728 + task->acl = subj;
68729 + task->is_writable = 0;
68730 + /* ignore additional mmap checks for processes that are writable
68731 + by the default ACL */
68732 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
68733 + if (unlikely(obj->mode & GR_WRITE))
68734 + task->is_writable = 1;
68735 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
68736 + if (unlikely(obj->mode & GR_WRITE))
68737 + task->is_writable = 1;
68738 +
68739 + gr_set_proc_res(task);
68740 +
68741 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68742 + 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);
68743 +#endif
68744 +}
68745 +
68746 +static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
68747 +{
68748 + __gr_apply_subject_to_task(&running_polstate, task, subj);
68749 +}
68750 +
68751 +__u32
68752 +gr_search_file(const struct dentry * dentry, const __u32 mode,
68753 + const struct vfsmount * mnt)
68754 +{
68755 + __u32 retval = mode;
68756 + struct acl_subject_label *curracl;
68757 + struct acl_object_label *currobj;
68758 +
68759 + if (unlikely(!(gr_status & GR_READY)))
68760 + return (mode & ~GR_AUDITS);
68761 +
68762 + curracl = current->acl;
68763 +
68764 + currobj = chk_obj_label(dentry, mnt, curracl);
68765 + retval = currobj->mode & mode;
68766 +
68767 + /* if we're opening a specified transfer file for writing
68768 + (e.g. /dev/initctl), then transfer our role to init
68769 + */
68770 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
68771 + current->role->roletype & GR_ROLE_PERSIST)) {
68772 + struct task_struct *task = init_pid_ns.child_reaper;
68773 +
68774 + if (task->role != current->role) {
68775 + struct acl_subject_label *subj;
68776 +
68777 + task->acl_sp_role = 0;
68778 + task->acl_role_id = current->acl_role_id;
68779 + task->role = current->role;
68780 + rcu_read_lock();
68781 + read_lock(&grsec_exec_file_lock);
68782 + subj = gr_get_subject_for_task(task, NULL);
68783 + gr_apply_subject_to_task(task, subj);
68784 + read_unlock(&grsec_exec_file_lock);
68785 + rcu_read_unlock();
68786 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
68787 + }
68788 + }
68789 +
68790 + if (unlikely
68791 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
68792 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
68793 + __u32 new_mode = mode;
68794 +
68795 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
68796 +
68797 + retval = new_mode;
68798 +
68799 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
68800 + new_mode |= GR_INHERIT;
68801 +
68802 + if (!(mode & GR_NOLEARN))
68803 + gr_log_learn(dentry, mnt, new_mode);
68804 + }
68805 +
68806 + return retval;
68807 +}
68808 +
68809 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
68810 + const struct dentry *parent,
68811 + const struct vfsmount *mnt)
68812 +{
68813 + struct name_entry *match;
68814 + struct acl_object_label *matchpo;
68815 + struct acl_subject_label *curracl;
68816 + char *path;
68817 +
68818 + if (unlikely(!(gr_status & GR_READY)))
68819 + return NULL;
68820 +
68821 + preempt_disable();
68822 + path = gr_to_filename_rbac(new_dentry, mnt);
68823 + match = lookup_name_entry_create(path);
68824 +
68825 + curracl = current->acl;
68826 +
68827 + if (match) {
68828 + read_lock(&gr_inode_lock);
68829 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
68830 + read_unlock(&gr_inode_lock);
68831 +
68832 + if (matchpo) {
68833 + preempt_enable();
68834 + return matchpo;
68835 + }
68836 + }
68837 +
68838 + // lookup parent
68839 +
68840 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
68841 +
68842 + preempt_enable();
68843 + return matchpo;
68844 +}
68845 +
68846 +__u32
68847 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
68848 + const struct vfsmount * mnt, const __u32 mode)
68849 +{
68850 + struct acl_object_label *matchpo;
68851 + __u32 retval;
68852 +
68853 + if (unlikely(!(gr_status & GR_READY)))
68854 + return (mode & ~GR_AUDITS);
68855 +
68856 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
68857 +
68858 + retval = matchpo->mode & mode;
68859 +
68860 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
68861 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
68862 + __u32 new_mode = mode;
68863 +
68864 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
68865 +
68866 + gr_log_learn(new_dentry, mnt, new_mode);
68867 + return new_mode;
68868 + }
68869 +
68870 + return retval;
68871 +}
68872 +
68873 +__u32
68874 +gr_check_link(const struct dentry * new_dentry,
68875 + const struct dentry * parent_dentry,
68876 + const struct vfsmount * parent_mnt,
68877 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
68878 +{
68879 + struct acl_object_label *obj;
68880 + __u32 oldmode, newmode;
68881 + __u32 needmode;
68882 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
68883 + GR_DELETE | GR_INHERIT;
68884 +
68885 + if (unlikely(!(gr_status & GR_READY)))
68886 + return (GR_CREATE | GR_LINK);
68887 +
68888 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
68889 + oldmode = obj->mode;
68890 +
68891 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
68892 + newmode = obj->mode;
68893 +
68894 + needmode = newmode & checkmodes;
68895 +
68896 + // old name for hardlink must have at least the permissions of the new name
68897 + if ((oldmode & needmode) != needmode)
68898 + goto bad;
68899 +
68900 + // if old name had restrictions/auditing, make sure the new name does as well
68901 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
68902 +
68903 + // don't allow hardlinking of suid/sgid/fcapped files without permission
68904 + if (is_privileged_binary(old_dentry))
68905 + needmode |= GR_SETID;
68906 +
68907 + if ((newmode & needmode) != needmode)
68908 + goto bad;
68909 +
68910 + // enforce minimum permissions
68911 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
68912 + return newmode;
68913 +bad:
68914 + needmode = oldmode;
68915 + if (is_privileged_binary(old_dentry))
68916 + needmode |= GR_SETID;
68917 +
68918 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
68919 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
68920 + return (GR_CREATE | GR_LINK);
68921 + } else if (newmode & GR_SUPPRESS)
68922 + return GR_SUPPRESS;
68923 + else
68924 + return 0;
68925 +}
68926 +
68927 +int
68928 +gr_check_hidden_task(const struct task_struct *task)
68929 +{
68930 + if (unlikely(!(gr_status & GR_READY)))
68931 + return 0;
68932 +
68933 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
68934 + return 1;
68935 +
68936 + return 0;
68937 +}
68938 +
68939 +int
68940 +gr_check_protected_task(const struct task_struct *task)
68941 +{
68942 + if (unlikely(!(gr_status & GR_READY) || !task))
68943 + return 0;
68944 +
68945 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
68946 + task->acl != current->acl)
68947 + return 1;
68948 +
68949 + return 0;
68950 +}
68951 +
68952 +int
68953 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
68954 +{
68955 + struct task_struct *p;
68956 + int ret = 0;
68957 +
68958 + if (unlikely(!(gr_status & GR_READY) || !pid))
68959 + return ret;
68960 +
68961 + read_lock(&tasklist_lock);
68962 + do_each_pid_task(pid, type, p) {
68963 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
68964 + p->acl != current->acl) {
68965 + ret = 1;
68966 + goto out;
68967 + }
68968 + } while_each_pid_task(pid, type, p);
68969 +out:
68970 + read_unlock(&tasklist_lock);
68971 +
68972 + return ret;
68973 +}
68974 +
68975 +void
68976 +gr_copy_label(struct task_struct *tsk)
68977 +{
68978 + struct task_struct *p = current;
68979 +
68980 + tsk->inherited = p->inherited;
68981 + tsk->acl_sp_role = 0;
68982 + tsk->acl_role_id = p->acl_role_id;
68983 + tsk->acl = p->acl;
68984 + tsk->role = p->role;
68985 + tsk->signal->used_accept = 0;
68986 + tsk->signal->curr_ip = p->signal->curr_ip;
68987 + tsk->signal->saved_ip = p->signal->saved_ip;
68988 + if (p->exec_file)
68989 + get_file(p->exec_file);
68990 + tsk->exec_file = p->exec_file;
68991 + tsk->is_writable = p->is_writable;
68992 + if (unlikely(p->signal->used_accept)) {
68993 + p->signal->curr_ip = 0;
68994 + p->signal->saved_ip = 0;
68995 + }
68996 +
68997 + return;
68998 +}
68999 +
69000 +extern int gr_process_kernel_setuid_ban(struct user_struct *user);
69001 +
69002 +int
69003 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
69004 +{
69005 + unsigned int i;
69006 + __u16 num;
69007 + uid_t *uidlist;
69008 + uid_t curuid;
69009 + int realok = 0;
69010 + int effectiveok = 0;
69011 + int fsok = 0;
69012 + uid_t globalreal, globaleffective, globalfs;
69013 +
69014 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
69015 + struct user_struct *user;
69016 +
69017 + if (!uid_valid(real))
69018 + goto skipit;
69019 +
69020 + /* find user based on global namespace */
69021 +
69022 + globalreal = GR_GLOBAL_UID(real);
69023 +
69024 + user = find_user(make_kuid(&init_user_ns, globalreal));
69025 + if (user == NULL)
69026 + goto skipit;
69027 +
69028 + if (gr_process_kernel_setuid_ban(user)) {
69029 + /* for find_user */
69030 + free_uid(user);
69031 + return 1;
69032 + }
69033 +
69034 + /* for find_user */
69035 + free_uid(user);
69036 +
69037 +skipit:
69038 +#endif
69039 +
69040 + if (unlikely(!(gr_status & GR_READY)))
69041 + return 0;
69042 +
69043 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
69044 + gr_log_learn_uid_change(real, effective, fs);
69045 +
69046 + num = current->acl->user_trans_num;
69047 + uidlist = current->acl->user_transitions;
69048 +
69049 + if (uidlist == NULL)
69050 + return 0;
69051 +
69052 + if (!uid_valid(real)) {
69053 + realok = 1;
69054 + globalreal = (uid_t)-1;
69055 + } else {
69056 + globalreal = GR_GLOBAL_UID(real);
69057 + }
69058 + if (!uid_valid(effective)) {
69059 + effectiveok = 1;
69060 + globaleffective = (uid_t)-1;
69061 + } else {
69062 + globaleffective = GR_GLOBAL_UID(effective);
69063 + }
69064 + if (!uid_valid(fs)) {
69065 + fsok = 1;
69066 + globalfs = (uid_t)-1;
69067 + } else {
69068 + globalfs = GR_GLOBAL_UID(fs);
69069 + }
69070 +
69071 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
69072 + for (i = 0; i < num; i++) {
69073 + curuid = uidlist[i];
69074 + if (globalreal == curuid)
69075 + realok = 1;
69076 + if (globaleffective == curuid)
69077 + effectiveok = 1;
69078 + if (globalfs == curuid)
69079 + fsok = 1;
69080 + }
69081 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
69082 + for (i = 0; i < num; i++) {
69083 + curuid = uidlist[i];
69084 + if (globalreal == curuid)
69085 + break;
69086 + if (globaleffective == curuid)
69087 + break;
69088 + if (globalfs == curuid)
69089 + break;
69090 + }
69091 + /* not in deny list */
69092 + if (i == num) {
69093 + realok = 1;
69094 + effectiveok = 1;
69095 + fsok = 1;
69096 + }
69097 + }
69098 +
69099 + if (realok && effectiveok && fsok)
69100 + return 0;
69101 + else {
69102 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
69103 + return 1;
69104 + }
69105 +}
69106 +
69107 +int
69108 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
69109 +{
69110 + unsigned int i;
69111 + __u16 num;
69112 + gid_t *gidlist;
69113 + gid_t curgid;
69114 + int realok = 0;
69115 + int effectiveok = 0;
69116 + int fsok = 0;
69117 + gid_t globalreal, globaleffective, globalfs;
69118 +
69119 + if (unlikely(!(gr_status & GR_READY)))
69120 + return 0;
69121 +
69122 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
69123 + gr_log_learn_gid_change(real, effective, fs);
69124 +
69125 + num = current->acl->group_trans_num;
69126 + gidlist = current->acl->group_transitions;
69127 +
69128 + if (gidlist == NULL)
69129 + return 0;
69130 +
69131 + if (!gid_valid(real)) {
69132 + realok = 1;
69133 + globalreal = (gid_t)-1;
69134 + } else {
69135 + globalreal = GR_GLOBAL_GID(real);
69136 + }
69137 + if (!gid_valid(effective)) {
69138 + effectiveok = 1;
69139 + globaleffective = (gid_t)-1;
69140 + } else {
69141 + globaleffective = GR_GLOBAL_GID(effective);
69142 + }
69143 + if (!gid_valid(fs)) {
69144 + fsok = 1;
69145 + globalfs = (gid_t)-1;
69146 + } else {
69147 + globalfs = GR_GLOBAL_GID(fs);
69148 + }
69149 +
69150 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
69151 + for (i = 0; i < num; i++) {
69152 + curgid = gidlist[i];
69153 + if (globalreal == curgid)
69154 + realok = 1;
69155 + if (globaleffective == curgid)
69156 + effectiveok = 1;
69157 + if (globalfs == curgid)
69158 + fsok = 1;
69159 + }
69160 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
69161 + for (i = 0; i < num; i++) {
69162 + curgid = gidlist[i];
69163 + if (globalreal == curgid)
69164 + break;
69165 + if (globaleffective == curgid)
69166 + break;
69167 + if (globalfs == curgid)
69168 + break;
69169 + }
69170 + /* not in deny list */
69171 + if (i == num) {
69172 + realok = 1;
69173 + effectiveok = 1;
69174 + fsok = 1;
69175 + }
69176 + }
69177 +
69178 + if (realok && effectiveok && fsok)
69179 + return 0;
69180 + else {
69181 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
69182 + return 1;
69183 + }
69184 +}
69185 +
69186 +extern int gr_acl_is_capable(const int cap);
69187 +
69188 +void
69189 +gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
69190 +{
69191 + struct acl_role_label *role = task->role;
69192 + struct acl_subject_label *subj = NULL;
69193 + struct acl_object_label *obj;
69194 + struct file *filp;
69195 + uid_t uid;
69196 + gid_t gid;
69197 +
69198 + if (unlikely(!(gr_status & GR_READY)))
69199 + return;
69200 +
69201 + uid = GR_GLOBAL_UID(kuid);
69202 + gid = GR_GLOBAL_GID(kgid);
69203 +
69204 + filp = task->exec_file;
69205 +
69206 + /* kernel process, we'll give them the kernel role */
69207 + if (unlikely(!filp)) {
69208 + task->role = running_polstate.kernel_role;
69209 + task->acl = running_polstate.kernel_role->root_label;
69210 + return;
69211 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
69212 + /* save the current ip at time of role lookup so that the proper
69213 + IP will be learned for role_allowed_ip */
69214 + task->signal->saved_ip = task->signal->curr_ip;
69215 + role = lookup_acl_role_label(task, uid, gid);
69216 + }
69217 +
69218 + /* don't change the role if we're not a privileged process */
69219 + if (role && task->role != role &&
69220 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
69221 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
69222 + return;
69223 +
69224 + /* perform subject lookup in possibly new role
69225 + we can use this result below in the case where role == task->role
69226 + */
69227 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
69228 +
69229 + /* if we changed uid/gid, but result in the same role
69230 + and are using inheritance, don't lose the inherited subject
69231 + if current subject is other than what normal lookup
69232 + would result in, we arrived via inheritance, don't
69233 + lose subject
69234 + */
69235 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
69236 + (subj == task->acl)))
69237 + task->acl = subj;
69238 +
69239 + /* leave task->inherited unaffected */
69240 +
69241 + task->role = role;
69242 +
69243 + task->is_writable = 0;
69244 +
69245 + /* ignore additional mmap checks for processes that are writable
69246 + by the default ACL */
69247 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
69248 + if (unlikely(obj->mode & GR_WRITE))
69249 + task->is_writable = 1;
69250 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
69251 + if (unlikely(obj->mode & GR_WRITE))
69252 + task->is_writable = 1;
69253 +
69254 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
69255 + 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);
69256 +#endif
69257 +
69258 + gr_set_proc_res(task);
69259 +
69260 + return;
69261 +}
69262 +
69263 +int
69264 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
69265 + const int unsafe_flags)
69266 +{
69267 + struct task_struct *task = current;
69268 + struct acl_subject_label *newacl;
69269 + struct acl_object_label *obj;
69270 + __u32 retmode;
69271 +
69272 + if (unlikely(!(gr_status & GR_READY)))
69273 + return 0;
69274 +
69275 + newacl = chk_subj_label(dentry, mnt, task->role);
69276 +
69277 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
69278 + did an exec
69279 + */
69280 + rcu_read_lock();
69281 + read_lock(&tasklist_lock);
69282 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
69283 + (task->parent->acl->mode & GR_POVERRIDE))) {
69284 + read_unlock(&tasklist_lock);
69285 + rcu_read_unlock();
69286 + goto skip_check;
69287 + }
69288 + read_unlock(&tasklist_lock);
69289 + rcu_read_unlock();
69290 +
69291 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
69292 + !(task->role->roletype & GR_ROLE_GOD) &&
69293 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
69294 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
69295 + if (unsafe_flags & LSM_UNSAFE_SHARE)
69296 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
69297 + else
69298 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
69299 + return -EACCES;
69300 + }
69301 +
69302 +skip_check:
69303 +
69304 + obj = chk_obj_label(dentry, mnt, task->acl);
69305 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
69306 +
69307 + if (!(task->acl->mode & GR_INHERITLEARN) &&
69308 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
69309 + if (obj->nested)
69310 + task->acl = obj->nested;
69311 + else
69312 + task->acl = newacl;
69313 + task->inherited = 0;
69314 + } else {
69315 + task->inherited = 1;
69316 + if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
69317 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
69318 + }
69319 +
69320 + task->is_writable = 0;
69321 +
69322 + /* ignore additional mmap checks for processes that are writable
69323 + by the default ACL */
69324 + obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
69325 + if (unlikely(obj->mode & GR_WRITE))
69326 + task->is_writable = 1;
69327 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
69328 + if (unlikely(obj->mode & GR_WRITE))
69329 + task->is_writable = 1;
69330 +
69331 + gr_set_proc_res(task);
69332 +
69333 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
69334 + 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);
69335 +#endif
69336 + return 0;
69337 +}
69338 +
69339 +/* always called with valid inodev ptr */
69340 +static void
69341 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
69342 +{
69343 + struct acl_object_label *matchpo;
69344 + struct acl_subject_label *matchps;
69345 + struct acl_subject_label *subj;
69346 + struct acl_role_label *role;
69347 + unsigned int x;
69348 +
69349 + FOR_EACH_ROLE_START(role)
69350 + FOR_EACH_SUBJECT_START(role, subj, x)
69351 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
69352 + matchpo->mode |= GR_DELETED;
69353 + FOR_EACH_SUBJECT_END(subj,x)
69354 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
69355 + /* nested subjects aren't in the role's subj_hash table */
69356 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
69357 + matchpo->mode |= GR_DELETED;
69358 + FOR_EACH_NESTED_SUBJECT_END(subj)
69359 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
69360 + matchps->mode |= GR_DELETED;
69361 + FOR_EACH_ROLE_END(role)
69362 +
69363 + inodev->nentry->deleted = 1;
69364 +
69365 + return;
69366 +}
69367 +
69368 +void
69369 +gr_handle_delete(const ino_t ino, const dev_t dev)
69370 +{
69371 + struct inodev_entry *inodev;
69372 +
69373 + if (unlikely(!(gr_status & GR_READY)))
69374 + return;
69375 +
69376 + write_lock(&gr_inode_lock);
69377 + inodev = lookup_inodev_entry(ino, dev);
69378 + if (inodev != NULL)
69379 + do_handle_delete(inodev, ino, dev);
69380 + write_unlock(&gr_inode_lock);
69381 +
69382 + return;
69383 +}
69384 +
69385 +static void
69386 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
69387 + const ino_t newinode, const dev_t newdevice,
69388 + struct acl_subject_label *subj)
69389 +{
69390 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
69391 + struct acl_object_label *match;
69392 +
69393 + match = subj->obj_hash[index];
69394 +
69395 + while (match && (match->inode != oldinode ||
69396 + match->device != olddevice ||
69397 + !(match->mode & GR_DELETED)))
69398 + match = match->next;
69399 +
69400 + if (match && (match->inode == oldinode)
69401 + && (match->device == olddevice)
69402 + && (match->mode & GR_DELETED)) {
69403 + if (match->prev == NULL) {
69404 + subj->obj_hash[index] = match->next;
69405 + if (match->next != NULL)
69406 + match->next->prev = NULL;
69407 + } else {
69408 + match->prev->next = match->next;
69409 + if (match->next != NULL)
69410 + match->next->prev = match->prev;
69411 + }
69412 + match->prev = NULL;
69413 + match->next = NULL;
69414 + match->inode = newinode;
69415 + match->device = newdevice;
69416 + match->mode &= ~GR_DELETED;
69417 +
69418 + insert_acl_obj_label(match, subj);
69419 + }
69420 +
69421 + return;
69422 +}
69423 +
69424 +static void
69425 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
69426 + const ino_t newinode, const dev_t newdevice,
69427 + struct acl_role_label *role)
69428 +{
69429 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
69430 + struct acl_subject_label *match;
69431 +
69432 + match = role->subj_hash[index];
69433 +
69434 + while (match && (match->inode != oldinode ||
69435 + match->device != olddevice ||
69436 + !(match->mode & GR_DELETED)))
69437 + match = match->next;
69438 +
69439 + if (match && (match->inode == oldinode)
69440 + && (match->device == olddevice)
69441 + && (match->mode & GR_DELETED)) {
69442 + if (match->prev == NULL) {
69443 + role->subj_hash[index] = match->next;
69444 + if (match->next != NULL)
69445 + match->next->prev = NULL;
69446 + } else {
69447 + match->prev->next = match->next;
69448 + if (match->next != NULL)
69449 + match->next->prev = match->prev;
69450 + }
69451 + match->prev = NULL;
69452 + match->next = NULL;
69453 + match->inode = newinode;
69454 + match->device = newdevice;
69455 + match->mode &= ~GR_DELETED;
69456 +
69457 + insert_acl_subj_label(match, role);
69458 + }
69459 +
69460 + return;
69461 +}
69462 +
69463 +static void
69464 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
69465 + const ino_t newinode, const dev_t newdevice)
69466 +{
69467 + unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
69468 + struct inodev_entry *match;
69469 +
69470 + match = running_polstate.inodev_set.i_hash[index];
69471 +
69472 + while (match && (match->nentry->inode != oldinode ||
69473 + match->nentry->device != olddevice || !match->nentry->deleted))
69474 + match = match->next;
69475 +
69476 + if (match && (match->nentry->inode == oldinode)
69477 + && (match->nentry->device == olddevice) &&
69478 + match->nentry->deleted) {
69479 + if (match->prev == NULL) {
69480 + running_polstate.inodev_set.i_hash[index] = match->next;
69481 + if (match->next != NULL)
69482 + match->next->prev = NULL;
69483 + } else {
69484 + match->prev->next = match->next;
69485 + if (match->next != NULL)
69486 + match->next->prev = match->prev;
69487 + }
69488 + match->prev = NULL;
69489 + match->next = NULL;
69490 + match->nentry->inode = newinode;
69491 + match->nentry->device = newdevice;
69492 + match->nentry->deleted = 0;
69493 +
69494 + insert_inodev_entry(match);
69495 + }
69496 +
69497 + return;
69498 +}
69499 +
69500 +static void
69501 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
69502 +{
69503 + struct acl_subject_label *subj;
69504 + struct acl_role_label *role;
69505 + unsigned int x;
69506 +
69507 + FOR_EACH_ROLE_START(role)
69508 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
69509 +
69510 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
69511 + if ((subj->inode == ino) && (subj->device == dev)) {
69512 + subj->inode = ino;
69513 + subj->device = dev;
69514 + }
69515 + /* nested subjects aren't in the role's subj_hash table */
69516 + update_acl_obj_label(matchn->inode, matchn->device,
69517 + ino, dev, subj);
69518 + FOR_EACH_NESTED_SUBJECT_END(subj)
69519 + FOR_EACH_SUBJECT_START(role, subj, x)
69520 + update_acl_obj_label(matchn->inode, matchn->device,
69521 + ino, dev, subj);
69522 + FOR_EACH_SUBJECT_END(subj,x)
69523 + FOR_EACH_ROLE_END(role)
69524 +
69525 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
69526 +
69527 + return;
69528 +}
69529 +
69530 +static void
69531 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
69532 + const struct vfsmount *mnt)
69533 +{
69534 + ino_t ino = dentry->d_inode->i_ino;
69535 + dev_t dev = __get_dev(dentry);
69536 +
69537 + __do_handle_create(matchn, ino, dev);
69538 +
69539 + return;
69540 +}
69541 +
69542 +void
69543 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
69544 +{
69545 + struct name_entry *matchn;
69546 +
69547 + if (unlikely(!(gr_status & GR_READY)))
69548 + return;
69549 +
69550 + preempt_disable();
69551 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
69552 +
69553 + if (unlikely((unsigned long)matchn)) {
69554 + write_lock(&gr_inode_lock);
69555 + do_handle_create(matchn, dentry, mnt);
69556 + write_unlock(&gr_inode_lock);
69557 + }
69558 + preempt_enable();
69559 +
69560 + return;
69561 +}
69562 +
69563 +void
69564 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
69565 +{
69566 + struct name_entry *matchn;
69567 +
69568 + if (unlikely(!(gr_status & GR_READY)))
69569 + return;
69570 +
69571 + preempt_disable();
69572 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
69573 +
69574 + if (unlikely((unsigned long)matchn)) {
69575 + write_lock(&gr_inode_lock);
69576 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
69577 + write_unlock(&gr_inode_lock);
69578 + }
69579 + preempt_enable();
69580 +
69581 + return;
69582 +}
69583 +
69584 +void
69585 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
69586 + struct dentry *old_dentry,
69587 + struct dentry *new_dentry,
69588 + struct vfsmount *mnt, const __u8 replace, unsigned int flags)
69589 +{
69590 + struct name_entry *matchn;
69591 + struct name_entry *matchn2 = NULL;
69592 + struct inodev_entry *inodev;
69593 + struct inode *inode = new_dentry->d_inode;
69594 + ino_t old_ino = old_dentry->d_inode->i_ino;
69595 + dev_t old_dev = __get_dev(old_dentry);
69596 + unsigned int exchange = flags & RENAME_EXCHANGE;
69597 +
69598 + /* vfs_rename swaps the name and parent link for old_dentry and
69599 + new_dentry
69600 + at this point, old_dentry has the new name, parent link, and inode
69601 + for the renamed file
69602 + if a file is being replaced by a rename, new_dentry has the inode
69603 + and name for the replaced file
69604 + */
69605 +
69606 + if (unlikely(!(gr_status & GR_READY)))
69607 + return;
69608 +
69609 + preempt_disable();
69610 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
69611 +
69612 + /* exchange cases:
69613 + a filename exists for the source, but not dest
69614 + do a recreate on source
69615 + a filename exists for the dest, but not source
69616 + do a recreate on dest
69617 + a filename exists for both source and dest
69618 + delete source and dest, then create source and dest
69619 + a filename exists for neither source nor dest
69620 + no updates needed
69621 +
69622 + the name entry lookups get us the old inode/dev associated with
69623 + each name, so do the deletes first (if possible) so that when
69624 + we do the create, we pick up on the right entries
69625 + */
69626 +
69627 + if (exchange)
69628 + matchn2 = lookup_name_entry(gr_to_filename_rbac(new_dentry, mnt));
69629 +
69630 + /* we wouldn't have to check d_inode if it weren't for
69631 + NFS silly-renaming
69632 + */
69633 +
69634 + write_lock(&gr_inode_lock);
69635 + if (unlikely((replace || exchange) && inode)) {
69636 + ino_t new_ino = inode->i_ino;
69637 + dev_t new_dev = __get_dev(new_dentry);
69638 +
69639 + inodev = lookup_inodev_entry(new_ino, new_dev);
69640 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
69641 + do_handle_delete(inodev, new_ino, new_dev);
69642 + }
69643 +
69644 + inodev = lookup_inodev_entry(old_ino, old_dev);
69645 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
69646 + do_handle_delete(inodev, old_ino, old_dev);
69647 +
69648 + if (unlikely(matchn != NULL))
69649 + do_handle_create(matchn, old_dentry, mnt);
69650 +
69651 + if (unlikely(matchn2 != NULL))
69652 + do_handle_create(matchn2, new_dentry, mnt);
69653 +
69654 + write_unlock(&gr_inode_lock);
69655 + preempt_enable();
69656 +
69657 + return;
69658 +}
69659 +
69660 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
69661 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
69662 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
69663 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
69664 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
69665 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
69666 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
69667 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
69668 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
69669 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
69670 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
69671 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
69672 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
69673 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
69674 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
69675 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
69676 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
69677 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
69678 +};
69679 +
69680 +void
69681 +gr_learn_resource(const struct task_struct *task,
69682 + const int res, const unsigned long wanted, const int gt)
69683 +{
69684 + struct acl_subject_label *acl;
69685 + const struct cred *cred;
69686 +
69687 + if (unlikely((gr_status & GR_READY) &&
69688 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
69689 + goto skip_reslog;
69690 +
69691 + gr_log_resource(task, res, wanted, gt);
69692 +skip_reslog:
69693 +
69694 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
69695 + return;
69696 +
69697 + acl = task->acl;
69698 +
69699 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
69700 + !(acl->resmask & (1U << (unsigned short) res))))
69701 + return;
69702 +
69703 + if (wanted >= acl->res[res].rlim_cur) {
69704 + unsigned long res_add;
69705 +
69706 + res_add = wanted + res_learn_bumps[res];
69707 +
69708 + acl->res[res].rlim_cur = res_add;
69709 +
69710 + if (wanted > acl->res[res].rlim_max)
69711 + acl->res[res].rlim_max = res_add;
69712 +
69713 + /* only log the subject filename, since resource logging is supported for
69714 + single-subject learning only */
69715 + rcu_read_lock();
69716 + cred = __task_cred(task);
69717 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
69718 + task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
69719 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
69720 + "", (unsigned long) res, &task->signal->saved_ip);
69721 + rcu_read_unlock();
69722 + }
69723 +
69724 + return;
69725 +}
69726 +EXPORT_SYMBOL_GPL(gr_learn_resource);
69727 +#endif
69728 +
69729 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
69730 +void
69731 +pax_set_initial_flags(struct linux_binprm *bprm)
69732 +{
69733 + struct task_struct *task = current;
69734 + struct acl_subject_label *proc;
69735 + unsigned long flags;
69736 +
69737 + if (unlikely(!(gr_status & GR_READY)))
69738 + return;
69739 +
69740 + flags = pax_get_flags(task);
69741 +
69742 + proc = task->acl;
69743 +
69744 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
69745 + flags &= ~MF_PAX_PAGEEXEC;
69746 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
69747 + flags &= ~MF_PAX_SEGMEXEC;
69748 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
69749 + flags &= ~MF_PAX_RANDMMAP;
69750 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
69751 + flags &= ~MF_PAX_EMUTRAMP;
69752 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
69753 + flags &= ~MF_PAX_MPROTECT;
69754 +
69755 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
69756 + flags |= MF_PAX_PAGEEXEC;
69757 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
69758 + flags |= MF_PAX_SEGMEXEC;
69759 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
69760 + flags |= MF_PAX_RANDMMAP;
69761 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
69762 + flags |= MF_PAX_EMUTRAMP;
69763 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
69764 + flags |= MF_PAX_MPROTECT;
69765 +
69766 + pax_set_flags(task, flags);
69767 +
69768 + return;
69769 +}
69770 +#endif
69771 +
69772 +int
69773 +gr_handle_proc_ptrace(struct task_struct *task)
69774 +{
69775 + struct file *filp;
69776 + struct task_struct *tmp = task;
69777 + struct task_struct *curtemp = current;
69778 + __u32 retmode;
69779 +
69780 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
69781 + if (unlikely(!(gr_status & GR_READY)))
69782 + return 0;
69783 +#endif
69784 +
69785 + read_lock(&tasklist_lock);
69786 + read_lock(&grsec_exec_file_lock);
69787 + filp = task->exec_file;
69788 +
69789 + while (task_pid_nr(tmp) > 0) {
69790 + if (tmp == curtemp)
69791 + break;
69792 + tmp = tmp->real_parent;
69793 + }
69794 +
69795 + if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
69796 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
69797 + read_unlock(&grsec_exec_file_lock);
69798 + read_unlock(&tasklist_lock);
69799 + return 1;
69800 + }
69801 +
69802 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69803 + if (!(gr_status & GR_READY)) {
69804 + read_unlock(&grsec_exec_file_lock);
69805 + read_unlock(&tasklist_lock);
69806 + return 0;
69807 + }
69808 +#endif
69809 +
69810 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
69811 + read_unlock(&grsec_exec_file_lock);
69812 + read_unlock(&tasklist_lock);
69813 +
69814 + if (retmode & GR_NOPTRACE)
69815 + return 1;
69816 +
69817 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
69818 + && (current->acl != task->acl || (current->acl != current->role->root_label
69819 + && task_pid_nr(current) != task_pid_nr(task))))
69820 + return 1;
69821 +
69822 + return 0;
69823 +}
69824 +
69825 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
69826 +{
69827 + if (unlikely(!(gr_status & GR_READY)))
69828 + return;
69829 +
69830 + if (!(current->role->roletype & GR_ROLE_GOD))
69831 + return;
69832 +
69833 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
69834 + p->role->rolename, gr_task_roletype_to_char(p),
69835 + p->acl->filename);
69836 +}
69837 +
69838 +int
69839 +gr_handle_ptrace(struct task_struct *task, const long request)
69840 +{
69841 + struct task_struct *tmp = task;
69842 + struct task_struct *curtemp = current;
69843 + __u32 retmode;
69844 +
69845 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
69846 + if (unlikely(!(gr_status & GR_READY)))
69847 + return 0;
69848 +#endif
69849 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69850 + read_lock(&tasklist_lock);
69851 + while (task_pid_nr(tmp) > 0) {
69852 + if (tmp == curtemp)
69853 + break;
69854 + tmp = tmp->real_parent;
69855 + }
69856 +
69857 + if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
69858 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
69859 + read_unlock(&tasklist_lock);
69860 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69861 + return 1;
69862 + }
69863 + read_unlock(&tasklist_lock);
69864 + }
69865 +
69866 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69867 + if (!(gr_status & GR_READY))
69868 + return 0;
69869 +#endif
69870 +
69871 + read_lock(&grsec_exec_file_lock);
69872 + if (unlikely(!task->exec_file)) {
69873 + read_unlock(&grsec_exec_file_lock);
69874 + return 0;
69875 + }
69876 +
69877 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
69878 + read_unlock(&grsec_exec_file_lock);
69879 +
69880 + if (retmode & GR_NOPTRACE) {
69881 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69882 + return 1;
69883 + }
69884 +
69885 + if (retmode & GR_PTRACERD) {
69886 + switch (request) {
69887 + case PTRACE_SEIZE:
69888 + case PTRACE_POKETEXT:
69889 + case PTRACE_POKEDATA:
69890 + case PTRACE_POKEUSR:
69891 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
69892 + case PTRACE_SETREGS:
69893 + case PTRACE_SETFPREGS:
69894 +#endif
69895 +#ifdef CONFIG_X86
69896 + case PTRACE_SETFPXREGS:
69897 +#endif
69898 +#ifdef CONFIG_ALTIVEC
69899 + case PTRACE_SETVRREGS:
69900 +#endif
69901 + return 1;
69902 + default:
69903 + return 0;
69904 + }
69905 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
69906 + !(current->role->roletype & GR_ROLE_GOD) &&
69907 + (current->acl != task->acl)) {
69908 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69909 + return 1;
69910 + }
69911 +
69912 + return 0;
69913 +}
69914 +
69915 +static int is_writable_mmap(const struct file *filp)
69916 +{
69917 + struct task_struct *task = current;
69918 + struct acl_object_label *obj, *obj2;
69919 +
69920 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
69921 + !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))) {
69922 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
69923 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
69924 + task->role->root_label);
69925 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
69926 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
69927 + return 1;
69928 + }
69929 + }
69930 + return 0;
69931 +}
69932 +
69933 +int
69934 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
69935 +{
69936 + __u32 mode;
69937 +
69938 + if (unlikely(!file || !(prot & PROT_EXEC)))
69939 + return 1;
69940 +
69941 + if (is_writable_mmap(file))
69942 + return 0;
69943 +
69944 + mode =
69945 + gr_search_file(file->f_path.dentry,
69946 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
69947 + file->f_path.mnt);
69948 +
69949 + if (!gr_tpe_allow(file))
69950 + return 0;
69951 +
69952 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
69953 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69954 + return 0;
69955 + } else if (unlikely(!(mode & GR_EXEC))) {
69956 + return 0;
69957 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
69958 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69959 + return 1;
69960 + }
69961 +
69962 + return 1;
69963 +}
69964 +
69965 +int
69966 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
69967 +{
69968 + __u32 mode;
69969 +
69970 + if (unlikely(!file || !(prot & PROT_EXEC)))
69971 + return 1;
69972 +
69973 + if (is_writable_mmap(file))
69974 + return 0;
69975 +
69976 + mode =
69977 + gr_search_file(file->f_path.dentry,
69978 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
69979 + file->f_path.mnt);
69980 +
69981 + if (!gr_tpe_allow(file))
69982 + return 0;
69983 +
69984 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
69985 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69986 + return 0;
69987 + } else if (unlikely(!(mode & GR_EXEC))) {
69988 + return 0;
69989 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
69990 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69991 + return 1;
69992 + }
69993 +
69994 + return 1;
69995 +}
69996 +
69997 +void
69998 +gr_acl_handle_psacct(struct task_struct *task, const long code)
69999 +{
70000 + unsigned long runtime, cputime;
70001 + cputime_t utime, stime;
70002 + unsigned int wday, cday;
70003 + __u8 whr, chr;
70004 + __u8 wmin, cmin;
70005 + __u8 wsec, csec;
70006 + struct timespec timeval;
70007 +
70008 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
70009 + !(task->acl->mode & GR_PROCACCT)))
70010 + return;
70011 +
70012 + do_posix_clock_monotonic_gettime(&timeval);
70013 + runtime = timeval.tv_sec - task->start_time.tv_sec;
70014 + wday = runtime / (60 * 60 * 24);
70015 + runtime -= wday * (60 * 60 * 24);
70016 + whr = runtime / (60 * 60);
70017 + runtime -= whr * (60 * 60);
70018 + wmin = runtime / 60;
70019 + runtime -= wmin * 60;
70020 + wsec = runtime;
70021 +
70022 + task_cputime(task, &utime, &stime);
70023 + cputime = cputime_to_secs(utime + stime);
70024 + cday = cputime / (60 * 60 * 24);
70025 + cputime -= cday * (60 * 60 * 24);
70026 + chr = cputime / (60 * 60);
70027 + cputime -= chr * (60 * 60);
70028 + cmin = cputime / 60;
70029 + cputime -= cmin * 60;
70030 + csec = cputime;
70031 +
70032 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
70033 +
70034 + return;
70035 +}
70036 +
70037 +#ifdef CONFIG_TASKSTATS
70038 +int gr_is_taskstats_denied(int pid)
70039 +{
70040 + struct task_struct *task;
70041 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70042 + const struct cred *cred;
70043 +#endif
70044 + int ret = 0;
70045 +
70046 + /* restrict taskstats viewing to un-chrooted root users
70047 + who have the 'view' subject flag if the RBAC system is enabled
70048 + */
70049 +
70050 + rcu_read_lock();
70051 + read_lock(&tasklist_lock);
70052 + task = find_task_by_vpid(pid);
70053 + if (task) {
70054 +#ifdef CONFIG_GRKERNSEC_CHROOT
70055 + if (proc_is_chrooted(task))
70056 + ret = -EACCES;
70057 +#endif
70058 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70059 + cred = __task_cred(task);
70060 +#ifdef CONFIG_GRKERNSEC_PROC_USER
70061 + if (gr_is_global_nonroot(cred->uid))
70062 + ret = -EACCES;
70063 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70064 + if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
70065 + ret = -EACCES;
70066 +#endif
70067 +#endif
70068 + if (gr_status & GR_READY) {
70069 + if (!(task->acl->mode & GR_VIEW))
70070 + ret = -EACCES;
70071 + }
70072 + } else
70073 + ret = -ENOENT;
70074 +
70075 + read_unlock(&tasklist_lock);
70076 + rcu_read_unlock();
70077 +
70078 + return ret;
70079 +}
70080 +#endif
70081 +
70082 +/* AUXV entries are filled via a descendant of search_binary_handler
70083 + after we've already applied the subject for the target
70084 +*/
70085 +int gr_acl_enable_at_secure(void)
70086 +{
70087 + if (unlikely(!(gr_status & GR_READY)))
70088 + return 0;
70089 +
70090 + if (current->acl->mode & GR_ATSECURE)
70091 + return 1;
70092 +
70093 + return 0;
70094 +}
70095 +
70096 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
70097 +{
70098 + struct task_struct *task = current;
70099 + struct dentry *dentry = file->f_path.dentry;
70100 + struct vfsmount *mnt = file->f_path.mnt;
70101 + struct acl_object_label *obj, *tmp;
70102 + struct acl_subject_label *subj;
70103 + unsigned int bufsize;
70104 + int is_not_root;
70105 + char *path;
70106 + dev_t dev = __get_dev(dentry);
70107 +
70108 + if (unlikely(!(gr_status & GR_READY)))
70109 + return 1;
70110 +
70111 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
70112 + return 1;
70113 +
70114 + /* ignore Eric Biederman */
70115 + if (IS_PRIVATE(dentry->d_inode))
70116 + return 1;
70117 +
70118 + subj = task->acl;
70119 + read_lock(&gr_inode_lock);
70120 + do {
70121 + obj = lookup_acl_obj_label(ino, dev, subj);
70122 + if (obj != NULL) {
70123 + read_unlock(&gr_inode_lock);
70124 + return (obj->mode & GR_FIND) ? 1 : 0;
70125 + }
70126 + } while ((subj = subj->parent_subject));
70127 + read_unlock(&gr_inode_lock);
70128 +
70129 + /* this is purely an optimization since we're looking for an object
70130 + for the directory we're doing a readdir on
70131 + if it's possible for any globbed object to match the entry we're
70132 + filling into the directory, then the object we find here will be
70133 + an anchor point with attached globbed objects
70134 + */
70135 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
70136 + if (obj->globbed == NULL)
70137 + return (obj->mode & GR_FIND) ? 1 : 0;
70138 +
70139 + is_not_root = ((obj->filename[0] == '/') &&
70140 + (obj->filename[1] == '\0')) ? 0 : 1;
70141 + bufsize = PAGE_SIZE - namelen - is_not_root;
70142 +
70143 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
70144 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
70145 + return 1;
70146 +
70147 + preempt_disable();
70148 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
70149 + bufsize);
70150 +
70151 + bufsize = strlen(path);
70152 +
70153 + /* if base is "/", don't append an additional slash */
70154 + if (is_not_root)
70155 + *(path + bufsize) = '/';
70156 + memcpy(path + bufsize + is_not_root, name, namelen);
70157 + *(path + bufsize + namelen + is_not_root) = '\0';
70158 +
70159 + tmp = obj->globbed;
70160 + while (tmp) {
70161 + if (!glob_match(tmp->filename, path)) {
70162 + preempt_enable();
70163 + return (tmp->mode & GR_FIND) ? 1 : 0;
70164 + }
70165 + tmp = tmp->next;
70166 + }
70167 + preempt_enable();
70168 + return (obj->mode & GR_FIND) ? 1 : 0;
70169 +}
70170 +
70171 +void gr_put_exec_file(struct task_struct *task)
70172 +{
70173 + struct file *filp;
70174 +
70175 + write_lock(&grsec_exec_file_lock);
70176 + filp = task->exec_file;
70177 + task->exec_file = NULL;
70178 + write_unlock(&grsec_exec_file_lock);
70179 +
70180 + if (filp)
70181 + fput(filp);
70182 +
70183 + return;
70184 +}
70185 +
70186 +
70187 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
70188 +EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
70189 +#endif
70190 +#ifdef CONFIG_SECURITY
70191 +EXPORT_SYMBOL_GPL(gr_check_user_change);
70192 +EXPORT_SYMBOL_GPL(gr_check_group_change);
70193 +#endif
70194 +
70195 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
70196 new file mode 100644
70197 index 0000000..18ffbbd
70198 --- /dev/null
70199 +++ b/grsecurity/gracl_alloc.c
70200 @@ -0,0 +1,105 @@
70201 +#include <linux/kernel.h>
70202 +#include <linux/mm.h>
70203 +#include <linux/slab.h>
70204 +#include <linux/vmalloc.h>
70205 +#include <linux/gracl.h>
70206 +#include <linux/grsecurity.h>
70207 +
70208 +static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
70209 +struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
70210 +
70211 +static __inline__ int
70212 +alloc_pop(void)
70213 +{
70214 + if (current_alloc_state->alloc_stack_next == 1)
70215 + return 0;
70216 +
70217 + kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
70218 +
70219 + current_alloc_state->alloc_stack_next--;
70220 +
70221 + return 1;
70222 +}
70223 +
70224 +static __inline__ int
70225 +alloc_push(void *buf)
70226 +{
70227 + if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
70228 + return 1;
70229 +
70230 + current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
70231 +
70232 + current_alloc_state->alloc_stack_next++;
70233 +
70234 + return 0;
70235 +}
70236 +
70237 +void *
70238 +acl_alloc(unsigned long len)
70239 +{
70240 + void *ret = NULL;
70241 +
70242 + if (!len || len > PAGE_SIZE)
70243 + goto out;
70244 +
70245 + ret = kmalloc(len, GFP_KERNEL);
70246 +
70247 + if (ret) {
70248 + if (alloc_push(ret)) {
70249 + kfree(ret);
70250 + ret = NULL;
70251 + }
70252 + }
70253 +
70254 +out:
70255 + return ret;
70256 +}
70257 +
70258 +void *
70259 +acl_alloc_num(unsigned long num, unsigned long len)
70260 +{
70261 + if (!len || (num > (PAGE_SIZE / len)))
70262 + return NULL;
70263 +
70264 + return acl_alloc(num * len);
70265 +}
70266 +
70267 +void
70268 +acl_free_all(void)
70269 +{
70270 + if (!current_alloc_state->alloc_stack)
70271 + return;
70272 +
70273 + while (alloc_pop()) ;
70274 +
70275 + if (current_alloc_state->alloc_stack) {
70276 + if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
70277 + kfree(current_alloc_state->alloc_stack);
70278 + else
70279 + vfree(current_alloc_state->alloc_stack);
70280 + }
70281 +
70282 + current_alloc_state->alloc_stack = NULL;
70283 + current_alloc_state->alloc_stack_size = 1;
70284 + current_alloc_state->alloc_stack_next = 1;
70285 +
70286 + return;
70287 +}
70288 +
70289 +int
70290 +acl_alloc_stack_init(unsigned long size)
70291 +{
70292 + if ((size * sizeof (void *)) <= PAGE_SIZE)
70293 + current_alloc_state->alloc_stack =
70294 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
70295 + else
70296 + current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
70297 +
70298 + current_alloc_state->alloc_stack_size = size;
70299 + current_alloc_state->alloc_stack_next = 1;
70300 +
70301 + if (!current_alloc_state->alloc_stack)
70302 + return 0;
70303 + else
70304 + return 1;
70305 +}
70306 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
70307 new file mode 100644
70308 index 0000000..bdd51ea
70309 --- /dev/null
70310 +++ b/grsecurity/gracl_cap.c
70311 @@ -0,0 +1,110 @@
70312 +#include <linux/kernel.h>
70313 +#include <linux/module.h>
70314 +#include <linux/sched.h>
70315 +#include <linux/gracl.h>
70316 +#include <linux/grsecurity.h>
70317 +#include <linux/grinternal.h>
70318 +
70319 +extern const char *captab_log[];
70320 +extern int captab_log_entries;
70321 +
70322 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
70323 +{
70324 + struct acl_subject_label *curracl;
70325 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
70326 + kernel_cap_t cap_audit = __cap_empty_set;
70327 +
70328 + if (!gr_acl_is_enabled())
70329 + return 1;
70330 +
70331 + curracl = task->acl;
70332 +
70333 + cap_drop = curracl->cap_lower;
70334 + cap_mask = curracl->cap_mask;
70335 + cap_audit = curracl->cap_invert_audit;
70336 +
70337 + while ((curracl = curracl->parent_subject)) {
70338 + /* if the cap isn't specified in the current computed mask but is specified in the
70339 + current level subject, and is lowered in the current level subject, then add
70340 + it to the set of dropped capabilities
70341 + otherwise, add the current level subject's mask to the current computed mask
70342 + */
70343 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
70344 + cap_raise(cap_mask, cap);
70345 + if (cap_raised(curracl->cap_lower, cap))
70346 + cap_raise(cap_drop, cap);
70347 + if (cap_raised(curracl->cap_invert_audit, cap))
70348 + cap_raise(cap_audit, cap);
70349 + }
70350 + }
70351 +
70352 + if (!cap_raised(cap_drop, cap)) {
70353 + if (cap_raised(cap_audit, cap))
70354 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
70355 + return 1;
70356 + }
70357 +
70358 + curracl = task->acl;
70359 +
70360 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
70361 + && cap_raised(cred->cap_effective, cap)) {
70362 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
70363 + task->role->roletype, GR_GLOBAL_UID(cred->uid),
70364 + GR_GLOBAL_GID(cred->gid), task->exec_file ?
70365 + gr_to_filename(task->exec_file->f_path.dentry,
70366 + task->exec_file->f_path.mnt) : curracl->filename,
70367 + curracl->filename, 0UL,
70368 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
70369 + return 1;
70370 + }
70371 +
70372 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
70373 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
70374 +
70375 + return 0;
70376 +}
70377 +
70378 +int
70379 +gr_acl_is_capable(const int cap)
70380 +{
70381 + return gr_task_acl_is_capable(current, current_cred(), cap);
70382 +}
70383 +
70384 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
70385 +{
70386 + struct acl_subject_label *curracl;
70387 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
70388 +
70389 + if (!gr_acl_is_enabled())
70390 + return 1;
70391 +
70392 + curracl = task->acl;
70393 +
70394 + cap_drop = curracl->cap_lower;
70395 + cap_mask = curracl->cap_mask;
70396 +
70397 + while ((curracl = curracl->parent_subject)) {
70398 + /* if the cap isn't specified in the current computed mask but is specified in the
70399 + current level subject, and is lowered in the current level subject, then add
70400 + it to the set of dropped capabilities
70401 + otherwise, add the current level subject's mask to the current computed mask
70402 + */
70403 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
70404 + cap_raise(cap_mask, cap);
70405 + if (cap_raised(curracl->cap_lower, cap))
70406 + cap_raise(cap_drop, cap);
70407 + }
70408 + }
70409 +
70410 + if (!cap_raised(cap_drop, cap))
70411 + return 1;
70412 +
70413 + return 0;
70414 +}
70415 +
70416 +int
70417 +gr_acl_is_capable_nolog(const int cap)
70418 +{
70419 + return gr_task_acl_is_capable_nolog(current, cap);
70420 +}
70421 +
70422 diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
70423 new file mode 100644
70424 index 0000000..ca25605
70425 --- /dev/null
70426 +++ b/grsecurity/gracl_compat.c
70427 @@ -0,0 +1,270 @@
70428 +#include <linux/kernel.h>
70429 +#include <linux/gracl.h>
70430 +#include <linux/compat.h>
70431 +#include <linux/gracl_compat.h>
70432 +
70433 +#include <asm/uaccess.h>
70434 +
70435 +int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
70436 +{
70437 + struct gr_arg_wrapper_compat uwrapcompat;
70438 +
70439 + if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
70440 + return -EFAULT;
70441 +
70442 + if (((uwrapcompat.version != GRSECURITY_VERSION) &&
70443 + (uwrapcompat.version != 0x2901)) ||
70444 + (uwrapcompat.size != sizeof(struct gr_arg_compat)))
70445 + return -EINVAL;
70446 +
70447 + uwrap->arg = compat_ptr(uwrapcompat.arg);
70448 + uwrap->version = uwrapcompat.version;
70449 + uwrap->size = sizeof(struct gr_arg);
70450 +
70451 + return 0;
70452 +}
70453 +
70454 +int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
70455 +{
70456 + struct gr_arg_compat argcompat;
70457 +
70458 + if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
70459 + return -EFAULT;
70460 +
70461 + arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
70462 + arg->role_db.num_pointers = argcompat.role_db.num_pointers;
70463 + arg->role_db.num_roles = argcompat.role_db.num_roles;
70464 + arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
70465 + arg->role_db.num_subjects = argcompat.role_db.num_subjects;
70466 + arg->role_db.num_objects = argcompat.role_db.num_objects;
70467 +
70468 + memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
70469 + memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
70470 + memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
70471 + memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
70472 + arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
70473 + arg->segv_device = argcompat.segv_device;
70474 + arg->segv_inode = argcompat.segv_inode;
70475 + arg->segv_uid = argcompat.segv_uid;
70476 + arg->num_sprole_pws = argcompat.num_sprole_pws;
70477 + arg->mode = argcompat.mode;
70478 +
70479 + return 0;
70480 +}
70481 +
70482 +int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
70483 +{
70484 + struct acl_object_label_compat objcompat;
70485 +
70486 + if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
70487 + return -EFAULT;
70488 +
70489 + obj->filename = compat_ptr(objcompat.filename);
70490 + obj->inode = objcompat.inode;
70491 + obj->device = objcompat.device;
70492 + obj->mode = objcompat.mode;
70493 +
70494 + obj->nested = compat_ptr(objcompat.nested);
70495 + obj->globbed = compat_ptr(objcompat.globbed);
70496 +
70497 + obj->prev = compat_ptr(objcompat.prev);
70498 + obj->next = compat_ptr(objcompat.next);
70499 +
70500 + return 0;
70501 +}
70502 +
70503 +int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
70504 +{
70505 + unsigned int i;
70506 + struct acl_subject_label_compat subjcompat;
70507 +
70508 + if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
70509 + return -EFAULT;
70510 +
70511 + subj->filename = compat_ptr(subjcompat.filename);
70512 + subj->inode = subjcompat.inode;
70513 + subj->device = subjcompat.device;
70514 + subj->mode = subjcompat.mode;
70515 + subj->cap_mask = subjcompat.cap_mask;
70516 + subj->cap_lower = subjcompat.cap_lower;
70517 + subj->cap_invert_audit = subjcompat.cap_invert_audit;
70518 +
70519 + for (i = 0; i < GR_NLIMITS; i++) {
70520 + if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
70521 + subj->res[i].rlim_cur = RLIM_INFINITY;
70522 + else
70523 + subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
70524 + if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
70525 + subj->res[i].rlim_max = RLIM_INFINITY;
70526 + else
70527 + subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
70528 + }
70529 + subj->resmask = subjcompat.resmask;
70530 +
70531 + subj->user_trans_type = subjcompat.user_trans_type;
70532 + subj->group_trans_type = subjcompat.group_trans_type;
70533 + subj->user_transitions = compat_ptr(subjcompat.user_transitions);
70534 + subj->group_transitions = compat_ptr(subjcompat.group_transitions);
70535 + subj->user_trans_num = subjcompat.user_trans_num;
70536 + subj->group_trans_num = subjcompat.group_trans_num;
70537 +
70538 + memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
70539 + memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
70540 + subj->ip_type = subjcompat.ip_type;
70541 + subj->ips = compat_ptr(subjcompat.ips);
70542 + subj->ip_num = subjcompat.ip_num;
70543 + subj->inaddr_any_override = subjcompat.inaddr_any_override;
70544 +
70545 + subj->crashes = subjcompat.crashes;
70546 + subj->expires = subjcompat.expires;
70547 +
70548 + subj->parent_subject = compat_ptr(subjcompat.parent_subject);
70549 + subj->hash = compat_ptr(subjcompat.hash);
70550 + subj->prev = compat_ptr(subjcompat.prev);
70551 + subj->next = compat_ptr(subjcompat.next);
70552 +
70553 + subj->obj_hash = compat_ptr(subjcompat.obj_hash);
70554 + subj->obj_hash_size = subjcompat.obj_hash_size;
70555 + subj->pax_flags = subjcompat.pax_flags;
70556 +
70557 + return 0;
70558 +}
70559 +
70560 +int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
70561 +{
70562 + struct acl_role_label_compat rolecompat;
70563 +
70564 + if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
70565 + return -EFAULT;
70566 +
70567 + role->rolename = compat_ptr(rolecompat.rolename);
70568 + role->uidgid = rolecompat.uidgid;
70569 + role->roletype = rolecompat.roletype;
70570 +
70571 + role->auth_attempts = rolecompat.auth_attempts;
70572 + role->expires = rolecompat.expires;
70573 +
70574 + role->root_label = compat_ptr(rolecompat.root_label);
70575 + role->hash = compat_ptr(rolecompat.hash);
70576 +
70577 + role->prev = compat_ptr(rolecompat.prev);
70578 + role->next = compat_ptr(rolecompat.next);
70579 +
70580 + role->transitions = compat_ptr(rolecompat.transitions);
70581 + role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
70582 + role->domain_children = compat_ptr(rolecompat.domain_children);
70583 + role->domain_child_num = rolecompat.domain_child_num;
70584 +
70585 + role->umask = rolecompat.umask;
70586 +
70587 + role->subj_hash = compat_ptr(rolecompat.subj_hash);
70588 + role->subj_hash_size = rolecompat.subj_hash_size;
70589 +
70590 + return 0;
70591 +}
70592 +
70593 +int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
70594 +{
70595 + struct role_allowed_ip_compat roleip_compat;
70596 +
70597 + if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
70598 + return -EFAULT;
70599 +
70600 + roleip->addr = roleip_compat.addr;
70601 + roleip->netmask = roleip_compat.netmask;
70602 +
70603 + roleip->prev = compat_ptr(roleip_compat.prev);
70604 + roleip->next = compat_ptr(roleip_compat.next);
70605 +
70606 + return 0;
70607 +}
70608 +
70609 +int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
70610 +{
70611 + struct role_transition_compat trans_compat;
70612 +
70613 + if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
70614 + return -EFAULT;
70615 +
70616 + trans->rolename = compat_ptr(trans_compat.rolename);
70617 +
70618 + trans->prev = compat_ptr(trans_compat.prev);
70619 + trans->next = compat_ptr(trans_compat.next);
70620 +
70621 + return 0;
70622 +
70623 +}
70624 +
70625 +int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
70626 +{
70627 + struct gr_hash_struct_compat hash_compat;
70628 +
70629 + if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
70630 + return -EFAULT;
70631 +
70632 + hash->table = compat_ptr(hash_compat.table);
70633 + hash->nametable = compat_ptr(hash_compat.nametable);
70634 + hash->first = compat_ptr(hash_compat.first);
70635 +
70636 + hash->table_size = hash_compat.table_size;
70637 + hash->used_size = hash_compat.used_size;
70638 +
70639 + hash->type = hash_compat.type;
70640 +
70641 + return 0;
70642 +}
70643 +
70644 +int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
70645 +{
70646 + compat_uptr_t ptrcompat;
70647 +
70648 + if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
70649 + return -EFAULT;
70650 +
70651 + *(void **)ptr = compat_ptr(ptrcompat);
70652 +
70653 + return 0;
70654 +}
70655 +
70656 +int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
70657 +{
70658 + struct acl_ip_label_compat ip_compat;
70659 +
70660 + if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
70661 + return -EFAULT;
70662 +
70663 + ip->iface = compat_ptr(ip_compat.iface);
70664 + ip->addr = ip_compat.addr;
70665 + ip->netmask = ip_compat.netmask;
70666 + ip->low = ip_compat.low;
70667 + ip->high = ip_compat.high;
70668 + ip->mode = ip_compat.mode;
70669 + ip->type = ip_compat.type;
70670 +
70671 + memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
70672 +
70673 + ip->prev = compat_ptr(ip_compat.prev);
70674 + ip->next = compat_ptr(ip_compat.next);
70675 +
70676 + return 0;
70677 +}
70678 +
70679 +int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
70680 +{
70681 + struct sprole_pw_compat pw_compat;
70682 +
70683 + if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
70684 + return -EFAULT;
70685 +
70686 + pw->rolename = compat_ptr(pw_compat.rolename);
70687 + memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
70688 + memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
70689 +
70690 + return 0;
70691 +}
70692 +
70693 +size_t get_gr_arg_wrapper_size_compat(void)
70694 +{
70695 + return sizeof(struct gr_arg_wrapper_compat);
70696 +}
70697 +
70698 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
70699 new file mode 100644
70700 index 0000000..4008fdc
70701 --- /dev/null
70702 +++ b/grsecurity/gracl_fs.c
70703 @@ -0,0 +1,445 @@
70704 +#include <linux/kernel.h>
70705 +#include <linux/sched.h>
70706 +#include <linux/types.h>
70707 +#include <linux/fs.h>
70708 +#include <linux/file.h>
70709 +#include <linux/stat.h>
70710 +#include <linux/grsecurity.h>
70711 +#include <linux/grinternal.h>
70712 +#include <linux/gracl.h>
70713 +
70714 +umode_t
70715 +gr_acl_umask(void)
70716 +{
70717 + if (unlikely(!gr_acl_is_enabled()))
70718 + return 0;
70719 +
70720 + return current->role->umask;
70721 +}
70722 +
70723 +__u32
70724 +gr_acl_handle_hidden_file(const struct dentry * dentry,
70725 + const struct vfsmount * mnt)
70726 +{
70727 + __u32 mode;
70728 +
70729 + if (unlikely(d_is_negative(dentry)))
70730 + return GR_FIND;
70731 +
70732 + mode =
70733 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
70734 +
70735 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
70736 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
70737 + return mode;
70738 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
70739 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
70740 + return 0;
70741 + } else if (unlikely(!(mode & GR_FIND)))
70742 + return 0;
70743 +
70744 + return GR_FIND;
70745 +}
70746 +
70747 +__u32
70748 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
70749 + int acc_mode)
70750 +{
70751 + __u32 reqmode = GR_FIND;
70752 + __u32 mode;
70753 +
70754 + if (unlikely(d_is_negative(dentry)))
70755 + return reqmode;
70756 +
70757 + if (acc_mode & MAY_APPEND)
70758 + reqmode |= GR_APPEND;
70759 + else if (acc_mode & MAY_WRITE)
70760 + reqmode |= GR_WRITE;
70761 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
70762 + reqmode |= GR_READ;
70763 +
70764 + mode =
70765 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
70766 + mnt);
70767 +
70768 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70769 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
70770 + reqmode & GR_READ ? " reading" : "",
70771 + reqmode & GR_WRITE ? " writing" : reqmode &
70772 + GR_APPEND ? " appending" : "");
70773 + return reqmode;
70774 + } else
70775 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70776 + {
70777 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
70778 + reqmode & GR_READ ? " reading" : "",
70779 + reqmode & GR_WRITE ? " writing" : reqmode &
70780 + GR_APPEND ? " appending" : "");
70781 + return 0;
70782 + } else if (unlikely((mode & reqmode) != reqmode))
70783 + return 0;
70784 +
70785 + return reqmode;
70786 +}
70787 +
70788 +__u32
70789 +gr_acl_handle_creat(const struct dentry * dentry,
70790 + const struct dentry * p_dentry,
70791 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
70792 + const int imode)
70793 +{
70794 + __u32 reqmode = GR_WRITE | GR_CREATE;
70795 + __u32 mode;
70796 +
70797 + if (acc_mode & MAY_APPEND)
70798 + reqmode |= GR_APPEND;
70799 + // if a directory was required or the directory already exists, then
70800 + // don't count this open as a read
70801 + if ((acc_mode & MAY_READ) &&
70802 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
70803 + reqmode |= GR_READ;
70804 + if ((open_flags & O_CREAT) &&
70805 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
70806 + reqmode |= GR_SETID;
70807 +
70808 + mode =
70809 + gr_check_create(dentry, p_dentry, p_mnt,
70810 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
70811 +
70812 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70813 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
70814 + reqmode & GR_READ ? " reading" : "",
70815 + reqmode & GR_WRITE ? " writing" : reqmode &
70816 + GR_APPEND ? " appending" : "");
70817 + return reqmode;
70818 + } else
70819 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70820 + {
70821 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
70822 + reqmode & GR_READ ? " reading" : "",
70823 + reqmode & GR_WRITE ? " writing" : reqmode &
70824 + GR_APPEND ? " appending" : "");
70825 + return 0;
70826 + } else if (unlikely((mode & reqmode) != reqmode))
70827 + return 0;
70828 +
70829 + return reqmode;
70830 +}
70831 +
70832 +__u32
70833 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
70834 + const int fmode)
70835 +{
70836 + __u32 mode, reqmode = GR_FIND;
70837 +
70838 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
70839 + reqmode |= GR_EXEC;
70840 + if (fmode & S_IWOTH)
70841 + reqmode |= GR_WRITE;
70842 + if (fmode & S_IROTH)
70843 + reqmode |= GR_READ;
70844 +
70845 + mode =
70846 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
70847 + mnt);
70848 +
70849 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70850 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
70851 + reqmode & GR_READ ? " reading" : "",
70852 + reqmode & GR_WRITE ? " writing" : "",
70853 + reqmode & GR_EXEC ? " executing" : "");
70854 + return reqmode;
70855 + } else
70856 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70857 + {
70858 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
70859 + reqmode & GR_READ ? " reading" : "",
70860 + reqmode & GR_WRITE ? " writing" : "",
70861 + reqmode & GR_EXEC ? " executing" : "");
70862 + return 0;
70863 + } else if (unlikely((mode & reqmode) != reqmode))
70864 + return 0;
70865 +
70866 + return reqmode;
70867 +}
70868 +
70869 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
70870 +{
70871 + __u32 mode;
70872 +
70873 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
70874 +
70875 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
70876 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
70877 + return mode;
70878 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
70879 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
70880 + return 0;
70881 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
70882 + return 0;
70883 +
70884 + return (reqmode);
70885 +}
70886 +
70887 +__u32
70888 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
70889 +{
70890 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
70891 +}
70892 +
70893 +__u32
70894 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
70895 +{
70896 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
70897 +}
70898 +
70899 +__u32
70900 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
70901 +{
70902 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
70903 +}
70904 +
70905 +__u32
70906 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
70907 +{
70908 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
70909 +}
70910 +
70911 +__u32
70912 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
70913 + umode_t *modeptr)
70914 +{
70915 + umode_t mode;
70916 +
70917 + *modeptr &= ~gr_acl_umask();
70918 + mode = *modeptr;
70919 +
70920 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
70921 + return 1;
70922 +
70923 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
70924 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
70925 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
70926 + GR_CHMOD_ACL_MSG);
70927 + } else {
70928 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
70929 + }
70930 +}
70931 +
70932 +__u32
70933 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
70934 +{
70935 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
70936 +}
70937 +
70938 +__u32
70939 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
70940 +{
70941 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
70942 +}
70943 +
70944 +__u32
70945 +gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
70946 +{
70947 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
70948 +}
70949 +
70950 +__u32
70951 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
70952 +{
70953 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
70954 +}
70955 +
70956 +__u32
70957 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
70958 +{
70959 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
70960 + GR_UNIXCONNECT_ACL_MSG);
70961 +}
70962 +
70963 +/* hardlinks require at minimum create and link permission,
70964 + any additional privilege required is based on the
70965 + privilege of the file being linked to
70966 +*/
70967 +__u32
70968 +gr_acl_handle_link(const struct dentry * new_dentry,
70969 + const struct dentry * parent_dentry,
70970 + const struct vfsmount * parent_mnt,
70971 + const struct dentry * old_dentry,
70972 + const struct vfsmount * old_mnt, const struct filename *to)
70973 +{
70974 + __u32 mode;
70975 + __u32 needmode = GR_CREATE | GR_LINK;
70976 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
70977 +
70978 + mode =
70979 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
70980 + old_mnt);
70981 +
70982 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
70983 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
70984 + return mode;
70985 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
70986 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
70987 + return 0;
70988 + } else if (unlikely((mode & needmode) != needmode))
70989 + return 0;
70990 +
70991 + return 1;
70992 +}
70993 +
70994 +__u32
70995 +gr_acl_handle_symlink(const struct dentry * new_dentry,
70996 + const struct dentry * parent_dentry,
70997 + const struct vfsmount * parent_mnt, const struct filename *from)
70998 +{
70999 + __u32 needmode = GR_WRITE | GR_CREATE;
71000 + __u32 mode;
71001 +
71002 + mode =
71003 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
71004 + GR_CREATE | GR_AUDIT_CREATE |
71005 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
71006 +
71007 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
71008 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
71009 + return mode;
71010 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
71011 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
71012 + return 0;
71013 + } else if (unlikely((mode & needmode) != needmode))
71014 + return 0;
71015 +
71016 + return (GR_WRITE | GR_CREATE);
71017 +}
71018 +
71019 +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)
71020 +{
71021 + __u32 mode;
71022 +
71023 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
71024 +
71025 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
71026 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
71027 + return mode;
71028 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
71029 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
71030 + return 0;
71031 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
71032 + return 0;
71033 +
71034 + return (reqmode);
71035 +}
71036 +
71037 +__u32
71038 +gr_acl_handle_mknod(const struct dentry * new_dentry,
71039 + const struct dentry * parent_dentry,
71040 + const struct vfsmount * parent_mnt,
71041 + const int mode)
71042 +{
71043 + __u32 reqmode = GR_WRITE | GR_CREATE;
71044 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
71045 + reqmode |= GR_SETID;
71046 +
71047 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
71048 + reqmode, GR_MKNOD_ACL_MSG);
71049 +}
71050 +
71051 +__u32
71052 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
71053 + const struct dentry *parent_dentry,
71054 + const struct vfsmount *parent_mnt)
71055 +{
71056 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
71057 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
71058 +}
71059 +
71060 +#define RENAME_CHECK_SUCCESS(old, new) \
71061 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
71062 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
71063 +
71064 +int
71065 +gr_acl_handle_rename(struct dentry *new_dentry,
71066 + struct dentry *parent_dentry,
71067 + const struct vfsmount *parent_mnt,
71068 + struct dentry *old_dentry,
71069 + struct inode *old_parent_inode,
71070 + struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags)
71071 +{
71072 + __u32 comp1, comp2;
71073 + int error = 0;
71074 +
71075 + if (unlikely(!gr_acl_is_enabled()))
71076 + return 0;
71077 +
71078 + if (flags & RENAME_EXCHANGE) {
71079 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
71080 + GR_AUDIT_READ | GR_AUDIT_WRITE |
71081 + GR_SUPPRESS, parent_mnt);
71082 + comp2 =
71083 + gr_search_file(old_dentry,
71084 + GR_READ | GR_WRITE | GR_AUDIT_READ |
71085 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
71086 + } else if (d_is_negative(new_dentry)) {
71087 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
71088 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
71089 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
71090 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
71091 + GR_DELETE | GR_AUDIT_DELETE |
71092 + GR_AUDIT_READ | GR_AUDIT_WRITE |
71093 + GR_SUPPRESS, old_mnt);
71094 + } else {
71095 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
71096 + GR_CREATE | GR_DELETE |
71097 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
71098 + GR_AUDIT_READ | GR_AUDIT_WRITE |
71099 + GR_SUPPRESS, parent_mnt);
71100 + comp2 =
71101 + gr_search_file(old_dentry,
71102 + GR_READ | GR_WRITE | GR_AUDIT_READ |
71103 + GR_DELETE | GR_AUDIT_DELETE |
71104 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
71105 + }
71106 +
71107 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
71108 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
71109 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
71110 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
71111 + && !(comp2 & GR_SUPPRESS)) {
71112 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
71113 + error = -EACCES;
71114 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
71115 + error = -EACCES;
71116 +
71117 + return error;
71118 +}
71119 +
71120 +void
71121 +gr_acl_handle_exit(void)
71122 +{
71123 + u16 id;
71124 + char *rolename;
71125 +
71126 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
71127 + !(current->role->roletype & GR_ROLE_PERSIST))) {
71128 + id = current->acl_role_id;
71129 + rolename = current->role->rolename;
71130 + gr_set_acls(1);
71131 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
71132 + }
71133 +
71134 + gr_put_exec_file(current);
71135 + return;
71136 +}
71137 +
71138 +int
71139 +gr_acl_handle_procpidmem(const struct task_struct *task)
71140 +{
71141 + if (unlikely(!gr_acl_is_enabled()))
71142 + return 0;
71143 +
71144 + if (task != current && task->acl->mode & GR_PROTPROCFD)
71145 + return -EACCES;
71146 +
71147 + return 0;
71148 +}
71149 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
71150 new file mode 100644
71151 index 0000000..f056b81
71152 --- /dev/null
71153 +++ b/grsecurity/gracl_ip.c
71154 @@ -0,0 +1,386 @@
71155 +#include <linux/kernel.h>
71156 +#include <asm/uaccess.h>
71157 +#include <asm/errno.h>
71158 +#include <net/sock.h>
71159 +#include <linux/file.h>
71160 +#include <linux/fs.h>
71161 +#include <linux/net.h>
71162 +#include <linux/in.h>
71163 +#include <linux/skbuff.h>
71164 +#include <linux/ip.h>
71165 +#include <linux/udp.h>
71166 +#include <linux/types.h>
71167 +#include <linux/sched.h>
71168 +#include <linux/netdevice.h>
71169 +#include <linux/inetdevice.h>
71170 +#include <linux/gracl.h>
71171 +#include <linux/grsecurity.h>
71172 +#include <linux/grinternal.h>
71173 +
71174 +#define GR_BIND 0x01
71175 +#define GR_CONNECT 0x02
71176 +#define GR_INVERT 0x04
71177 +#define GR_BINDOVERRIDE 0x08
71178 +#define GR_CONNECTOVERRIDE 0x10
71179 +#define GR_SOCK_FAMILY 0x20
71180 +
71181 +static const char * gr_protocols[IPPROTO_MAX] = {
71182 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
71183 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
71184 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
71185 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
71186 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
71187 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
71188 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
71189 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
71190 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
71191 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
71192 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
71193 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
71194 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
71195 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
71196 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
71197 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
71198 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
71199 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
71200 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
71201 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
71202 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
71203 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
71204 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
71205 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
71206 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
71207 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
71208 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
71209 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
71210 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
71211 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
71212 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
71213 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
71214 + };
71215 +
71216 +static const char * gr_socktypes[SOCK_MAX] = {
71217 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
71218 + "unknown:7", "unknown:8", "unknown:9", "packet"
71219 + };
71220 +
71221 +static const char * gr_sockfamilies[AF_MAX+1] = {
71222 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
71223 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
71224 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
71225 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
71226 + };
71227 +
71228 +const char *
71229 +gr_proto_to_name(unsigned char proto)
71230 +{
71231 + return gr_protocols[proto];
71232 +}
71233 +
71234 +const char *
71235 +gr_socktype_to_name(unsigned char type)
71236 +{
71237 + return gr_socktypes[type];
71238 +}
71239 +
71240 +const char *
71241 +gr_sockfamily_to_name(unsigned char family)
71242 +{
71243 + return gr_sockfamilies[family];
71244 +}
71245 +
71246 +extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
71247 +
71248 +int
71249 +gr_search_socket(const int domain, const int type, const int protocol)
71250 +{
71251 + struct acl_subject_label *curr;
71252 + const struct cred *cred = current_cred();
71253 +
71254 + if (unlikely(!gr_acl_is_enabled()))
71255 + goto exit;
71256 +
71257 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
71258 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
71259 + goto exit; // let the kernel handle it
71260 +
71261 + curr = current->acl;
71262 +
71263 + if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
71264 + /* the family is allowed, if this is PF_INET allow it only if
71265 + the extra sock type/protocol checks pass */
71266 + if (domain == PF_INET)
71267 + goto inet_check;
71268 + goto exit;
71269 + } else {
71270 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
71271 + __u32 fakeip = 0;
71272 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
71273 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
71274 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
71275 + gr_to_filename(current->exec_file->f_path.dentry,
71276 + current->exec_file->f_path.mnt) :
71277 + curr->filename, curr->filename,
71278 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
71279 + &current->signal->saved_ip);
71280 + goto exit;
71281 + }
71282 + goto exit_fail;
71283 + }
71284 +
71285 +inet_check:
71286 + /* the rest of this checking is for IPv4 only */
71287 + if (!curr->ips)
71288 + goto exit;
71289 +
71290 + if ((curr->ip_type & (1U << type)) &&
71291 + (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
71292 + goto exit;
71293 +
71294 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
71295 + /* we don't place acls on raw sockets , and sometimes
71296 + dgram/ip sockets are opened for ioctl and not
71297 + bind/connect, so we'll fake a bind learn log */
71298 + if (type == SOCK_RAW || type == SOCK_PACKET) {
71299 + __u32 fakeip = 0;
71300 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
71301 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
71302 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
71303 + gr_to_filename(current->exec_file->f_path.dentry,
71304 + current->exec_file->f_path.mnt) :
71305 + curr->filename, curr->filename,
71306 + &fakeip, 0, type,
71307 + protocol, GR_CONNECT, &current->signal->saved_ip);
71308 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
71309 + __u32 fakeip = 0;
71310 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
71311 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
71312 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
71313 + gr_to_filename(current->exec_file->f_path.dentry,
71314 + current->exec_file->f_path.mnt) :
71315 + curr->filename, curr->filename,
71316 + &fakeip, 0, type,
71317 + protocol, GR_BIND, &current->signal->saved_ip);
71318 + }
71319 + /* we'll log when they use connect or bind */
71320 + goto exit;
71321 + }
71322 +
71323 +exit_fail:
71324 + if (domain == PF_INET)
71325 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
71326 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
71327 + else if (rcu_access_pointer(net_families[domain]) != NULL)
71328 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
71329 + gr_socktype_to_name(type), protocol);
71330 +
71331 + return 0;
71332 +exit:
71333 + return 1;
71334 +}
71335 +
71336 +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)
71337 +{
71338 + if ((ip->mode & mode) &&
71339 + (ip_port >= ip->low) &&
71340 + (ip_port <= ip->high) &&
71341 + ((ntohl(ip_addr) & our_netmask) ==
71342 + (ntohl(our_addr) & our_netmask))
71343 + && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
71344 + && (ip->type & (1U << type))) {
71345 + if (ip->mode & GR_INVERT)
71346 + return 2; // specifically denied
71347 + else
71348 + return 1; // allowed
71349 + }
71350 +
71351 + return 0; // not specifically allowed, may continue parsing
71352 +}
71353 +
71354 +static int
71355 +gr_search_connectbind(const int full_mode, struct sock *sk,
71356 + struct sockaddr_in *addr, const int type)
71357 +{
71358 + char iface[IFNAMSIZ] = {0};
71359 + struct acl_subject_label *curr;
71360 + struct acl_ip_label *ip;
71361 + struct inet_sock *isk;
71362 + struct net_device *dev;
71363 + struct in_device *idev;
71364 + unsigned long i;
71365 + int ret;
71366 + int mode = full_mode & (GR_BIND | GR_CONNECT);
71367 + __u32 ip_addr = 0;
71368 + __u32 our_addr;
71369 + __u32 our_netmask;
71370 + char *p;
71371 + __u16 ip_port = 0;
71372 + const struct cred *cred = current_cred();
71373 +
71374 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
71375 + return 0;
71376 +
71377 + curr = current->acl;
71378 + isk = inet_sk(sk);
71379 +
71380 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
71381 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
71382 + addr->sin_addr.s_addr = curr->inaddr_any_override;
71383 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
71384 + struct sockaddr_in saddr;
71385 + int err;
71386 +
71387 + saddr.sin_family = AF_INET;
71388 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
71389 + saddr.sin_port = isk->inet_sport;
71390 +
71391 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
71392 + if (err)
71393 + return err;
71394 +
71395 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
71396 + if (err)
71397 + return err;
71398 + }
71399 +
71400 + if (!curr->ips)
71401 + return 0;
71402 +
71403 + ip_addr = addr->sin_addr.s_addr;
71404 + ip_port = ntohs(addr->sin_port);
71405 +
71406 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
71407 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
71408 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
71409 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
71410 + gr_to_filename(current->exec_file->f_path.dentry,
71411 + current->exec_file->f_path.mnt) :
71412 + curr->filename, curr->filename,
71413 + &ip_addr, ip_port, type,
71414 + sk->sk_protocol, mode, &current->signal->saved_ip);
71415 + return 0;
71416 + }
71417 +
71418 + for (i = 0; i < curr->ip_num; i++) {
71419 + ip = *(curr->ips + i);
71420 + if (ip->iface != NULL) {
71421 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
71422 + p = strchr(iface, ':');
71423 + if (p != NULL)
71424 + *p = '\0';
71425 + dev = dev_get_by_name(sock_net(sk), iface);
71426 + if (dev == NULL)
71427 + continue;
71428 + idev = in_dev_get(dev);
71429 + if (idev == NULL) {
71430 + dev_put(dev);
71431 + continue;
71432 + }
71433 + rcu_read_lock();
71434 + for_ifa(idev) {
71435 + if (!strcmp(ip->iface, ifa->ifa_label)) {
71436 + our_addr = ifa->ifa_address;
71437 + our_netmask = 0xffffffff;
71438 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
71439 + if (ret == 1) {
71440 + rcu_read_unlock();
71441 + in_dev_put(idev);
71442 + dev_put(dev);
71443 + return 0;
71444 + } else if (ret == 2) {
71445 + rcu_read_unlock();
71446 + in_dev_put(idev);
71447 + dev_put(dev);
71448 + goto denied;
71449 + }
71450 + }
71451 + } endfor_ifa(idev);
71452 + rcu_read_unlock();
71453 + in_dev_put(idev);
71454 + dev_put(dev);
71455 + } else {
71456 + our_addr = ip->addr;
71457 + our_netmask = ip->netmask;
71458 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
71459 + if (ret == 1)
71460 + return 0;
71461 + else if (ret == 2)
71462 + goto denied;
71463 + }
71464 + }
71465 +
71466 +denied:
71467 + if (mode == GR_BIND)
71468 + 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));
71469 + else if (mode == GR_CONNECT)
71470 + 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));
71471 +
71472 + return -EACCES;
71473 +}
71474 +
71475 +int
71476 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
71477 +{
71478 + /* always allow disconnection of dgram sockets with connect */
71479 + if (addr->sin_family == AF_UNSPEC)
71480 + return 0;
71481 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
71482 +}
71483 +
71484 +int
71485 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
71486 +{
71487 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
71488 +}
71489 +
71490 +int gr_search_listen(struct socket *sock)
71491 +{
71492 + struct sock *sk = sock->sk;
71493 + struct sockaddr_in addr;
71494 +
71495 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
71496 + addr.sin_port = inet_sk(sk)->inet_sport;
71497 +
71498 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
71499 +}
71500 +
71501 +int gr_search_accept(struct socket *sock)
71502 +{
71503 + struct sock *sk = sock->sk;
71504 + struct sockaddr_in addr;
71505 +
71506 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
71507 + addr.sin_port = inet_sk(sk)->inet_sport;
71508 +
71509 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
71510 +}
71511 +
71512 +int
71513 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
71514 +{
71515 + if (addr)
71516 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
71517 + else {
71518 + struct sockaddr_in sin;
71519 + const struct inet_sock *inet = inet_sk(sk);
71520 +
71521 + sin.sin_addr.s_addr = inet->inet_daddr;
71522 + sin.sin_port = inet->inet_dport;
71523 +
71524 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
71525 + }
71526 +}
71527 +
71528 +int
71529 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
71530 +{
71531 + struct sockaddr_in sin;
71532 +
71533 + if (unlikely(skb->len < sizeof (struct udphdr)))
71534 + return 0; // skip this packet
71535 +
71536 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
71537 + sin.sin_port = udp_hdr(skb)->source;
71538 +
71539 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
71540 +}
71541 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
71542 new file mode 100644
71543 index 0000000..25f54ef
71544 --- /dev/null
71545 +++ b/grsecurity/gracl_learn.c
71546 @@ -0,0 +1,207 @@
71547 +#include <linux/kernel.h>
71548 +#include <linux/mm.h>
71549 +#include <linux/sched.h>
71550 +#include <linux/poll.h>
71551 +#include <linux/string.h>
71552 +#include <linux/file.h>
71553 +#include <linux/types.h>
71554 +#include <linux/vmalloc.h>
71555 +#include <linux/grinternal.h>
71556 +
71557 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
71558 + size_t count, loff_t *ppos);
71559 +extern int gr_acl_is_enabled(void);
71560 +
71561 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
71562 +static int gr_learn_attached;
71563 +
71564 +/* use a 512k buffer */
71565 +#define LEARN_BUFFER_SIZE (512 * 1024)
71566 +
71567 +static DEFINE_SPINLOCK(gr_learn_lock);
71568 +static DEFINE_MUTEX(gr_learn_user_mutex);
71569 +
71570 +/* we need to maintain two buffers, so that the kernel context of grlearn
71571 + uses a semaphore around the userspace copying, and the other kernel contexts
71572 + use a spinlock when copying into the buffer, since they cannot sleep
71573 +*/
71574 +static char *learn_buffer;
71575 +static char *learn_buffer_user;
71576 +static int learn_buffer_len;
71577 +static int learn_buffer_user_len;
71578 +
71579 +static ssize_t
71580 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
71581 +{
71582 + DECLARE_WAITQUEUE(wait, current);
71583 + ssize_t retval = 0;
71584 +
71585 + add_wait_queue(&learn_wait, &wait);
71586 + set_current_state(TASK_INTERRUPTIBLE);
71587 + do {
71588 + mutex_lock(&gr_learn_user_mutex);
71589 + spin_lock(&gr_learn_lock);
71590 + if (learn_buffer_len)
71591 + break;
71592 + spin_unlock(&gr_learn_lock);
71593 + mutex_unlock(&gr_learn_user_mutex);
71594 + if (file->f_flags & O_NONBLOCK) {
71595 + retval = -EAGAIN;
71596 + goto out;
71597 + }
71598 + if (signal_pending(current)) {
71599 + retval = -ERESTARTSYS;
71600 + goto out;
71601 + }
71602 +
71603 + schedule();
71604 + } while (1);
71605 +
71606 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
71607 + learn_buffer_user_len = learn_buffer_len;
71608 + retval = learn_buffer_len;
71609 + learn_buffer_len = 0;
71610 +
71611 + spin_unlock(&gr_learn_lock);
71612 +
71613 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
71614 + retval = -EFAULT;
71615 +
71616 + mutex_unlock(&gr_learn_user_mutex);
71617 +out:
71618 + set_current_state(TASK_RUNNING);
71619 + remove_wait_queue(&learn_wait, &wait);
71620 + return retval;
71621 +}
71622 +
71623 +static unsigned int
71624 +poll_learn(struct file * file, poll_table * wait)
71625 +{
71626 + poll_wait(file, &learn_wait, wait);
71627 +
71628 + if (learn_buffer_len)
71629 + return (POLLIN | POLLRDNORM);
71630 +
71631 + return 0;
71632 +}
71633 +
71634 +void
71635 +gr_clear_learn_entries(void)
71636 +{
71637 + char *tmp;
71638 +
71639 + mutex_lock(&gr_learn_user_mutex);
71640 + spin_lock(&gr_learn_lock);
71641 + tmp = learn_buffer;
71642 + learn_buffer = NULL;
71643 + spin_unlock(&gr_learn_lock);
71644 + if (tmp)
71645 + vfree(tmp);
71646 + if (learn_buffer_user != NULL) {
71647 + vfree(learn_buffer_user);
71648 + learn_buffer_user = NULL;
71649 + }
71650 + learn_buffer_len = 0;
71651 + mutex_unlock(&gr_learn_user_mutex);
71652 +
71653 + return;
71654 +}
71655 +
71656 +void
71657 +gr_add_learn_entry(const char *fmt, ...)
71658 +{
71659 + va_list args;
71660 + unsigned int len;
71661 +
71662 + if (!gr_learn_attached)
71663 + return;
71664 +
71665 + spin_lock(&gr_learn_lock);
71666 +
71667 + /* leave a gap at the end so we know when it's "full" but don't have to
71668 + compute the exact length of the string we're trying to append
71669 + */
71670 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
71671 + spin_unlock(&gr_learn_lock);
71672 + wake_up_interruptible(&learn_wait);
71673 + return;
71674 + }
71675 + if (learn_buffer == NULL) {
71676 + spin_unlock(&gr_learn_lock);
71677 + return;
71678 + }
71679 +
71680 + va_start(args, fmt);
71681 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
71682 + va_end(args);
71683 +
71684 + learn_buffer_len += len + 1;
71685 +
71686 + spin_unlock(&gr_learn_lock);
71687 + wake_up_interruptible(&learn_wait);
71688 +
71689 + return;
71690 +}
71691 +
71692 +static int
71693 +open_learn(struct inode *inode, struct file *file)
71694 +{
71695 + if (file->f_mode & FMODE_READ && gr_learn_attached)
71696 + return -EBUSY;
71697 + if (file->f_mode & FMODE_READ) {
71698 + int retval = 0;
71699 + mutex_lock(&gr_learn_user_mutex);
71700 + if (learn_buffer == NULL)
71701 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
71702 + if (learn_buffer_user == NULL)
71703 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
71704 + if (learn_buffer == NULL) {
71705 + retval = -ENOMEM;
71706 + goto out_error;
71707 + }
71708 + if (learn_buffer_user == NULL) {
71709 + retval = -ENOMEM;
71710 + goto out_error;
71711 + }
71712 + learn_buffer_len = 0;
71713 + learn_buffer_user_len = 0;
71714 + gr_learn_attached = 1;
71715 +out_error:
71716 + mutex_unlock(&gr_learn_user_mutex);
71717 + return retval;
71718 + }
71719 + return 0;
71720 +}
71721 +
71722 +static int
71723 +close_learn(struct inode *inode, struct file *file)
71724 +{
71725 + if (file->f_mode & FMODE_READ) {
71726 + char *tmp = NULL;
71727 + mutex_lock(&gr_learn_user_mutex);
71728 + spin_lock(&gr_learn_lock);
71729 + tmp = learn_buffer;
71730 + learn_buffer = NULL;
71731 + spin_unlock(&gr_learn_lock);
71732 + if (tmp)
71733 + vfree(tmp);
71734 + if (learn_buffer_user != NULL) {
71735 + vfree(learn_buffer_user);
71736 + learn_buffer_user = NULL;
71737 + }
71738 + learn_buffer_len = 0;
71739 + learn_buffer_user_len = 0;
71740 + gr_learn_attached = 0;
71741 + mutex_unlock(&gr_learn_user_mutex);
71742 + }
71743 +
71744 + return 0;
71745 +}
71746 +
71747 +const struct file_operations grsec_fops = {
71748 + .read = read_learn,
71749 + .write = write_grsec_handler,
71750 + .open = open_learn,
71751 + .release = close_learn,
71752 + .poll = poll_learn,
71753 +};
71754 diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
71755 new file mode 100644
71756 index 0000000..3f8ade0
71757 --- /dev/null
71758 +++ b/grsecurity/gracl_policy.c
71759 @@ -0,0 +1,1782 @@
71760 +#include <linux/kernel.h>
71761 +#include <linux/module.h>
71762 +#include <linux/sched.h>
71763 +#include <linux/mm.h>
71764 +#include <linux/file.h>
71765 +#include <linux/fs.h>
71766 +#include <linux/namei.h>
71767 +#include <linux/mount.h>
71768 +#include <linux/tty.h>
71769 +#include <linux/proc_fs.h>
71770 +#include <linux/lglock.h>
71771 +#include <linux/slab.h>
71772 +#include <linux/vmalloc.h>
71773 +#include <linux/types.h>
71774 +#include <linux/sysctl.h>
71775 +#include <linux/netdevice.h>
71776 +#include <linux/ptrace.h>
71777 +#include <linux/gracl.h>
71778 +#include <linux/gralloc.h>
71779 +#include <linux/security.h>
71780 +#include <linux/grinternal.h>
71781 +#include <linux/pid_namespace.h>
71782 +#include <linux/stop_machine.h>
71783 +#include <linux/fdtable.h>
71784 +#include <linux/percpu.h>
71785 +#include <linux/lglock.h>
71786 +#include <linux/hugetlb.h>
71787 +#include <linux/posix-timers.h>
71788 +#include "../fs/mount.h"
71789 +
71790 +#include <asm/uaccess.h>
71791 +#include <asm/errno.h>
71792 +#include <asm/mman.h>
71793 +
71794 +extern struct gr_policy_state *polstate;
71795 +
71796 +#define FOR_EACH_ROLE_START(role) \
71797 + role = polstate->role_list; \
71798 + while (role) {
71799 +
71800 +#define FOR_EACH_ROLE_END(role) \
71801 + role = role->prev; \
71802 + }
71803 +
71804 +struct path gr_real_root;
71805 +
71806 +extern struct gr_alloc_state *current_alloc_state;
71807 +
71808 +u16 acl_sp_role_value;
71809 +
71810 +static DEFINE_MUTEX(gr_dev_mutex);
71811 +
71812 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
71813 +extern void gr_clear_learn_entries(void);
71814 +
71815 +struct gr_arg *gr_usermode __read_only;
71816 +unsigned char *gr_system_salt __read_only;
71817 +unsigned char *gr_system_sum __read_only;
71818 +
71819 +static unsigned int gr_auth_attempts = 0;
71820 +static unsigned long gr_auth_expires = 0UL;
71821 +
71822 +struct acl_object_label *fakefs_obj_rw;
71823 +struct acl_object_label *fakefs_obj_rwx;
71824 +
71825 +extern int gr_init_uidset(void);
71826 +extern void gr_free_uidset(void);
71827 +extern void gr_remove_uid(uid_t uid);
71828 +extern int gr_find_uid(uid_t uid);
71829 +
71830 +extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
71831 +extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
71832 +extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
71833 +extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
71834 +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);
71835 +extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
71836 +extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
71837 +extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
71838 +extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
71839 +extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
71840 +extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
71841 +extern void assign_special_role(const char *rolename);
71842 +extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
71843 +extern int gr_rbac_disable(void *unused);
71844 +extern void gr_enable_rbac_system(void);
71845 +
71846 +static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
71847 +{
71848 + if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
71849 + return -EFAULT;
71850 +
71851 + return 0;
71852 +}
71853 +
71854 +static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
71855 +{
71856 + if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
71857 + return -EFAULT;
71858 +
71859 + return 0;
71860 +}
71861 +
71862 +static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
71863 +{
71864 + if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
71865 + return -EFAULT;
71866 +
71867 + return 0;
71868 +}
71869 +
71870 +static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
71871 +{
71872 + if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
71873 + return -EFAULT;
71874 +
71875 + return 0;
71876 +}
71877 +
71878 +static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
71879 +{
71880 + if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
71881 + return -EFAULT;
71882 +
71883 + return 0;
71884 +}
71885 +
71886 +static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
71887 +{
71888 + if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
71889 + return -EFAULT;
71890 +
71891 + return 0;
71892 +}
71893 +
71894 +static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
71895 +{
71896 + if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
71897 + return -EFAULT;
71898 +
71899 + return 0;
71900 +}
71901 +
71902 +static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
71903 +{
71904 + if (copy_from_user(trans, userp, sizeof(struct role_transition)))
71905 + return -EFAULT;
71906 +
71907 + return 0;
71908 +}
71909 +
71910 +int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
71911 +{
71912 + if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
71913 + return -EFAULT;
71914 +
71915 + return 0;
71916 +}
71917 +
71918 +static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
71919 +{
71920 + if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
71921 + return -EFAULT;
71922 +
71923 + if (((uwrap->version != GRSECURITY_VERSION) &&
71924 + (uwrap->version != 0x2901)) ||
71925 + (uwrap->size != sizeof(struct gr_arg)))
71926 + return -EINVAL;
71927 +
71928 + return 0;
71929 +}
71930 +
71931 +static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
71932 +{
71933 + if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
71934 + return -EFAULT;
71935 +
71936 + return 0;
71937 +}
71938 +
71939 +static size_t get_gr_arg_wrapper_size_normal(void)
71940 +{
71941 + return sizeof(struct gr_arg_wrapper);
71942 +}
71943 +
71944 +#ifdef CONFIG_COMPAT
71945 +extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
71946 +extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
71947 +extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
71948 +extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
71949 +extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
71950 +extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
71951 +extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
71952 +extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
71953 +extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
71954 +extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
71955 +extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
71956 +extern size_t get_gr_arg_wrapper_size_compat(void);
71957 +
71958 +int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
71959 +int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
71960 +int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
71961 +int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
71962 +int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
71963 +int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
71964 +int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
71965 +int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
71966 +int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
71967 +int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
71968 +int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
71969 +size_t (* get_gr_arg_wrapper_size)(void) __read_only;
71970 +
71971 +#else
71972 +#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
71973 +#define copy_gr_arg copy_gr_arg_normal
71974 +#define copy_gr_hash_struct copy_gr_hash_struct_normal
71975 +#define copy_acl_object_label copy_acl_object_label_normal
71976 +#define copy_acl_subject_label copy_acl_subject_label_normal
71977 +#define copy_acl_role_label copy_acl_role_label_normal
71978 +#define copy_acl_ip_label copy_acl_ip_label_normal
71979 +#define copy_pointer_from_array copy_pointer_from_array_normal
71980 +#define copy_sprole_pw copy_sprole_pw_normal
71981 +#define copy_role_transition copy_role_transition_normal
71982 +#define copy_role_allowed_ip copy_role_allowed_ip_normal
71983 +#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
71984 +#endif
71985 +
71986 +static struct acl_subject_label *
71987 +lookup_subject_map(const struct acl_subject_label *userp)
71988 +{
71989 + unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
71990 + struct subject_map *match;
71991 +
71992 + match = polstate->subj_map_set.s_hash[index];
71993 +
71994 + while (match && match->user != userp)
71995 + match = match->next;
71996 +
71997 + if (match != NULL)
71998 + return match->kernel;
71999 + else
72000 + return NULL;
72001 +}
72002 +
72003 +static void
72004 +insert_subj_map_entry(struct subject_map *subjmap)
72005 +{
72006 + unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
72007 + struct subject_map **curr;
72008 +
72009 + subjmap->prev = NULL;
72010 +
72011 + curr = &polstate->subj_map_set.s_hash[index];
72012 + if (*curr != NULL)
72013 + (*curr)->prev = subjmap;
72014 +
72015 + subjmap->next = *curr;
72016 + *curr = subjmap;
72017 +
72018 + return;
72019 +}
72020 +
72021 +static void
72022 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
72023 +{
72024 + unsigned int index =
72025 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
72026 + struct acl_role_label **curr;
72027 + struct acl_role_label *tmp, *tmp2;
72028 +
72029 + curr = &polstate->acl_role_set.r_hash[index];
72030 +
72031 + /* simple case, slot is empty, just set it to our role */
72032 + if (*curr == NULL) {
72033 + *curr = role;
72034 + } else {
72035 + /* example:
72036 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
72037 + 2 -> 3
72038 + */
72039 + /* first check to see if we can already be reached via this slot */
72040 + tmp = *curr;
72041 + while (tmp && tmp != role)
72042 + tmp = tmp->next;
72043 + if (tmp == role) {
72044 + /* we don't need to add ourselves to this slot's chain */
72045 + return;
72046 + }
72047 + /* we need to add ourselves to this chain, two cases */
72048 + if (role->next == NULL) {
72049 + /* simple case, append the current chain to our role */
72050 + role->next = *curr;
72051 + *curr = role;
72052 + } else {
72053 + /* 1 -> 2 -> 3 -> 4
72054 + 2 -> 3 -> 4
72055 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
72056 + */
72057 + /* trickier case: walk our role's chain until we find
72058 + the role for the start of the current slot's chain */
72059 + tmp = role;
72060 + tmp2 = *curr;
72061 + while (tmp->next && tmp->next != tmp2)
72062 + tmp = tmp->next;
72063 + if (tmp->next == tmp2) {
72064 + /* from example above, we found 3, so just
72065 + replace this slot's chain with ours */
72066 + *curr = role;
72067 + } else {
72068 + /* we didn't find a subset of our role's chain
72069 + in the current slot's chain, so append their
72070 + chain to ours, and set us as the first role in
72071 + the slot's chain
72072 +
72073 + we could fold this case with the case above,
72074 + but making it explicit for clarity
72075 + */
72076 + tmp->next = tmp2;
72077 + *curr = role;
72078 + }
72079 + }
72080 + }
72081 +
72082 + return;
72083 +}
72084 +
72085 +static void
72086 +insert_acl_role_label(struct acl_role_label *role)
72087 +{
72088 + int i;
72089 +
72090 + if (polstate->role_list == NULL) {
72091 + polstate->role_list = role;
72092 + role->prev = NULL;
72093 + } else {
72094 + role->prev = polstate->role_list;
72095 + polstate->role_list = role;
72096 + }
72097 +
72098 + /* used for hash chains */
72099 + role->next = NULL;
72100 +
72101 + if (role->roletype & GR_ROLE_DOMAIN) {
72102 + for (i = 0; i < role->domain_child_num; i++)
72103 + __insert_acl_role_label(role, role->domain_children[i]);
72104 + } else
72105 + __insert_acl_role_label(role, role->uidgid);
72106 +}
72107 +
72108 +static int
72109 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
72110 +{
72111 + struct name_entry **curr, *nentry;
72112 + struct inodev_entry *ientry;
72113 + unsigned int len = strlen(name);
72114 + unsigned int key = full_name_hash(name, len);
72115 + unsigned int index = key % polstate->name_set.n_size;
72116 +
72117 + curr = &polstate->name_set.n_hash[index];
72118 +
72119 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
72120 + curr = &((*curr)->next);
72121 +
72122 + if (*curr != NULL)
72123 + return 1;
72124 +
72125 + nentry = acl_alloc(sizeof (struct name_entry));
72126 + if (nentry == NULL)
72127 + return 0;
72128 + ientry = acl_alloc(sizeof (struct inodev_entry));
72129 + if (ientry == NULL)
72130 + return 0;
72131 + ientry->nentry = nentry;
72132 +
72133 + nentry->key = key;
72134 + nentry->name = name;
72135 + nentry->inode = inode;
72136 + nentry->device = device;
72137 + nentry->len = len;
72138 + nentry->deleted = deleted;
72139 +
72140 + nentry->prev = NULL;
72141 + curr = &polstate->name_set.n_hash[index];
72142 + if (*curr != NULL)
72143 + (*curr)->prev = nentry;
72144 + nentry->next = *curr;
72145 + *curr = nentry;
72146 +
72147 + /* insert us into the table searchable by inode/dev */
72148 + __insert_inodev_entry(polstate, ientry);
72149 +
72150 + return 1;
72151 +}
72152 +
72153 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
72154 +
72155 +static void *
72156 +create_table(__u32 * len, int elementsize)
72157 +{
72158 + unsigned int table_sizes[] = {
72159 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
72160 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
72161 + 4194301, 8388593, 16777213, 33554393, 67108859
72162 + };
72163 + void *newtable = NULL;
72164 + unsigned int pwr = 0;
72165 +
72166 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
72167 + table_sizes[pwr] <= *len)
72168 + pwr++;
72169 +
72170 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
72171 + return newtable;
72172 +
72173 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
72174 + newtable =
72175 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
72176 + else
72177 + newtable = vmalloc(table_sizes[pwr] * elementsize);
72178 +
72179 + *len = table_sizes[pwr];
72180 +
72181 + return newtable;
72182 +}
72183 +
72184 +static int
72185 +init_variables(const struct gr_arg *arg, bool reload)
72186 +{
72187 + struct task_struct *reaper = init_pid_ns.child_reaper;
72188 + unsigned int stacksize;
72189 +
72190 + polstate->subj_map_set.s_size = arg->role_db.num_subjects;
72191 + polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
72192 + polstate->name_set.n_size = arg->role_db.num_objects;
72193 + polstate->inodev_set.i_size = arg->role_db.num_objects;
72194 +
72195 + if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
72196 + !polstate->name_set.n_size || !polstate->inodev_set.i_size)
72197 + return 1;
72198 +
72199 + if (!reload) {
72200 + if (!gr_init_uidset())
72201 + return 1;
72202 + }
72203 +
72204 + /* set up the stack that holds allocation info */
72205 +
72206 + stacksize = arg->role_db.num_pointers + 5;
72207 +
72208 + if (!acl_alloc_stack_init(stacksize))
72209 + return 1;
72210 +
72211 + if (!reload) {
72212 + /* grab reference for the real root dentry and vfsmount */
72213 + get_fs_root(reaper->fs, &gr_real_root);
72214 +
72215 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
72216 + 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);
72217 +#endif
72218 +
72219 + fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
72220 + if (fakefs_obj_rw == NULL)
72221 + return 1;
72222 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
72223 +
72224 + fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
72225 + if (fakefs_obj_rwx == NULL)
72226 + return 1;
72227 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
72228 + }
72229 +
72230 + polstate->subj_map_set.s_hash =
72231 + (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
72232 + polstate->acl_role_set.r_hash =
72233 + (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
72234 + polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
72235 + polstate->inodev_set.i_hash =
72236 + (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
72237 +
72238 + if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
72239 + !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
72240 + return 1;
72241 +
72242 + memset(polstate->subj_map_set.s_hash, 0,
72243 + sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
72244 + memset(polstate->acl_role_set.r_hash, 0,
72245 + sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
72246 + memset(polstate->name_set.n_hash, 0,
72247 + sizeof (struct name_entry *) * polstate->name_set.n_size);
72248 + memset(polstate->inodev_set.i_hash, 0,
72249 + sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
72250 +
72251 + return 0;
72252 +}
72253 +
72254 +/* free information not needed after startup
72255 + currently contains user->kernel pointer mappings for subjects
72256 +*/
72257 +
72258 +static void
72259 +free_init_variables(void)
72260 +{
72261 + __u32 i;
72262 +
72263 + if (polstate->subj_map_set.s_hash) {
72264 + for (i = 0; i < polstate->subj_map_set.s_size; i++) {
72265 + if (polstate->subj_map_set.s_hash[i]) {
72266 + kfree(polstate->subj_map_set.s_hash[i]);
72267 + polstate->subj_map_set.s_hash[i] = NULL;
72268 + }
72269 + }
72270 +
72271 + if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
72272 + PAGE_SIZE)
72273 + kfree(polstate->subj_map_set.s_hash);
72274 + else
72275 + vfree(polstate->subj_map_set.s_hash);
72276 + }
72277 +
72278 + return;
72279 +}
72280 +
72281 +static void
72282 +free_variables(bool reload)
72283 +{
72284 + struct acl_subject_label *s;
72285 + struct acl_role_label *r;
72286 + struct task_struct *task, *task2;
72287 + unsigned int x;
72288 +
72289 + if (!reload) {
72290 + gr_clear_learn_entries();
72291 +
72292 + read_lock(&tasklist_lock);
72293 + do_each_thread(task2, task) {
72294 + task->acl_sp_role = 0;
72295 + task->acl_role_id = 0;
72296 + task->inherited = 0;
72297 + task->acl = NULL;
72298 + task->role = NULL;
72299 + } while_each_thread(task2, task);
72300 + read_unlock(&tasklist_lock);
72301 +
72302 + kfree(fakefs_obj_rw);
72303 + fakefs_obj_rw = NULL;
72304 + kfree(fakefs_obj_rwx);
72305 + fakefs_obj_rwx = NULL;
72306 +
72307 + /* release the reference to the real root dentry and vfsmount */
72308 + path_put(&gr_real_root);
72309 + memset(&gr_real_root, 0, sizeof(gr_real_root));
72310 + }
72311 +
72312 + /* free all object hash tables */
72313 +
72314 + FOR_EACH_ROLE_START(r)
72315 + if (r->subj_hash == NULL)
72316 + goto next_role;
72317 + FOR_EACH_SUBJECT_START(r, s, x)
72318 + if (s->obj_hash == NULL)
72319 + break;
72320 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
72321 + kfree(s->obj_hash);
72322 + else
72323 + vfree(s->obj_hash);
72324 + FOR_EACH_SUBJECT_END(s, x)
72325 + FOR_EACH_NESTED_SUBJECT_START(r, s)
72326 + if (s->obj_hash == NULL)
72327 + break;
72328 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
72329 + kfree(s->obj_hash);
72330 + else
72331 + vfree(s->obj_hash);
72332 + FOR_EACH_NESTED_SUBJECT_END(s)
72333 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
72334 + kfree(r->subj_hash);
72335 + else
72336 + vfree(r->subj_hash);
72337 + r->subj_hash = NULL;
72338 +next_role:
72339 + FOR_EACH_ROLE_END(r)
72340 +
72341 + acl_free_all();
72342 +
72343 + if (polstate->acl_role_set.r_hash) {
72344 + if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
72345 + PAGE_SIZE)
72346 + kfree(polstate->acl_role_set.r_hash);
72347 + else
72348 + vfree(polstate->acl_role_set.r_hash);
72349 + }
72350 + if (polstate->name_set.n_hash) {
72351 + if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
72352 + PAGE_SIZE)
72353 + kfree(polstate->name_set.n_hash);
72354 + else
72355 + vfree(polstate->name_set.n_hash);
72356 + }
72357 +
72358 + if (polstate->inodev_set.i_hash) {
72359 + if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
72360 + PAGE_SIZE)
72361 + kfree(polstate->inodev_set.i_hash);
72362 + else
72363 + vfree(polstate->inodev_set.i_hash);
72364 + }
72365 +
72366 + if (!reload)
72367 + gr_free_uidset();
72368 +
72369 + memset(&polstate->name_set, 0, sizeof (struct name_db));
72370 + memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
72371 + memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
72372 + memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
72373 +
72374 + polstate->default_role = NULL;
72375 + polstate->kernel_role = NULL;
72376 + polstate->role_list = NULL;
72377 +
72378 + return;
72379 +}
72380 +
72381 +static struct acl_subject_label *
72382 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
72383 +
72384 +static int alloc_and_copy_string(char **name, unsigned int maxlen)
72385 +{
72386 + unsigned int len = strnlen_user(*name, maxlen);
72387 + char *tmp;
72388 +
72389 + if (!len || len >= maxlen)
72390 + return -EINVAL;
72391 +
72392 + if ((tmp = (char *) acl_alloc(len)) == NULL)
72393 + return -ENOMEM;
72394 +
72395 + if (copy_from_user(tmp, *name, len))
72396 + return -EFAULT;
72397 +
72398 + tmp[len-1] = '\0';
72399 + *name = tmp;
72400 +
72401 + return 0;
72402 +}
72403 +
72404 +static int
72405 +copy_user_glob(struct acl_object_label *obj)
72406 +{
72407 + struct acl_object_label *g_tmp, **guser;
72408 + int error;
72409 +
72410 + if (obj->globbed == NULL)
72411 + return 0;
72412 +
72413 + guser = &obj->globbed;
72414 + while (*guser) {
72415 + g_tmp = (struct acl_object_label *)
72416 + acl_alloc(sizeof (struct acl_object_label));
72417 + if (g_tmp == NULL)
72418 + return -ENOMEM;
72419 +
72420 + if (copy_acl_object_label(g_tmp, *guser))
72421 + return -EFAULT;
72422 +
72423 + error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
72424 + if (error)
72425 + return error;
72426 +
72427 + *guser = g_tmp;
72428 + guser = &(g_tmp->next);
72429 + }
72430 +
72431 + return 0;
72432 +}
72433 +
72434 +static int
72435 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
72436 + struct acl_role_label *role)
72437 +{
72438 + struct acl_object_label *o_tmp;
72439 + int ret;
72440 +
72441 + while (userp) {
72442 + if ((o_tmp = (struct acl_object_label *)
72443 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
72444 + return -ENOMEM;
72445 +
72446 + if (copy_acl_object_label(o_tmp, userp))
72447 + return -EFAULT;
72448 +
72449 + userp = o_tmp->prev;
72450 +
72451 + ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
72452 + if (ret)
72453 + return ret;
72454 +
72455 + insert_acl_obj_label(o_tmp, subj);
72456 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
72457 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
72458 + return -ENOMEM;
72459 +
72460 + ret = copy_user_glob(o_tmp);
72461 + if (ret)
72462 + return ret;
72463 +
72464 + if (o_tmp->nested) {
72465 + int already_copied;
72466 +
72467 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
72468 + if (IS_ERR(o_tmp->nested))
72469 + return PTR_ERR(o_tmp->nested);
72470 +
72471 + /* insert into nested subject list if we haven't copied this one yet
72472 + to prevent duplicate entries */
72473 + if (!already_copied) {
72474 + o_tmp->nested->next = role->hash->first;
72475 + role->hash->first = o_tmp->nested;
72476 + }
72477 + }
72478 + }
72479 +
72480 + return 0;
72481 +}
72482 +
72483 +static __u32
72484 +count_user_subjs(struct acl_subject_label *userp)
72485 +{
72486 + struct acl_subject_label s_tmp;
72487 + __u32 num = 0;
72488 +
72489 + while (userp) {
72490 + if (copy_acl_subject_label(&s_tmp, userp))
72491 + break;
72492 +
72493 + userp = s_tmp.prev;
72494 + }
72495 +
72496 + return num;
72497 +}
72498 +
72499 +static int
72500 +copy_user_allowedips(struct acl_role_label *rolep)
72501 +{
72502 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
72503 +
72504 + ruserip = rolep->allowed_ips;
72505 +
72506 + while (ruserip) {
72507 + rlast = rtmp;
72508 +
72509 + if ((rtmp = (struct role_allowed_ip *)
72510 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
72511 + return -ENOMEM;
72512 +
72513 + if (copy_role_allowed_ip(rtmp, ruserip))
72514 + return -EFAULT;
72515 +
72516 + ruserip = rtmp->prev;
72517 +
72518 + if (!rlast) {
72519 + rtmp->prev = NULL;
72520 + rolep->allowed_ips = rtmp;
72521 + } else {
72522 + rlast->next = rtmp;
72523 + rtmp->prev = rlast;
72524 + }
72525 +
72526 + if (!ruserip)
72527 + rtmp->next = NULL;
72528 + }
72529 +
72530 + return 0;
72531 +}
72532 +
72533 +static int
72534 +copy_user_transitions(struct acl_role_label *rolep)
72535 +{
72536 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
72537 + int error;
72538 +
72539 + rusertp = rolep->transitions;
72540 +
72541 + while (rusertp) {
72542 + rlast = rtmp;
72543 +
72544 + if ((rtmp = (struct role_transition *)
72545 + acl_alloc(sizeof (struct role_transition))) == NULL)
72546 + return -ENOMEM;
72547 +
72548 + if (copy_role_transition(rtmp, rusertp))
72549 + return -EFAULT;
72550 +
72551 + rusertp = rtmp->prev;
72552 +
72553 + error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
72554 + if (error)
72555 + return error;
72556 +
72557 + if (!rlast) {
72558 + rtmp->prev = NULL;
72559 + rolep->transitions = rtmp;
72560 + } else {
72561 + rlast->next = rtmp;
72562 + rtmp->prev = rlast;
72563 + }
72564 +
72565 + if (!rusertp)
72566 + rtmp->next = NULL;
72567 + }
72568 +
72569 + return 0;
72570 +}
72571 +
72572 +static __u32 count_user_objs(const struct acl_object_label __user *userp)
72573 +{
72574 + struct acl_object_label o_tmp;
72575 + __u32 num = 0;
72576 +
72577 + while (userp) {
72578 + if (copy_acl_object_label(&o_tmp, userp))
72579 + break;
72580 +
72581 + userp = o_tmp.prev;
72582 + num++;
72583 + }
72584 +
72585 + return num;
72586 +}
72587 +
72588 +static struct acl_subject_label *
72589 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
72590 +{
72591 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
72592 + __u32 num_objs;
72593 + struct acl_ip_label **i_tmp, *i_utmp2;
72594 + struct gr_hash_struct ghash;
72595 + struct subject_map *subjmap;
72596 + unsigned int i_num;
72597 + int err;
72598 +
72599 + if (already_copied != NULL)
72600 + *already_copied = 0;
72601 +
72602 + s_tmp = lookup_subject_map(userp);
72603 +
72604 + /* we've already copied this subject into the kernel, just return
72605 + the reference to it, and don't copy it over again
72606 + */
72607 + if (s_tmp) {
72608 + if (already_copied != NULL)
72609 + *already_copied = 1;
72610 + return(s_tmp);
72611 + }
72612 +
72613 + if ((s_tmp = (struct acl_subject_label *)
72614 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
72615 + return ERR_PTR(-ENOMEM);
72616 +
72617 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
72618 + if (subjmap == NULL)
72619 + return ERR_PTR(-ENOMEM);
72620 +
72621 + subjmap->user = userp;
72622 + subjmap->kernel = s_tmp;
72623 + insert_subj_map_entry(subjmap);
72624 +
72625 + if (copy_acl_subject_label(s_tmp, userp))
72626 + return ERR_PTR(-EFAULT);
72627 +
72628 + err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
72629 + if (err)
72630 + return ERR_PTR(err);
72631 +
72632 + if (!strcmp(s_tmp->filename, "/"))
72633 + role->root_label = s_tmp;
72634 +
72635 + if (copy_gr_hash_struct(&ghash, s_tmp->hash))
72636 + return ERR_PTR(-EFAULT);
72637 +
72638 + /* copy user and group transition tables */
72639 +
72640 + if (s_tmp->user_trans_num) {
72641 + uid_t *uidlist;
72642 +
72643 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
72644 + if (uidlist == NULL)
72645 + return ERR_PTR(-ENOMEM);
72646 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
72647 + return ERR_PTR(-EFAULT);
72648 +
72649 + s_tmp->user_transitions = uidlist;
72650 + }
72651 +
72652 + if (s_tmp->group_trans_num) {
72653 + gid_t *gidlist;
72654 +
72655 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
72656 + if (gidlist == NULL)
72657 + return ERR_PTR(-ENOMEM);
72658 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
72659 + return ERR_PTR(-EFAULT);
72660 +
72661 + s_tmp->group_transitions = gidlist;
72662 + }
72663 +
72664 + /* set up object hash table */
72665 + num_objs = count_user_objs(ghash.first);
72666 +
72667 + s_tmp->obj_hash_size = num_objs;
72668 + s_tmp->obj_hash =
72669 + (struct acl_object_label **)
72670 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
72671 +
72672 + if (!s_tmp->obj_hash)
72673 + return ERR_PTR(-ENOMEM);
72674 +
72675 + memset(s_tmp->obj_hash, 0,
72676 + s_tmp->obj_hash_size *
72677 + sizeof (struct acl_object_label *));
72678 +
72679 + /* add in objects */
72680 + err = copy_user_objs(ghash.first, s_tmp, role);
72681 +
72682 + if (err)
72683 + return ERR_PTR(err);
72684 +
72685 + /* set pointer for parent subject */
72686 + if (s_tmp->parent_subject) {
72687 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
72688 +
72689 + if (IS_ERR(s_tmp2))
72690 + return s_tmp2;
72691 +
72692 + s_tmp->parent_subject = s_tmp2;
72693 + }
72694 +
72695 + /* add in ip acls */
72696 +
72697 + if (!s_tmp->ip_num) {
72698 + s_tmp->ips = NULL;
72699 + goto insert;
72700 + }
72701 +
72702 + i_tmp =
72703 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
72704 + sizeof (struct acl_ip_label *));
72705 +
72706 + if (!i_tmp)
72707 + return ERR_PTR(-ENOMEM);
72708 +
72709 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
72710 + *(i_tmp + i_num) =
72711 + (struct acl_ip_label *)
72712 + acl_alloc(sizeof (struct acl_ip_label));
72713 + if (!*(i_tmp + i_num))
72714 + return ERR_PTR(-ENOMEM);
72715 +
72716 + if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
72717 + return ERR_PTR(-EFAULT);
72718 +
72719 + if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
72720 + return ERR_PTR(-EFAULT);
72721 +
72722 + if ((*(i_tmp + i_num))->iface == NULL)
72723 + continue;
72724 +
72725 + err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
72726 + if (err)
72727 + return ERR_PTR(err);
72728 + }
72729 +
72730 + s_tmp->ips = i_tmp;
72731 +
72732 +insert:
72733 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
72734 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
72735 + return ERR_PTR(-ENOMEM);
72736 +
72737 + return s_tmp;
72738 +}
72739 +
72740 +static int
72741 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
72742 +{
72743 + struct acl_subject_label s_pre;
72744 + struct acl_subject_label * ret;
72745 + int err;
72746 +
72747 + while (userp) {
72748 + if (copy_acl_subject_label(&s_pre, userp))
72749 + return -EFAULT;
72750 +
72751 + ret = do_copy_user_subj(userp, role, NULL);
72752 +
72753 + err = PTR_ERR(ret);
72754 + if (IS_ERR(ret))
72755 + return err;
72756 +
72757 + insert_acl_subj_label(ret, role);
72758 +
72759 + userp = s_pre.prev;
72760 + }
72761 +
72762 + return 0;
72763 +}
72764 +
72765 +static int
72766 +copy_user_acl(struct gr_arg *arg)
72767 +{
72768 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
72769 + struct acl_subject_label *subj_list;
72770 + struct sprole_pw *sptmp;
72771 + struct gr_hash_struct *ghash;
72772 + uid_t *domainlist;
72773 + unsigned int r_num;
72774 + int err = 0;
72775 + __u16 i;
72776 + __u32 num_subjs;
72777 +
72778 + /* we need a default and kernel role */
72779 + if (arg->role_db.num_roles < 2)
72780 + return -EINVAL;
72781 +
72782 + /* copy special role authentication info from userspace */
72783 +
72784 + polstate->num_sprole_pws = arg->num_sprole_pws;
72785 + polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
72786 +
72787 + if (!polstate->acl_special_roles && polstate->num_sprole_pws)
72788 + return -ENOMEM;
72789 +
72790 + for (i = 0; i < polstate->num_sprole_pws; i++) {
72791 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
72792 + if (!sptmp)
72793 + return -ENOMEM;
72794 + if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
72795 + return -EFAULT;
72796 +
72797 + err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
72798 + if (err)
72799 + return err;
72800 +
72801 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
72802 + printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
72803 +#endif
72804 +
72805 + polstate->acl_special_roles[i] = sptmp;
72806 + }
72807 +
72808 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
72809 +
72810 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
72811 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
72812 +
72813 + if (!r_tmp)
72814 + return -ENOMEM;
72815 +
72816 + if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
72817 + return -EFAULT;
72818 +
72819 + if (copy_acl_role_label(r_tmp, r_utmp2))
72820 + return -EFAULT;
72821 +
72822 + err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
72823 + if (err)
72824 + return err;
72825 +
72826 + if (!strcmp(r_tmp->rolename, "default")
72827 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
72828 + polstate->default_role = r_tmp;
72829 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
72830 + polstate->kernel_role = r_tmp;
72831 + }
72832 +
72833 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
72834 + return -ENOMEM;
72835 +
72836 + if (copy_gr_hash_struct(ghash, r_tmp->hash))
72837 + return -EFAULT;
72838 +
72839 + r_tmp->hash = ghash;
72840 +
72841 + num_subjs = count_user_subjs(r_tmp->hash->first);
72842 +
72843 + r_tmp->subj_hash_size = num_subjs;
72844 + r_tmp->subj_hash =
72845 + (struct acl_subject_label **)
72846 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
72847 +
72848 + if (!r_tmp->subj_hash)
72849 + return -ENOMEM;
72850 +
72851 + err = copy_user_allowedips(r_tmp);
72852 + if (err)
72853 + return err;
72854 +
72855 + /* copy domain info */
72856 + if (r_tmp->domain_children != NULL) {
72857 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
72858 + if (domainlist == NULL)
72859 + return -ENOMEM;
72860 +
72861 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
72862 + return -EFAULT;
72863 +
72864 + r_tmp->domain_children = domainlist;
72865 + }
72866 +
72867 + err = copy_user_transitions(r_tmp);
72868 + if (err)
72869 + return err;
72870 +
72871 + memset(r_tmp->subj_hash, 0,
72872 + r_tmp->subj_hash_size *
72873 + sizeof (struct acl_subject_label *));
72874 +
72875 + /* acquire the list of subjects, then NULL out
72876 + the list prior to parsing the subjects for this role,
72877 + as during this parsing the list is replaced with a list
72878 + of *nested* subjects for the role
72879 + */
72880 + subj_list = r_tmp->hash->first;
72881 +
72882 + /* set nested subject list to null */
72883 + r_tmp->hash->first = NULL;
72884 +
72885 + err = copy_user_subjs(subj_list, r_tmp);
72886 +
72887 + if (err)
72888 + return err;
72889 +
72890 + insert_acl_role_label(r_tmp);
72891 + }
72892 +
72893 + if (polstate->default_role == NULL || polstate->kernel_role == NULL)
72894 + return -EINVAL;
72895 +
72896 + return err;
72897 +}
72898 +
72899 +static int gracl_reload_apply_policies(void *reload)
72900 +{
72901 + struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
72902 + struct task_struct *task, *task2;
72903 + struct acl_role_label *role, *rtmp;
72904 + struct acl_subject_label *subj;
72905 + const struct cred *cred;
72906 + int role_applied;
72907 + int ret = 0;
72908 +
72909 + memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
72910 + memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
72911 +
72912 + /* first make sure we'll be able to apply the new policy cleanly */
72913 + do_each_thread(task2, task) {
72914 + if (task->exec_file == NULL)
72915 + continue;
72916 + role_applied = 0;
72917 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
72918 + /* preserve special roles */
72919 + FOR_EACH_ROLE_START(role)
72920 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
72921 + rtmp = task->role;
72922 + task->role = role;
72923 + role_applied = 1;
72924 + break;
72925 + }
72926 + FOR_EACH_ROLE_END(role)
72927 + }
72928 + if (!role_applied) {
72929 + cred = __task_cred(task);
72930 + rtmp = task->role;
72931 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72932 + }
72933 + /* this handles non-nested inherited subjects, nested subjects will still
72934 + be dropped currently */
72935 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
72936 + task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
72937 + /* change the role back so that we've made no modifications to the policy */
72938 + task->role = rtmp;
72939 +
72940 + if (subj == NULL || task->tmpacl == NULL) {
72941 + ret = -EINVAL;
72942 + goto out;
72943 + }
72944 + } while_each_thread(task2, task);
72945 +
72946 + /* now actually apply the policy */
72947 +
72948 + do_each_thread(task2, task) {
72949 + if (task->exec_file) {
72950 + role_applied = 0;
72951 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
72952 + /* preserve special roles */
72953 + FOR_EACH_ROLE_START(role)
72954 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
72955 + task->role = role;
72956 + role_applied = 1;
72957 + break;
72958 + }
72959 + FOR_EACH_ROLE_END(role)
72960 + }
72961 + if (!role_applied) {
72962 + cred = __task_cred(task);
72963 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72964 + }
72965 + /* this handles non-nested inherited subjects, nested subjects will still
72966 + be dropped currently */
72967 + if (!reload_state->oldmode && task->inherited)
72968 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
72969 + else {
72970 + /* looked up and tagged to the task previously */
72971 + subj = task->tmpacl;
72972 + }
72973 + /* subj will be non-null */
72974 + __gr_apply_subject_to_task(polstate, task, subj);
72975 + if (reload_state->oldmode) {
72976 + task->acl_role_id = 0;
72977 + task->acl_sp_role = 0;
72978 + task->inherited = 0;
72979 + }
72980 + } else {
72981 + // it's a kernel process
72982 + task->role = polstate->kernel_role;
72983 + task->acl = polstate->kernel_role->root_label;
72984 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
72985 + task->acl->mode &= ~GR_PROCFIND;
72986 +#endif
72987 + }
72988 + } while_each_thread(task2, task);
72989 +
72990 + memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
72991 + memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
72992 +
72993 +out:
72994 +
72995 + return ret;
72996 +}
72997 +
72998 +static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
72999 +{
73000 + struct gr_reload_state new_reload_state = { };
73001 + int err;
73002 +
73003 + new_reload_state.oldpolicy_ptr = polstate;
73004 + new_reload_state.oldalloc_ptr = current_alloc_state;
73005 + new_reload_state.oldmode = oldmode;
73006 +
73007 + current_alloc_state = &new_reload_state.newalloc;
73008 + polstate = &new_reload_state.newpolicy;
73009 +
73010 + /* everything relevant is now saved off, copy in the new policy */
73011 + if (init_variables(args, true)) {
73012 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
73013 + err = -ENOMEM;
73014 + goto error;
73015 + }
73016 +
73017 + err = copy_user_acl(args);
73018 + free_init_variables();
73019 + if (err)
73020 + goto error;
73021 + /* the new policy is copied in, with the old policy available via saved_state
73022 + first go through applying roles, making sure to preserve special roles
73023 + then apply new subjects, making sure to preserve inherited and nested subjects,
73024 + though currently only inherited subjects will be preserved
73025 + */
73026 + err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
73027 + if (err)
73028 + goto error;
73029 +
73030 + /* we've now applied the new policy, so restore the old policy state to free it */
73031 + polstate = &new_reload_state.oldpolicy;
73032 + current_alloc_state = &new_reload_state.oldalloc;
73033 + free_variables(true);
73034 +
73035 + /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
73036 + to running_polstate/current_alloc_state inside stop_machine
73037 + */
73038 + err = 0;
73039 + goto out;
73040 +error:
73041 + /* on error of loading the new policy, we'll just keep the previous
73042 + policy set around
73043 + */
73044 + free_variables(true);
73045 +
73046 + /* doesn't affect runtime, but maintains consistent state */
73047 +out:
73048 + polstate = new_reload_state.oldpolicy_ptr;
73049 + current_alloc_state = new_reload_state.oldalloc_ptr;
73050 +
73051 + return err;
73052 +}
73053 +
73054 +static int
73055 +gracl_init(struct gr_arg *args)
73056 +{
73057 + int error = 0;
73058 +
73059 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
73060 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
73061 +
73062 + if (init_variables(args, false)) {
73063 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
73064 + error = -ENOMEM;
73065 + goto out;
73066 + }
73067 +
73068 + error = copy_user_acl(args);
73069 + free_init_variables();
73070 + if (error)
73071 + goto out;
73072 +
73073 + error = gr_set_acls(0);
73074 + if (error)
73075 + goto out;
73076 +
73077 + gr_enable_rbac_system();
73078 +
73079 + return 0;
73080 +
73081 +out:
73082 + free_variables(false);
73083 + return error;
73084 +}
73085 +
73086 +static int
73087 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
73088 + unsigned char **sum)
73089 +{
73090 + struct acl_role_label *r;
73091 + struct role_allowed_ip *ipp;
73092 + struct role_transition *trans;
73093 + unsigned int i;
73094 + int found = 0;
73095 + u32 curr_ip = current->signal->curr_ip;
73096 +
73097 + current->signal->saved_ip = curr_ip;
73098 +
73099 + /* check transition table */
73100 +
73101 + for (trans = current->role->transitions; trans; trans = trans->next) {
73102 + if (!strcmp(rolename, trans->rolename)) {
73103 + found = 1;
73104 + break;
73105 + }
73106 + }
73107 +
73108 + if (!found)
73109 + return 0;
73110 +
73111 + /* handle special roles that do not require authentication
73112 + and check ip */
73113 +
73114 + FOR_EACH_ROLE_START(r)
73115 + if (!strcmp(rolename, r->rolename) &&
73116 + (r->roletype & GR_ROLE_SPECIAL)) {
73117 + found = 0;
73118 + if (r->allowed_ips != NULL) {
73119 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
73120 + if ((ntohl(curr_ip) & ipp->netmask) ==
73121 + (ntohl(ipp->addr) & ipp->netmask))
73122 + found = 1;
73123 + }
73124 + } else
73125 + found = 2;
73126 + if (!found)
73127 + return 0;
73128 +
73129 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
73130 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
73131 + *salt = NULL;
73132 + *sum = NULL;
73133 + return 1;
73134 + }
73135 + }
73136 + FOR_EACH_ROLE_END(r)
73137 +
73138 + for (i = 0; i < polstate->num_sprole_pws; i++) {
73139 + if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
73140 + *salt = polstate->acl_special_roles[i]->salt;
73141 + *sum = polstate->acl_special_roles[i]->sum;
73142 + return 1;
73143 + }
73144 + }
73145 +
73146 + return 0;
73147 +}
73148 +
73149 +int gr_check_secure_terminal(struct task_struct *task)
73150 +{
73151 + struct task_struct *p, *p2, *p3;
73152 + struct files_struct *files;
73153 + struct fdtable *fdt;
73154 + struct file *our_file = NULL, *file;
73155 + int i;
73156 +
73157 + if (task->signal->tty == NULL)
73158 + return 1;
73159 +
73160 + files = get_files_struct(task);
73161 + if (files != NULL) {
73162 + rcu_read_lock();
73163 + fdt = files_fdtable(files);
73164 + for (i=0; i < fdt->max_fds; i++) {
73165 + file = fcheck_files(files, i);
73166 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
73167 + get_file(file);
73168 + our_file = file;
73169 + }
73170 + }
73171 + rcu_read_unlock();
73172 + put_files_struct(files);
73173 + }
73174 +
73175 + if (our_file == NULL)
73176 + return 1;
73177 +
73178 + read_lock(&tasklist_lock);
73179 + do_each_thread(p2, p) {
73180 + files = get_files_struct(p);
73181 + if (files == NULL ||
73182 + (p->signal && p->signal->tty == task->signal->tty)) {
73183 + if (files != NULL)
73184 + put_files_struct(files);
73185 + continue;
73186 + }
73187 + rcu_read_lock();
73188 + fdt = files_fdtable(files);
73189 + for (i=0; i < fdt->max_fds; i++) {
73190 + file = fcheck_files(files, i);
73191 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
73192 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
73193 + p3 = task;
73194 + while (task_pid_nr(p3) > 0) {
73195 + if (p3 == p)
73196 + break;
73197 + p3 = p3->real_parent;
73198 + }
73199 + if (p3 == p)
73200 + break;
73201 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
73202 + gr_handle_alertkill(p);
73203 + rcu_read_unlock();
73204 + put_files_struct(files);
73205 + read_unlock(&tasklist_lock);
73206 + fput(our_file);
73207 + return 0;
73208 + }
73209 + }
73210 + rcu_read_unlock();
73211 + put_files_struct(files);
73212 + } while_each_thread(p2, p);
73213 + read_unlock(&tasklist_lock);
73214 +
73215 + fput(our_file);
73216 + return 1;
73217 +}
73218 +
73219 +ssize_t
73220 +write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
73221 +{
73222 + struct gr_arg_wrapper uwrap;
73223 + unsigned char *sprole_salt = NULL;
73224 + unsigned char *sprole_sum = NULL;
73225 + int error = 0;
73226 + int error2 = 0;
73227 + size_t req_count = 0;
73228 + unsigned char oldmode = 0;
73229 +
73230 + mutex_lock(&gr_dev_mutex);
73231 +
73232 + if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
73233 + error = -EPERM;
73234 + goto out;
73235 + }
73236 +
73237 +#ifdef CONFIG_COMPAT
73238 + pax_open_kernel();
73239 + if (is_compat_task()) {
73240 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
73241 + copy_gr_arg = &copy_gr_arg_compat;
73242 + copy_acl_object_label = &copy_acl_object_label_compat;
73243 + copy_acl_subject_label = &copy_acl_subject_label_compat;
73244 + copy_acl_role_label = &copy_acl_role_label_compat;
73245 + copy_acl_ip_label = &copy_acl_ip_label_compat;
73246 + copy_role_allowed_ip = &copy_role_allowed_ip_compat;
73247 + copy_role_transition = &copy_role_transition_compat;
73248 + copy_sprole_pw = &copy_sprole_pw_compat;
73249 + copy_gr_hash_struct = &copy_gr_hash_struct_compat;
73250 + copy_pointer_from_array = &copy_pointer_from_array_compat;
73251 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
73252 + } else {
73253 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
73254 + copy_gr_arg = &copy_gr_arg_normal;
73255 + copy_acl_object_label = &copy_acl_object_label_normal;
73256 + copy_acl_subject_label = &copy_acl_subject_label_normal;
73257 + copy_acl_role_label = &copy_acl_role_label_normal;
73258 + copy_acl_ip_label = &copy_acl_ip_label_normal;
73259 + copy_role_allowed_ip = &copy_role_allowed_ip_normal;
73260 + copy_role_transition = &copy_role_transition_normal;
73261 + copy_sprole_pw = &copy_sprole_pw_normal;
73262 + copy_gr_hash_struct = &copy_gr_hash_struct_normal;
73263 + copy_pointer_from_array = &copy_pointer_from_array_normal;
73264 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
73265 + }
73266 + pax_close_kernel();
73267 +#endif
73268 +
73269 + req_count = get_gr_arg_wrapper_size();
73270 +
73271 + if (count != req_count) {
73272 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
73273 + error = -EINVAL;
73274 + goto out;
73275 + }
73276 +
73277 +
73278 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
73279 + gr_auth_expires = 0;
73280 + gr_auth_attempts = 0;
73281 + }
73282 +
73283 + error = copy_gr_arg_wrapper(buf, &uwrap);
73284 + if (error)
73285 + goto out;
73286 +
73287 + error = copy_gr_arg(uwrap.arg, gr_usermode);
73288 + if (error)
73289 + goto out;
73290 +
73291 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
73292 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
73293 + time_after(gr_auth_expires, get_seconds())) {
73294 + error = -EBUSY;
73295 + goto out;
73296 + }
73297 +
73298 + /* if non-root trying to do anything other than use a special role,
73299 + do not attempt authentication, do not count towards authentication
73300 + locking
73301 + */
73302 +
73303 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
73304 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
73305 + gr_is_global_nonroot(current_uid())) {
73306 + error = -EPERM;
73307 + goto out;
73308 + }
73309 +
73310 + /* ensure pw and special role name are null terminated */
73311 +
73312 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
73313 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
73314 +
73315 + /* Okay.
73316 + * We have our enough of the argument structure..(we have yet
73317 + * to copy_from_user the tables themselves) . Copy the tables
73318 + * only if we need them, i.e. for loading operations. */
73319 +
73320 + switch (gr_usermode->mode) {
73321 + case GR_STATUS:
73322 + if (gr_acl_is_enabled()) {
73323 + error = 1;
73324 + if (!gr_check_secure_terminal(current))
73325 + error = 3;
73326 + } else
73327 + error = 2;
73328 + goto out;
73329 + case GR_SHUTDOWN:
73330 + if (gr_acl_is_enabled() && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
73331 + stop_machine(gr_rbac_disable, NULL, NULL);
73332 + free_variables(false);
73333 + memset(gr_usermode, 0, sizeof(struct gr_arg));
73334 + memset(gr_system_salt, 0, GR_SALT_LEN);
73335 + memset(gr_system_sum, 0, GR_SHA_LEN);
73336 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
73337 + } else if (gr_acl_is_enabled()) {
73338 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
73339 + error = -EPERM;
73340 + } else {
73341 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
73342 + error = -EAGAIN;
73343 + }
73344 + break;
73345 + case GR_ENABLE:
73346 + if (!gr_acl_is_enabled() && !(error2 = gracl_init(gr_usermode)))
73347 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
73348 + else {
73349 + if (gr_acl_is_enabled())
73350 + error = -EAGAIN;
73351 + else
73352 + error = error2;
73353 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
73354 + }
73355 + break;
73356 + case GR_OLDRELOAD:
73357 + oldmode = 1;
73358 + case GR_RELOAD:
73359 + if (!gr_acl_is_enabled()) {
73360 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
73361 + error = -EAGAIN;
73362 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
73363 + error2 = gracl_reload(gr_usermode, oldmode);
73364 + if (!error2)
73365 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
73366 + else {
73367 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
73368 + error = error2;
73369 + }
73370 + } else {
73371 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
73372 + error = -EPERM;
73373 + }
73374 + break;
73375 + case GR_SEGVMOD:
73376 + if (unlikely(!gr_acl_is_enabled())) {
73377 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
73378 + error = -EAGAIN;
73379 + break;
73380 + }
73381 +
73382 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
73383 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
73384 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
73385 + struct acl_subject_label *segvacl;
73386 + segvacl =
73387 + lookup_acl_subj_label(gr_usermode->segv_inode,
73388 + gr_usermode->segv_device,
73389 + current->role);
73390 + if (segvacl) {
73391 + segvacl->crashes = 0;
73392 + segvacl->expires = 0;
73393 + }
73394 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
73395 + gr_remove_uid(gr_usermode->segv_uid);
73396 + }
73397 + } else {
73398 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
73399 + error = -EPERM;
73400 + }
73401 + break;
73402 + case GR_SPROLE:
73403 + case GR_SPROLEPAM:
73404 + if (unlikely(!gr_acl_is_enabled())) {
73405 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
73406 + error = -EAGAIN;
73407 + break;
73408 + }
73409 +
73410 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
73411 + current->role->expires = 0;
73412 + current->role->auth_attempts = 0;
73413 + }
73414 +
73415 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
73416 + time_after(current->role->expires, get_seconds())) {
73417 + error = -EBUSY;
73418 + goto out;
73419 + }
73420 +
73421 + if (lookup_special_role_auth
73422 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
73423 + && ((!sprole_salt && !sprole_sum)
73424 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
73425 + char *p = "";
73426 + assign_special_role(gr_usermode->sp_role);
73427 + read_lock(&tasklist_lock);
73428 + if (current->real_parent)
73429 + p = current->real_parent->role->rolename;
73430 + read_unlock(&tasklist_lock);
73431 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
73432 + p, acl_sp_role_value);
73433 + } else {
73434 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
73435 + error = -EPERM;
73436 + if(!(current->role->auth_attempts++))
73437 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
73438 +
73439 + goto out;
73440 + }
73441 + break;
73442 + case GR_UNSPROLE:
73443 + if (unlikely(!gr_acl_is_enabled())) {
73444 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
73445 + error = -EAGAIN;
73446 + break;
73447 + }
73448 +
73449 + if (current->role->roletype & GR_ROLE_SPECIAL) {
73450 + char *p = "";
73451 + int i = 0;
73452 +
73453 + read_lock(&tasklist_lock);
73454 + if (current->real_parent) {
73455 + p = current->real_parent->role->rolename;
73456 + i = current->real_parent->acl_role_id;
73457 + }
73458 + read_unlock(&tasklist_lock);
73459 +
73460 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
73461 + gr_set_acls(1);
73462 + } else {
73463 + error = -EPERM;
73464 + goto out;
73465 + }
73466 + break;
73467 + default:
73468 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
73469 + error = -EINVAL;
73470 + break;
73471 + }
73472 +
73473 + if (error != -EPERM)
73474 + goto out;
73475 +
73476 + if(!(gr_auth_attempts++))
73477 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
73478 +
73479 + out:
73480 + mutex_unlock(&gr_dev_mutex);
73481 +
73482 + if (!error)
73483 + error = req_count;
73484 +
73485 + return error;
73486 +}
73487 +
73488 +int
73489 +gr_set_acls(const int type)
73490 +{
73491 + struct task_struct *task, *task2;
73492 + struct acl_role_label *role = current->role;
73493 + struct acl_subject_label *subj;
73494 + __u16 acl_role_id = current->acl_role_id;
73495 + const struct cred *cred;
73496 + int ret;
73497 +
73498 + rcu_read_lock();
73499 + read_lock(&tasklist_lock);
73500 + read_lock(&grsec_exec_file_lock);
73501 + do_each_thread(task2, task) {
73502 + /* check to see if we're called from the exit handler,
73503 + if so, only replace ACLs that have inherited the admin
73504 + ACL */
73505 +
73506 + if (type && (task->role != role ||
73507 + task->acl_role_id != acl_role_id))
73508 + continue;
73509 +
73510 + task->acl_role_id = 0;
73511 + task->acl_sp_role = 0;
73512 + task->inherited = 0;
73513 +
73514 + if (task->exec_file) {
73515 + cred = __task_cred(task);
73516 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
73517 + subj = __gr_get_subject_for_task(polstate, task, NULL);
73518 + if (subj == NULL) {
73519 + ret = -EINVAL;
73520 + read_unlock(&grsec_exec_file_lock);
73521 + read_unlock(&tasklist_lock);
73522 + rcu_read_unlock();
73523 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
73524 + return ret;
73525 + }
73526 + __gr_apply_subject_to_task(polstate, task, subj);
73527 + } else {
73528 + // it's a kernel process
73529 + task->role = polstate->kernel_role;
73530 + task->acl = polstate->kernel_role->root_label;
73531 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
73532 + task->acl->mode &= ~GR_PROCFIND;
73533 +#endif
73534 + }
73535 + } while_each_thread(task2, task);
73536 + read_unlock(&grsec_exec_file_lock);
73537 + read_unlock(&tasklist_lock);
73538 + rcu_read_unlock();
73539 +
73540 + return 0;
73541 +}
73542 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
73543 new file mode 100644
73544 index 0000000..39645c9
73545 --- /dev/null
73546 +++ b/grsecurity/gracl_res.c
73547 @@ -0,0 +1,68 @@
73548 +#include <linux/kernel.h>
73549 +#include <linux/sched.h>
73550 +#include <linux/gracl.h>
73551 +#include <linux/grinternal.h>
73552 +
73553 +static const char *restab_log[] = {
73554 + [RLIMIT_CPU] = "RLIMIT_CPU",
73555 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
73556 + [RLIMIT_DATA] = "RLIMIT_DATA",
73557 + [RLIMIT_STACK] = "RLIMIT_STACK",
73558 + [RLIMIT_CORE] = "RLIMIT_CORE",
73559 + [RLIMIT_RSS] = "RLIMIT_RSS",
73560 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
73561 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
73562 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
73563 + [RLIMIT_AS] = "RLIMIT_AS",
73564 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
73565 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
73566 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
73567 + [RLIMIT_NICE] = "RLIMIT_NICE",
73568 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
73569 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
73570 + [GR_CRASH_RES] = "RLIMIT_CRASH"
73571 +};
73572 +
73573 +void
73574 +gr_log_resource(const struct task_struct *task,
73575 + const int res, const unsigned long wanted, const int gt)
73576 +{
73577 + const struct cred *cred;
73578 + unsigned long rlim;
73579 +
73580 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
73581 + return;
73582 +
73583 + // not yet supported resource
73584 + if (unlikely(!restab_log[res]))
73585 + return;
73586 +
73587 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
73588 + rlim = task_rlimit_max(task, res);
73589 + else
73590 + rlim = task_rlimit(task, res);
73591 +
73592 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
73593 + return;
73594 +
73595 + rcu_read_lock();
73596 + cred = __task_cred(task);
73597 +
73598 + if (res == RLIMIT_NPROC &&
73599 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
73600 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
73601 + goto out_rcu_unlock;
73602 + else if (res == RLIMIT_MEMLOCK &&
73603 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
73604 + goto out_rcu_unlock;
73605 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
73606 + goto out_rcu_unlock;
73607 + rcu_read_unlock();
73608 +
73609 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
73610 +
73611 + return;
73612 +out_rcu_unlock:
73613 + rcu_read_unlock();
73614 + return;
73615 +}
73616 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
73617 new file mode 100644
73618 index 0000000..2040e61
73619 --- /dev/null
73620 +++ b/grsecurity/gracl_segv.c
73621 @@ -0,0 +1,313 @@
73622 +#include <linux/kernel.h>
73623 +#include <linux/mm.h>
73624 +#include <asm/uaccess.h>
73625 +#include <asm/errno.h>
73626 +#include <asm/mman.h>
73627 +#include <net/sock.h>
73628 +#include <linux/file.h>
73629 +#include <linux/fs.h>
73630 +#include <linux/net.h>
73631 +#include <linux/in.h>
73632 +#include <linux/slab.h>
73633 +#include <linux/types.h>
73634 +#include <linux/sched.h>
73635 +#include <linux/timer.h>
73636 +#include <linux/gracl.h>
73637 +#include <linux/grsecurity.h>
73638 +#include <linux/grinternal.h>
73639 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
73640 +#include <linux/magic.h>
73641 +#include <linux/pagemap.h>
73642 +#include "../fs/btrfs/async-thread.h"
73643 +#include "../fs/btrfs/ctree.h"
73644 +#include "../fs/btrfs/btrfs_inode.h"
73645 +#endif
73646 +
73647 +static struct crash_uid *uid_set;
73648 +static unsigned short uid_used;
73649 +static DEFINE_SPINLOCK(gr_uid_lock);
73650 +extern rwlock_t gr_inode_lock;
73651 +extern struct acl_subject_label *
73652 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
73653 + struct acl_role_label *role);
73654 +
73655 +static inline dev_t __get_dev(const struct dentry *dentry)
73656 +{
73657 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
73658 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
73659 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
73660 + else
73661 +#endif
73662 + return dentry->d_sb->s_dev;
73663 +}
73664 +
73665 +int
73666 +gr_init_uidset(void)
73667 +{
73668 + uid_set =
73669 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
73670 + uid_used = 0;
73671 +
73672 + return uid_set ? 1 : 0;
73673 +}
73674 +
73675 +void
73676 +gr_free_uidset(void)
73677 +{
73678 + if (uid_set) {
73679 + struct crash_uid *tmpset;
73680 + spin_lock(&gr_uid_lock);
73681 + tmpset = uid_set;
73682 + uid_set = NULL;
73683 + uid_used = 0;
73684 + spin_unlock(&gr_uid_lock);
73685 + if (tmpset)
73686 + kfree(tmpset);
73687 + }
73688 +
73689 + return;
73690 +}
73691 +
73692 +int
73693 +gr_find_uid(const uid_t uid)
73694 +{
73695 + struct crash_uid *tmp = uid_set;
73696 + uid_t buid;
73697 + int low = 0, high = uid_used - 1, mid;
73698 +
73699 + while (high >= low) {
73700 + mid = (low + high) >> 1;
73701 + buid = tmp[mid].uid;
73702 + if (buid == uid)
73703 + return mid;
73704 + if (buid > uid)
73705 + high = mid - 1;
73706 + if (buid < uid)
73707 + low = mid + 1;
73708 + }
73709 +
73710 + return -1;
73711 +}
73712 +
73713 +static __inline__ void
73714 +gr_insertsort(void)
73715 +{
73716 + unsigned short i, j;
73717 + struct crash_uid index;
73718 +
73719 + for (i = 1; i < uid_used; i++) {
73720 + index = uid_set[i];
73721 + j = i;
73722 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
73723 + uid_set[j] = uid_set[j - 1];
73724 + j--;
73725 + }
73726 + uid_set[j] = index;
73727 + }
73728 +
73729 + return;
73730 +}
73731 +
73732 +static __inline__ void
73733 +gr_insert_uid(const kuid_t kuid, const unsigned long expires)
73734 +{
73735 + int loc;
73736 + uid_t uid = GR_GLOBAL_UID(kuid);
73737 +
73738 + if (uid_used == GR_UIDTABLE_MAX)
73739 + return;
73740 +
73741 + loc = gr_find_uid(uid);
73742 +
73743 + if (loc >= 0) {
73744 + uid_set[loc].expires = expires;
73745 + return;
73746 + }
73747 +
73748 + uid_set[uid_used].uid = uid;
73749 + uid_set[uid_used].expires = expires;
73750 + uid_used++;
73751 +
73752 + gr_insertsort();
73753 +
73754 + return;
73755 +}
73756 +
73757 +void
73758 +gr_remove_uid(const unsigned short loc)
73759 +{
73760 + unsigned short i;
73761 +
73762 + for (i = loc + 1; i < uid_used; i++)
73763 + uid_set[i - 1] = uid_set[i];
73764 +
73765 + uid_used--;
73766 +
73767 + return;
73768 +}
73769 +
73770 +int
73771 +gr_check_crash_uid(const kuid_t kuid)
73772 +{
73773 + int loc;
73774 + int ret = 0;
73775 + uid_t uid;
73776 +
73777 + if (unlikely(!gr_acl_is_enabled()))
73778 + return 0;
73779 +
73780 + uid = GR_GLOBAL_UID(kuid);
73781 +
73782 + spin_lock(&gr_uid_lock);
73783 + loc = gr_find_uid(uid);
73784 +
73785 + if (loc < 0)
73786 + goto out_unlock;
73787 +
73788 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
73789 + gr_remove_uid(loc);
73790 + else
73791 + ret = 1;
73792 +
73793 +out_unlock:
73794 + spin_unlock(&gr_uid_lock);
73795 + return ret;
73796 +}
73797 +
73798 +static __inline__ int
73799 +proc_is_setxid(const struct cred *cred)
73800 +{
73801 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
73802 + !uid_eq(cred->uid, cred->fsuid))
73803 + return 1;
73804 + if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
73805 + !gid_eq(cred->gid, cred->fsgid))
73806 + return 1;
73807 +
73808 + return 0;
73809 +}
73810 +
73811 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
73812 +
73813 +void
73814 +gr_handle_crash(struct task_struct *task, const int sig)
73815 +{
73816 + struct acl_subject_label *curr;
73817 + struct task_struct *tsk, *tsk2;
73818 + const struct cred *cred;
73819 + const struct cred *cred2;
73820 +
73821 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
73822 + return;
73823 +
73824 + if (unlikely(!gr_acl_is_enabled()))
73825 + return;
73826 +
73827 + curr = task->acl;
73828 +
73829 + if (!(curr->resmask & (1U << GR_CRASH_RES)))
73830 + return;
73831 +
73832 + if (time_before_eq(curr->expires, get_seconds())) {
73833 + curr->expires = 0;
73834 + curr->crashes = 0;
73835 + }
73836 +
73837 + curr->crashes++;
73838 +
73839 + if (!curr->expires)
73840 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
73841 +
73842 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
73843 + time_after(curr->expires, get_seconds())) {
73844 + rcu_read_lock();
73845 + cred = __task_cred(task);
73846 + if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
73847 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
73848 + spin_lock(&gr_uid_lock);
73849 + gr_insert_uid(cred->uid, curr->expires);
73850 + spin_unlock(&gr_uid_lock);
73851 + curr->expires = 0;
73852 + curr->crashes = 0;
73853 + read_lock(&tasklist_lock);
73854 + do_each_thread(tsk2, tsk) {
73855 + cred2 = __task_cred(tsk);
73856 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
73857 + gr_fake_force_sig(SIGKILL, tsk);
73858 + } while_each_thread(tsk2, tsk);
73859 + read_unlock(&tasklist_lock);
73860 + } else {
73861 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
73862 + read_lock(&tasklist_lock);
73863 + read_lock(&grsec_exec_file_lock);
73864 + do_each_thread(tsk2, tsk) {
73865 + if (likely(tsk != task)) {
73866 + // if this thread has the same subject as the one that triggered
73867 + // RES_CRASH and it's the same binary, kill it
73868 + if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
73869 + gr_fake_force_sig(SIGKILL, tsk);
73870 + }
73871 + } while_each_thread(tsk2, tsk);
73872 + read_unlock(&grsec_exec_file_lock);
73873 + read_unlock(&tasklist_lock);
73874 + }
73875 + rcu_read_unlock();
73876 + }
73877 +
73878 + return;
73879 +}
73880 +
73881 +int
73882 +gr_check_crash_exec(const struct file *filp)
73883 +{
73884 + struct acl_subject_label *curr;
73885 +
73886 + if (unlikely(!gr_acl_is_enabled()))
73887 + return 0;
73888 +
73889 + read_lock(&gr_inode_lock);
73890 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
73891 + __get_dev(filp->f_path.dentry),
73892 + current->role);
73893 + read_unlock(&gr_inode_lock);
73894 +
73895 + if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
73896 + (!curr->crashes && !curr->expires))
73897 + return 0;
73898 +
73899 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
73900 + time_after(curr->expires, get_seconds()))
73901 + return 1;
73902 + else if (time_before_eq(curr->expires, get_seconds())) {
73903 + curr->crashes = 0;
73904 + curr->expires = 0;
73905 + }
73906 +
73907 + return 0;
73908 +}
73909 +
73910 +void
73911 +gr_handle_alertkill(struct task_struct *task)
73912 +{
73913 + struct acl_subject_label *curracl;
73914 + __u32 curr_ip;
73915 + struct task_struct *p, *p2;
73916 +
73917 + if (unlikely(!gr_acl_is_enabled()))
73918 + return;
73919 +
73920 + curracl = task->acl;
73921 + curr_ip = task->signal->curr_ip;
73922 +
73923 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
73924 + read_lock(&tasklist_lock);
73925 + do_each_thread(p2, p) {
73926 + if (p->signal->curr_ip == curr_ip)
73927 + gr_fake_force_sig(SIGKILL, p);
73928 + } while_each_thread(p2, p);
73929 + read_unlock(&tasklist_lock);
73930 + } else if (curracl->mode & GR_KILLPROC)
73931 + gr_fake_force_sig(SIGKILL, task);
73932 +
73933 + return;
73934 +}
73935 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
73936 new file mode 100644
73937 index 0000000..98011b0
73938 --- /dev/null
73939 +++ b/grsecurity/gracl_shm.c
73940 @@ -0,0 +1,40 @@
73941 +#include <linux/kernel.h>
73942 +#include <linux/mm.h>
73943 +#include <linux/sched.h>
73944 +#include <linux/file.h>
73945 +#include <linux/ipc.h>
73946 +#include <linux/gracl.h>
73947 +#include <linux/grsecurity.h>
73948 +#include <linux/grinternal.h>
73949 +
73950 +int
73951 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73952 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
73953 +{
73954 + struct task_struct *task;
73955 +
73956 + if (!gr_acl_is_enabled())
73957 + return 1;
73958 +
73959 + rcu_read_lock();
73960 + read_lock(&tasklist_lock);
73961 +
73962 + task = find_task_by_vpid(shm_cprid);
73963 +
73964 + if (unlikely(!task))
73965 + task = find_task_by_vpid(shm_lapid);
73966 +
73967 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
73968 + (task_pid_nr(task) == shm_lapid)) &&
73969 + (task->acl->mode & GR_PROTSHM) &&
73970 + (task->acl != current->acl))) {
73971 + read_unlock(&tasklist_lock);
73972 + rcu_read_unlock();
73973 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
73974 + return 0;
73975 + }
73976 + read_unlock(&tasklist_lock);
73977 + rcu_read_unlock();
73978 +
73979 + return 1;
73980 +}
73981 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
73982 new file mode 100644
73983 index 0000000..bc0be01
73984 --- /dev/null
73985 +++ b/grsecurity/grsec_chdir.c
73986 @@ -0,0 +1,19 @@
73987 +#include <linux/kernel.h>
73988 +#include <linux/sched.h>
73989 +#include <linux/fs.h>
73990 +#include <linux/file.h>
73991 +#include <linux/grsecurity.h>
73992 +#include <linux/grinternal.h>
73993 +
73994 +void
73995 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
73996 +{
73997 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
73998 + if ((grsec_enable_chdir && grsec_enable_group &&
73999 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
74000 + !grsec_enable_group)) {
74001 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
74002 + }
74003 +#endif
74004 + return;
74005 +}
74006 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
74007 new file mode 100644
74008 index 0000000..baa635c
74009 --- /dev/null
74010 +++ b/grsecurity/grsec_chroot.c
74011 @@ -0,0 +1,387 @@
74012 +#include <linux/kernel.h>
74013 +#include <linux/module.h>
74014 +#include <linux/sched.h>
74015 +#include <linux/file.h>
74016 +#include <linux/fs.h>
74017 +#include <linux/mount.h>
74018 +#include <linux/types.h>
74019 +#include "../fs/mount.h"
74020 +#include <linux/grsecurity.h>
74021 +#include <linux/grinternal.h>
74022 +
74023 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
74024 +int gr_init_ran;
74025 +#endif
74026 +
74027 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
74028 +{
74029 +#ifdef CONFIG_GRKERNSEC
74030 + if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
74031 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
74032 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
74033 + && gr_init_ran
74034 +#endif
74035 + )
74036 + task->gr_is_chrooted = 1;
74037 + else {
74038 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
74039 + if (task_pid_nr(task) == 1 && !gr_init_ran)
74040 + gr_init_ran = 1;
74041 +#endif
74042 + task->gr_is_chrooted = 0;
74043 + }
74044 +
74045 + task->gr_chroot_dentry = path->dentry;
74046 +#endif
74047 + return;
74048 +}
74049 +
74050 +void gr_clear_chroot_entries(struct task_struct *task)
74051 +{
74052 +#ifdef CONFIG_GRKERNSEC
74053 + task->gr_is_chrooted = 0;
74054 + task->gr_chroot_dentry = NULL;
74055 +#endif
74056 + return;
74057 +}
74058 +
74059 +int
74060 +gr_handle_chroot_unix(const pid_t pid)
74061 +{
74062 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
74063 + struct task_struct *p;
74064 +
74065 + if (unlikely(!grsec_enable_chroot_unix))
74066 + return 1;
74067 +
74068 + if (likely(!proc_is_chrooted(current)))
74069 + return 1;
74070 +
74071 + rcu_read_lock();
74072 + read_lock(&tasklist_lock);
74073 + p = find_task_by_vpid_unrestricted(pid);
74074 + if (unlikely(p && !have_same_root(current, p))) {
74075 + read_unlock(&tasklist_lock);
74076 + rcu_read_unlock();
74077 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
74078 + return 0;
74079 + }
74080 + read_unlock(&tasklist_lock);
74081 + rcu_read_unlock();
74082 +#endif
74083 + return 1;
74084 +}
74085 +
74086 +int
74087 +gr_handle_chroot_nice(void)
74088 +{
74089 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
74090 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
74091 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
74092 + return -EPERM;
74093 + }
74094 +#endif
74095 + return 0;
74096 +}
74097 +
74098 +int
74099 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
74100 +{
74101 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
74102 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
74103 + && proc_is_chrooted(current)) {
74104 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
74105 + return -EACCES;
74106 + }
74107 +#endif
74108 + return 0;
74109 +}
74110 +
74111 +int
74112 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
74113 +{
74114 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74115 + struct task_struct *p;
74116 + int ret = 0;
74117 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
74118 + return ret;
74119 +
74120 + read_lock(&tasklist_lock);
74121 + do_each_pid_task(pid, type, p) {
74122 + if (!have_same_root(current, p)) {
74123 + ret = 1;
74124 + goto out;
74125 + }
74126 + } while_each_pid_task(pid, type, p);
74127 +out:
74128 + read_unlock(&tasklist_lock);
74129 + return ret;
74130 +#endif
74131 + return 0;
74132 +}
74133 +
74134 +int
74135 +gr_pid_is_chrooted(struct task_struct *p)
74136 +{
74137 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74138 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
74139 + return 0;
74140 +
74141 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
74142 + !have_same_root(current, p)) {
74143 + return 1;
74144 + }
74145 +#endif
74146 + return 0;
74147 +}
74148 +
74149 +EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
74150 +
74151 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
74152 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
74153 +{
74154 + struct path path, currentroot;
74155 + int ret = 0;
74156 +
74157 + path.dentry = (struct dentry *)u_dentry;
74158 + path.mnt = (struct vfsmount *)u_mnt;
74159 + get_fs_root(current->fs, &currentroot);
74160 + if (path_is_under(&path, &currentroot))
74161 + ret = 1;
74162 + path_put(&currentroot);
74163 +
74164 + return ret;
74165 +}
74166 +#endif
74167 +
74168 +int
74169 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
74170 +{
74171 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
74172 + if (!grsec_enable_chroot_fchdir)
74173 + return 1;
74174 +
74175 + if (!proc_is_chrooted(current))
74176 + return 1;
74177 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
74178 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
74179 + return 0;
74180 + }
74181 +#endif
74182 + return 1;
74183 +}
74184 +
74185 +int
74186 +gr_chroot_fhandle(void)
74187 +{
74188 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
74189 + if (!grsec_enable_chroot_fchdir)
74190 + return 1;
74191 +
74192 + if (!proc_is_chrooted(current))
74193 + return 1;
74194 + else {
74195 + gr_log_noargs(GR_DONT_AUDIT, GR_CHROOT_FHANDLE_MSG);
74196 + return 0;
74197 + }
74198 +#endif
74199 + return 1;
74200 +}
74201 +
74202 +int
74203 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74204 + const time_t shm_createtime)
74205 +{
74206 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
74207 + struct task_struct *p;
74208 + time_t starttime;
74209 +
74210 + if (unlikely(!grsec_enable_chroot_shmat))
74211 + return 1;
74212 +
74213 + if (likely(!proc_is_chrooted(current)))
74214 + return 1;
74215 +
74216 + rcu_read_lock();
74217 + read_lock(&tasklist_lock);
74218 +
74219 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
74220 + starttime = p->start_time.tv_sec;
74221 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
74222 + if (have_same_root(current, p)) {
74223 + goto allow;
74224 + } else {
74225 + read_unlock(&tasklist_lock);
74226 + rcu_read_unlock();
74227 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
74228 + return 0;
74229 + }
74230 + }
74231 + /* creator exited, pid reuse, fall through to next check */
74232 + }
74233 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
74234 + if (unlikely(!have_same_root(current, p))) {
74235 + read_unlock(&tasklist_lock);
74236 + rcu_read_unlock();
74237 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
74238 + return 0;
74239 + }
74240 + }
74241 +
74242 +allow:
74243 + read_unlock(&tasklist_lock);
74244 + rcu_read_unlock();
74245 +#endif
74246 + return 1;
74247 +}
74248 +
74249 +void
74250 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
74251 +{
74252 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
74253 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
74254 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
74255 +#endif
74256 + return;
74257 +}
74258 +
74259 +int
74260 +gr_handle_chroot_mknod(const struct dentry *dentry,
74261 + const struct vfsmount *mnt, const int mode)
74262 +{
74263 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
74264 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
74265 + proc_is_chrooted(current)) {
74266 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
74267 + return -EPERM;
74268 + }
74269 +#endif
74270 + return 0;
74271 +}
74272 +
74273 +int
74274 +gr_handle_chroot_mount(const struct dentry *dentry,
74275 + const struct vfsmount *mnt, const char *dev_name)
74276 +{
74277 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
74278 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
74279 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
74280 + return -EPERM;
74281 + }
74282 +#endif
74283 + return 0;
74284 +}
74285 +
74286 +int
74287 +gr_handle_chroot_pivot(void)
74288 +{
74289 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
74290 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
74291 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
74292 + return -EPERM;
74293 + }
74294 +#endif
74295 + return 0;
74296 +}
74297 +
74298 +int
74299 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
74300 +{
74301 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
74302 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
74303 + !gr_is_outside_chroot(dentry, mnt)) {
74304 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
74305 + return -EPERM;
74306 + }
74307 +#endif
74308 + return 0;
74309 +}
74310 +
74311 +extern const char *captab_log[];
74312 +extern int captab_log_entries;
74313 +
74314 +int
74315 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
74316 +{
74317 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74318 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
74319 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
74320 + if (cap_raised(chroot_caps, cap)) {
74321 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
74322 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
74323 + }
74324 + return 0;
74325 + }
74326 + }
74327 +#endif
74328 + return 1;
74329 +}
74330 +
74331 +int
74332 +gr_chroot_is_capable(const int cap)
74333 +{
74334 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74335 + return gr_task_chroot_is_capable(current, current_cred(), cap);
74336 +#endif
74337 + return 1;
74338 +}
74339 +
74340 +int
74341 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
74342 +{
74343 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74344 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
74345 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
74346 + if (cap_raised(chroot_caps, cap)) {
74347 + return 0;
74348 + }
74349 + }
74350 +#endif
74351 + return 1;
74352 +}
74353 +
74354 +int
74355 +gr_chroot_is_capable_nolog(const int cap)
74356 +{
74357 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74358 + return gr_task_chroot_is_capable_nolog(current, cap);
74359 +#endif
74360 + return 1;
74361 +}
74362 +
74363 +int
74364 +gr_handle_chroot_sysctl(const int op)
74365 +{
74366 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
74367 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
74368 + proc_is_chrooted(current))
74369 + return -EACCES;
74370 +#endif
74371 + return 0;
74372 +}
74373 +
74374 +void
74375 +gr_handle_chroot_chdir(const struct path *path)
74376 +{
74377 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
74378 + if (grsec_enable_chroot_chdir)
74379 + set_fs_pwd(current->fs, path);
74380 +#endif
74381 + return;
74382 +}
74383 +
74384 +int
74385 +gr_handle_chroot_chmod(const struct dentry *dentry,
74386 + const struct vfsmount *mnt, const int mode)
74387 +{
74388 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
74389 + /* allow chmod +s on directories, but not files */
74390 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
74391 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
74392 + proc_is_chrooted(current)) {
74393 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
74394 + return -EPERM;
74395 + }
74396 +#endif
74397 + return 0;
74398 +}
74399 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
74400 new file mode 100644
74401 index 0000000..de31e65
74402 --- /dev/null
74403 +++ b/grsecurity/grsec_disabled.c
74404 @@ -0,0 +1,434 @@
74405 +#include <linux/kernel.h>
74406 +#include <linux/module.h>
74407 +#include <linux/sched.h>
74408 +#include <linux/file.h>
74409 +#include <linux/fs.h>
74410 +#include <linux/kdev_t.h>
74411 +#include <linux/net.h>
74412 +#include <linux/in.h>
74413 +#include <linux/ip.h>
74414 +#include <linux/skbuff.h>
74415 +#include <linux/sysctl.h>
74416 +
74417 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
74418 +void
74419 +pax_set_initial_flags(struct linux_binprm *bprm)
74420 +{
74421 + return;
74422 +}
74423 +#endif
74424 +
74425 +#ifdef CONFIG_SYSCTL
74426 +__u32
74427 +gr_handle_sysctl(const struct ctl_table * table, const int op)
74428 +{
74429 + return 0;
74430 +}
74431 +#endif
74432 +
74433 +#ifdef CONFIG_TASKSTATS
74434 +int gr_is_taskstats_denied(int pid)
74435 +{
74436 + return 0;
74437 +}
74438 +#endif
74439 +
74440 +int
74441 +gr_acl_is_enabled(void)
74442 +{
74443 + return 0;
74444 +}
74445 +
74446 +void
74447 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
74448 +{
74449 + return;
74450 +}
74451 +
74452 +int
74453 +gr_handle_rawio(const struct inode *inode)
74454 +{
74455 + return 0;
74456 +}
74457 +
74458 +void
74459 +gr_acl_handle_psacct(struct task_struct *task, const long code)
74460 +{
74461 + return;
74462 +}
74463 +
74464 +int
74465 +gr_handle_ptrace(struct task_struct *task, const long request)
74466 +{
74467 + return 0;
74468 +}
74469 +
74470 +int
74471 +gr_handle_proc_ptrace(struct task_struct *task)
74472 +{
74473 + return 0;
74474 +}
74475 +
74476 +int
74477 +gr_set_acls(const int type)
74478 +{
74479 + return 0;
74480 +}
74481 +
74482 +int
74483 +gr_check_hidden_task(const struct task_struct *tsk)
74484 +{
74485 + return 0;
74486 +}
74487 +
74488 +int
74489 +gr_check_protected_task(const struct task_struct *task)
74490 +{
74491 + return 0;
74492 +}
74493 +
74494 +int
74495 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
74496 +{
74497 + return 0;
74498 +}
74499 +
74500 +void
74501 +gr_copy_label(struct task_struct *tsk)
74502 +{
74503 + return;
74504 +}
74505 +
74506 +void
74507 +gr_set_pax_flags(struct task_struct *task)
74508 +{
74509 + return;
74510 +}
74511 +
74512 +int
74513 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
74514 + const int unsafe_share)
74515 +{
74516 + return 0;
74517 +}
74518 +
74519 +void
74520 +gr_handle_delete(const ino_t ino, const dev_t dev)
74521 +{
74522 + return;
74523 +}
74524 +
74525 +void
74526 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
74527 +{
74528 + return;
74529 +}
74530 +
74531 +void
74532 +gr_handle_crash(struct task_struct *task, const int sig)
74533 +{
74534 + return;
74535 +}
74536 +
74537 +int
74538 +gr_check_crash_exec(const struct file *filp)
74539 +{
74540 + return 0;
74541 +}
74542 +
74543 +int
74544 +gr_check_crash_uid(const kuid_t uid)
74545 +{
74546 + return 0;
74547 +}
74548 +
74549 +void
74550 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
74551 + struct dentry *old_dentry,
74552 + struct dentry *new_dentry,
74553 + struct vfsmount *mnt, const __u8 replace, unsigned int flags)
74554 +{
74555 + return;
74556 +}
74557 +
74558 +int
74559 +gr_search_socket(const int family, const int type, const int protocol)
74560 +{
74561 + return 1;
74562 +}
74563 +
74564 +int
74565 +gr_search_connectbind(const int mode, const struct socket *sock,
74566 + const struct sockaddr_in *addr)
74567 +{
74568 + return 0;
74569 +}
74570 +
74571 +void
74572 +gr_handle_alertkill(struct task_struct *task)
74573 +{
74574 + return;
74575 +}
74576 +
74577 +__u32
74578 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
74579 +{
74580 + return 1;
74581 +}
74582 +
74583 +__u32
74584 +gr_acl_handle_hidden_file(const struct dentry * dentry,
74585 + const struct vfsmount * mnt)
74586 +{
74587 + return 1;
74588 +}
74589 +
74590 +__u32
74591 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
74592 + int acc_mode)
74593 +{
74594 + return 1;
74595 +}
74596 +
74597 +__u32
74598 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
74599 +{
74600 + return 1;
74601 +}
74602 +
74603 +__u32
74604 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
74605 +{
74606 + return 1;
74607 +}
74608 +
74609 +int
74610 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
74611 + unsigned int *vm_flags)
74612 +{
74613 + return 1;
74614 +}
74615 +
74616 +__u32
74617 +gr_acl_handle_truncate(const struct dentry * dentry,
74618 + const struct vfsmount * mnt)
74619 +{
74620 + return 1;
74621 +}
74622 +
74623 +__u32
74624 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
74625 +{
74626 + return 1;
74627 +}
74628 +
74629 +__u32
74630 +gr_acl_handle_access(const struct dentry * dentry,
74631 + const struct vfsmount * mnt, const int fmode)
74632 +{
74633 + return 1;
74634 +}
74635 +
74636 +__u32
74637 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
74638 + umode_t *mode)
74639 +{
74640 + return 1;
74641 +}
74642 +
74643 +__u32
74644 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
74645 +{
74646 + return 1;
74647 +}
74648 +
74649 +__u32
74650 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
74651 +{
74652 + return 1;
74653 +}
74654 +
74655 +__u32
74656 +gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
74657 +{
74658 + return 1;
74659 +}
74660 +
74661 +void
74662 +grsecurity_init(void)
74663 +{
74664 + return;
74665 +}
74666 +
74667 +umode_t gr_acl_umask(void)
74668 +{
74669 + return 0;
74670 +}
74671 +
74672 +__u32
74673 +gr_acl_handle_mknod(const struct dentry * new_dentry,
74674 + const struct dentry * parent_dentry,
74675 + const struct vfsmount * parent_mnt,
74676 + const int mode)
74677 +{
74678 + return 1;
74679 +}
74680 +
74681 +__u32
74682 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
74683 + const struct dentry * parent_dentry,
74684 + const struct vfsmount * parent_mnt)
74685 +{
74686 + return 1;
74687 +}
74688 +
74689 +__u32
74690 +gr_acl_handle_symlink(const struct dentry * new_dentry,
74691 + const struct dentry * parent_dentry,
74692 + const struct vfsmount * parent_mnt, const struct filename *from)
74693 +{
74694 + return 1;
74695 +}
74696 +
74697 +__u32
74698 +gr_acl_handle_link(const struct dentry * new_dentry,
74699 + const struct dentry * parent_dentry,
74700 + const struct vfsmount * parent_mnt,
74701 + const struct dentry * old_dentry,
74702 + const struct vfsmount * old_mnt, const struct filename *to)
74703 +{
74704 + return 1;
74705 +}
74706 +
74707 +int
74708 +gr_acl_handle_rename(const struct dentry *new_dentry,
74709 + const struct dentry *parent_dentry,
74710 + const struct vfsmount *parent_mnt,
74711 + const struct dentry *old_dentry,
74712 + const struct inode *old_parent_inode,
74713 + const struct vfsmount *old_mnt, const struct filename *newname,
74714 + unsigned int flags)
74715 +{
74716 + return 0;
74717 +}
74718 +
74719 +int
74720 +gr_acl_handle_filldir(const struct file *file, const char *name,
74721 + const int namelen, const ino_t ino)
74722 +{
74723 + return 1;
74724 +}
74725 +
74726 +int
74727 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74728 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
74729 +{
74730 + return 1;
74731 +}
74732 +
74733 +int
74734 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
74735 +{
74736 + return 0;
74737 +}
74738 +
74739 +int
74740 +gr_search_accept(const struct socket *sock)
74741 +{
74742 + return 0;
74743 +}
74744 +
74745 +int
74746 +gr_search_listen(const struct socket *sock)
74747 +{
74748 + return 0;
74749 +}
74750 +
74751 +int
74752 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
74753 +{
74754 + return 0;
74755 +}
74756 +
74757 +__u32
74758 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
74759 +{
74760 + return 1;
74761 +}
74762 +
74763 +__u32
74764 +gr_acl_handle_creat(const struct dentry * dentry,
74765 + const struct dentry * p_dentry,
74766 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
74767 + const int imode)
74768 +{
74769 + return 1;
74770 +}
74771 +
74772 +void
74773 +gr_acl_handle_exit(void)
74774 +{
74775 + return;
74776 +}
74777 +
74778 +int
74779 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
74780 +{
74781 + return 1;
74782 +}
74783 +
74784 +void
74785 +gr_set_role_label(const kuid_t uid, const kgid_t gid)
74786 +{
74787 + return;
74788 +}
74789 +
74790 +int
74791 +gr_acl_handle_procpidmem(const struct task_struct *task)
74792 +{
74793 + return 0;
74794 +}
74795 +
74796 +int
74797 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
74798 +{
74799 + return 0;
74800 +}
74801 +
74802 +int
74803 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
74804 +{
74805 + return 0;
74806 +}
74807 +
74808 +int
74809 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
74810 +{
74811 + return 0;
74812 +}
74813 +
74814 +int
74815 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
74816 +{
74817 + return 0;
74818 +}
74819 +
74820 +int gr_acl_enable_at_secure(void)
74821 +{
74822 + return 0;
74823 +}
74824 +
74825 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
74826 +{
74827 + return dentry->d_sb->s_dev;
74828 +}
74829 +
74830 +void gr_put_exec_file(struct task_struct *task)
74831 +{
74832 + return;
74833 +}
74834 +
74835 +#ifdef CONFIG_SECURITY
74836 +EXPORT_SYMBOL_GPL(gr_check_user_change);
74837 +EXPORT_SYMBOL_GPL(gr_check_group_change);
74838 +#endif
74839 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
74840 new file mode 100644
74841 index 0000000..14638ff
74842 --- /dev/null
74843 +++ b/grsecurity/grsec_exec.c
74844 @@ -0,0 +1,188 @@
74845 +#include <linux/kernel.h>
74846 +#include <linux/sched.h>
74847 +#include <linux/file.h>
74848 +#include <linux/binfmts.h>
74849 +#include <linux/fs.h>
74850 +#include <linux/types.h>
74851 +#include <linux/grdefs.h>
74852 +#include <linux/grsecurity.h>
74853 +#include <linux/grinternal.h>
74854 +#include <linux/capability.h>
74855 +#include <linux/module.h>
74856 +#include <linux/compat.h>
74857 +
74858 +#include <asm/uaccess.h>
74859 +
74860 +#ifdef CONFIG_GRKERNSEC_EXECLOG
74861 +static char gr_exec_arg_buf[132];
74862 +static DEFINE_MUTEX(gr_exec_arg_mutex);
74863 +#endif
74864 +
74865 +struct user_arg_ptr {
74866 +#ifdef CONFIG_COMPAT
74867 + bool is_compat;
74868 +#endif
74869 + union {
74870 + const char __user *const __user *native;
74871 +#ifdef CONFIG_COMPAT
74872 + const compat_uptr_t __user *compat;
74873 +#endif
74874 + } ptr;
74875 +};
74876 +
74877 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
74878 +
74879 +void
74880 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
74881 +{
74882 +#ifdef CONFIG_GRKERNSEC_EXECLOG
74883 + char *grarg = gr_exec_arg_buf;
74884 + unsigned int i, x, execlen = 0;
74885 + char c;
74886 +
74887 + if (!((grsec_enable_execlog && grsec_enable_group &&
74888 + in_group_p(grsec_audit_gid))
74889 + || (grsec_enable_execlog && !grsec_enable_group)))
74890 + return;
74891 +
74892 + mutex_lock(&gr_exec_arg_mutex);
74893 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
74894 +
74895 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
74896 + const char __user *p;
74897 + unsigned int len;
74898 +
74899 + p = get_user_arg_ptr(argv, i);
74900 + if (IS_ERR(p))
74901 + goto log;
74902 +
74903 + len = strnlen_user(p, 128 - execlen);
74904 + if (len > 128 - execlen)
74905 + len = 128 - execlen;
74906 + else if (len > 0)
74907 + len--;
74908 + if (copy_from_user(grarg + execlen, p, len))
74909 + goto log;
74910 +
74911 + /* rewrite unprintable characters */
74912 + for (x = 0; x < len; x++) {
74913 + c = *(grarg + execlen + x);
74914 + if (c < 32 || c > 126)
74915 + *(grarg + execlen + x) = ' ';
74916 + }
74917 +
74918 + execlen += len;
74919 + *(grarg + execlen) = ' ';
74920 + *(grarg + execlen + 1) = '\0';
74921 + execlen++;
74922 + }
74923 +
74924 + log:
74925 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
74926 + bprm->file->f_path.mnt, grarg);
74927 + mutex_unlock(&gr_exec_arg_mutex);
74928 +#endif
74929 + return;
74930 +}
74931 +
74932 +#ifdef CONFIG_GRKERNSEC
74933 +extern int gr_acl_is_capable(const int cap);
74934 +extern int gr_acl_is_capable_nolog(const int cap);
74935 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74936 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
74937 +extern int gr_chroot_is_capable(const int cap);
74938 +extern int gr_chroot_is_capable_nolog(const int cap);
74939 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74940 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
74941 +#endif
74942 +
74943 +const char *captab_log[] = {
74944 + "CAP_CHOWN",
74945 + "CAP_DAC_OVERRIDE",
74946 + "CAP_DAC_READ_SEARCH",
74947 + "CAP_FOWNER",
74948 + "CAP_FSETID",
74949 + "CAP_KILL",
74950 + "CAP_SETGID",
74951 + "CAP_SETUID",
74952 + "CAP_SETPCAP",
74953 + "CAP_LINUX_IMMUTABLE",
74954 + "CAP_NET_BIND_SERVICE",
74955 + "CAP_NET_BROADCAST",
74956 + "CAP_NET_ADMIN",
74957 + "CAP_NET_RAW",
74958 + "CAP_IPC_LOCK",
74959 + "CAP_IPC_OWNER",
74960 + "CAP_SYS_MODULE",
74961 + "CAP_SYS_RAWIO",
74962 + "CAP_SYS_CHROOT",
74963 + "CAP_SYS_PTRACE",
74964 + "CAP_SYS_PACCT",
74965 + "CAP_SYS_ADMIN",
74966 + "CAP_SYS_BOOT",
74967 + "CAP_SYS_NICE",
74968 + "CAP_SYS_RESOURCE",
74969 + "CAP_SYS_TIME",
74970 + "CAP_SYS_TTY_CONFIG",
74971 + "CAP_MKNOD",
74972 + "CAP_LEASE",
74973 + "CAP_AUDIT_WRITE",
74974 + "CAP_AUDIT_CONTROL",
74975 + "CAP_SETFCAP",
74976 + "CAP_MAC_OVERRIDE",
74977 + "CAP_MAC_ADMIN",
74978 + "CAP_SYSLOG",
74979 + "CAP_WAKE_ALARM",
74980 + "CAP_BLOCK_SUSPEND"
74981 +};
74982 +
74983 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
74984 +
74985 +int gr_is_capable(const int cap)
74986 +{
74987 +#ifdef CONFIG_GRKERNSEC
74988 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
74989 + return 1;
74990 + return 0;
74991 +#else
74992 + return 1;
74993 +#endif
74994 +}
74995 +
74996 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
74997 +{
74998 +#ifdef CONFIG_GRKERNSEC
74999 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
75000 + return 1;
75001 + return 0;
75002 +#else
75003 + return 1;
75004 +#endif
75005 +}
75006 +
75007 +int gr_is_capable_nolog(const int cap)
75008 +{
75009 +#ifdef CONFIG_GRKERNSEC
75010 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
75011 + return 1;
75012 + return 0;
75013 +#else
75014 + return 1;
75015 +#endif
75016 +}
75017 +
75018 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
75019 +{
75020 +#ifdef CONFIG_GRKERNSEC
75021 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
75022 + return 1;
75023 + return 0;
75024 +#else
75025 + return 1;
75026 +#endif
75027 +}
75028 +
75029 +EXPORT_SYMBOL_GPL(gr_is_capable);
75030 +EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
75031 +EXPORT_SYMBOL_GPL(gr_task_is_capable);
75032 +EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
75033 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
75034 new file mode 100644
75035 index 0000000..06cc6ea
75036 --- /dev/null
75037 +++ b/grsecurity/grsec_fifo.c
75038 @@ -0,0 +1,24 @@
75039 +#include <linux/kernel.h>
75040 +#include <linux/sched.h>
75041 +#include <linux/fs.h>
75042 +#include <linux/file.h>
75043 +#include <linux/grinternal.h>
75044 +
75045 +int
75046 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
75047 + const struct dentry *dir, const int flag, const int acc_mode)
75048 +{
75049 +#ifdef CONFIG_GRKERNSEC_FIFO
75050 + const struct cred *cred = current_cred();
75051 +
75052 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
75053 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
75054 + !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
75055 + !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
75056 + if (!inode_permission(dentry->d_inode, acc_mode))
75057 + 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));
75058 + return -EACCES;
75059 + }
75060 +#endif
75061 + return 0;
75062 +}
75063 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
75064 new file mode 100644
75065 index 0000000..8ca18bf
75066 --- /dev/null
75067 +++ b/grsecurity/grsec_fork.c
75068 @@ -0,0 +1,23 @@
75069 +#include <linux/kernel.h>
75070 +#include <linux/sched.h>
75071 +#include <linux/grsecurity.h>
75072 +#include <linux/grinternal.h>
75073 +#include <linux/errno.h>
75074 +
75075 +void
75076 +gr_log_forkfail(const int retval)
75077 +{
75078 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
75079 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
75080 + switch (retval) {
75081 + case -EAGAIN:
75082 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
75083 + break;
75084 + case -ENOMEM:
75085 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
75086 + break;
75087 + }
75088 + }
75089 +#endif
75090 + return;
75091 +}
75092 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
75093 new file mode 100644
75094 index 0000000..b7cb191
75095 --- /dev/null
75096 +++ b/grsecurity/grsec_init.c
75097 @@ -0,0 +1,286 @@
75098 +#include <linux/kernel.h>
75099 +#include <linux/sched.h>
75100 +#include <linux/mm.h>
75101 +#include <linux/gracl.h>
75102 +#include <linux/slab.h>
75103 +#include <linux/vmalloc.h>
75104 +#include <linux/percpu.h>
75105 +#include <linux/module.h>
75106 +
75107 +int grsec_enable_ptrace_readexec;
75108 +int grsec_enable_setxid;
75109 +int grsec_enable_symlinkown;
75110 +kgid_t grsec_symlinkown_gid;
75111 +int grsec_enable_brute;
75112 +int grsec_enable_link;
75113 +int grsec_enable_dmesg;
75114 +int grsec_enable_harden_ptrace;
75115 +int grsec_enable_harden_ipc;
75116 +int grsec_enable_fifo;
75117 +int grsec_enable_execlog;
75118 +int grsec_enable_signal;
75119 +int grsec_enable_forkfail;
75120 +int grsec_enable_audit_ptrace;
75121 +int grsec_enable_time;
75122 +int grsec_enable_group;
75123 +kgid_t grsec_audit_gid;
75124 +int grsec_enable_chdir;
75125 +int grsec_enable_mount;
75126 +int grsec_enable_rofs;
75127 +int grsec_deny_new_usb;
75128 +int grsec_enable_chroot_findtask;
75129 +int grsec_enable_chroot_mount;
75130 +int grsec_enable_chroot_shmat;
75131 +int grsec_enable_chroot_fchdir;
75132 +int grsec_enable_chroot_double;
75133 +int grsec_enable_chroot_pivot;
75134 +int grsec_enable_chroot_chdir;
75135 +int grsec_enable_chroot_chmod;
75136 +int grsec_enable_chroot_mknod;
75137 +int grsec_enable_chroot_nice;
75138 +int grsec_enable_chroot_execlog;
75139 +int grsec_enable_chroot_caps;
75140 +int grsec_enable_chroot_sysctl;
75141 +int grsec_enable_chroot_unix;
75142 +int grsec_enable_tpe;
75143 +kgid_t grsec_tpe_gid;
75144 +int grsec_enable_blackhole;
75145 +#ifdef CONFIG_IPV6_MODULE
75146 +EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
75147 +#endif
75148 +int grsec_lastack_retries;
75149 +int grsec_enable_tpe_all;
75150 +int grsec_enable_tpe_invert;
75151 +int grsec_enable_socket_all;
75152 +kgid_t grsec_socket_all_gid;
75153 +int grsec_enable_socket_client;
75154 +kgid_t grsec_socket_client_gid;
75155 +int grsec_enable_socket_server;
75156 +kgid_t grsec_socket_server_gid;
75157 +int grsec_resource_logging;
75158 +int grsec_disable_privio;
75159 +int grsec_enable_log_rwxmaps;
75160 +int grsec_lock;
75161 +
75162 +DEFINE_SPINLOCK(grsec_alert_lock);
75163 +unsigned long grsec_alert_wtime = 0;
75164 +unsigned long grsec_alert_fyet = 0;
75165 +
75166 +DEFINE_SPINLOCK(grsec_audit_lock);
75167 +
75168 +DEFINE_RWLOCK(grsec_exec_file_lock);
75169 +
75170 +char *gr_shared_page[4];
75171 +
75172 +char *gr_alert_log_fmt;
75173 +char *gr_audit_log_fmt;
75174 +char *gr_alert_log_buf;
75175 +char *gr_audit_log_buf;
75176 +
75177 +extern struct gr_arg *gr_usermode;
75178 +extern unsigned char *gr_system_salt;
75179 +extern unsigned char *gr_system_sum;
75180 +
75181 +void __init
75182 +grsecurity_init(void)
75183 +{
75184 + int j;
75185 + /* create the per-cpu shared pages */
75186 +
75187 +#ifdef CONFIG_X86
75188 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
75189 +#endif
75190 +
75191 + for (j = 0; j < 4; j++) {
75192 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
75193 + if (gr_shared_page[j] == NULL) {
75194 + panic("Unable to allocate grsecurity shared page");
75195 + return;
75196 + }
75197 + }
75198 +
75199 + /* allocate log buffers */
75200 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
75201 + if (!gr_alert_log_fmt) {
75202 + panic("Unable to allocate grsecurity alert log format buffer");
75203 + return;
75204 + }
75205 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
75206 + if (!gr_audit_log_fmt) {
75207 + panic("Unable to allocate grsecurity audit log format buffer");
75208 + return;
75209 + }
75210 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
75211 + if (!gr_alert_log_buf) {
75212 + panic("Unable to allocate grsecurity alert log buffer");
75213 + return;
75214 + }
75215 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
75216 + if (!gr_audit_log_buf) {
75217 + panic("Unable to allocate grsecurity audit log buffer");
75218 + return;
75219 + }
75220 +
75221 + /* allocate memory for authentication structure */
75222 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
75223 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
75224 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
75225 +
75226 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
75227 + panic("Unable to allocate grsecurity authentication structure");
75228 + return;
75229 + }
75230 +
75231 +#ifdef CONFIG_GRKERNSEC_IO
75232 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
75233 + grsec_disable_privio = 1;
75234 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
75235 + grsec_disable_privio = 1;
75236 +#else
75237 + grsec_disable_privio = 0;
75238 +#endif
75239 +#endif
75240 +
75241 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
75242 + /* for backward compatibility, tpe_invert always defaults to on if
75243 + enabled in the kernel
75244 + */
75245 + grsec_enable_tpe_invert = 1;
75246 +#endif
75247 +
75248 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
75249 +#ifndef CONFIG_GRKERNSEC_SYSCTL
75250 + grsec_lock = 1;
75251 +#endif
75252 +
75253 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75254 + grsec_enable_log_rwxmaps = 1;
75255 +#endif
75256 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
75257 + grsec_enable_group = 1;
75258 + grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
75259 +#endif
75260 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
75261 + grsec_enable_ptrace_readexec = 1;
75262 +#endif
75263 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
75264 + grsec_enable_chdir = 1;
75265 +#endif
75266 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
75267 + grsec_enable_harden_ptrace = 1;
75268 +#endif
75269 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
75270 + grsec_enable_harden_ipc = 1;
75271 +#endif
75272 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75273 + grsec_enable_mount = 1;
75274 +#endif
75275 +#ifdef CONFIG_GRKERNSEC_LINK
75276 + grsec_enable_link = 1;
75277 +#endif
75278 +#ifdef CONFIG_GRKERNSEC_BRUTE
75279 + grsec_enable_brute = 1;
75280 +#endif
75281 +#ifdef CONFIG_GRKERNSEC_DMESG
75282 + grsec_enable_dmesg = 1;
75283 +#endif
75284 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75285 + grsec_enable_blackhole = 1;
75286 + grsec_lastack_retries = 4;
75287 +#endif
75288 +#ifdef CONFIG_GRKERNSEC_FIFO
75289 + grsec_enable_fifo = 1;
75290 +#endif
75291 +#ifdef CONFIG_GRKERNSEC_EXECLOG
75292 + grsec_enable_execlog = 1;
75293 +#endif
75294 +#ifdef CONFIG_GRKERNSEC_SETXID
75295 + grsec_enable_setxid = 1;
75296 +#endif
75297 +#ifdef CONFIG_GRKERNSEC_SIGNAL
75298 + grsec_enable_signal = 1;
75299 +#endif
75300 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
75301 + grsec_enable_forkfail = 1;
75302 +#endif
75303 +#ifdef CONFIG_GRKERNSEC_TIME
75304 + grsec_enable_time = 1;
75305 +#endif
75306 +#ifdef CONFIG_GRKERNSEC_RESLOG
75307 + grsec_resource_logging = 1;
75308 +#endif
75309 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
75310 + grsec_enable_chroot_findtask = 1;
75311 +#endif
75312 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
75313 + grsec_enable_chroot_unix = 1;
75314 +#endif
75315 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
75316 + grsec_enable_chroot_mount = 1;
75317 +#endif
75318 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
75319 + grsec_enable_chroot_fchdir = 1;
75320 +#endif
75321 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
75322 + grsec_enable_chroot_shmat = 1;
75323 +#endif
75324 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
75325 + grsec_enable_audit_ptrace = 1;
75326 +#endif
75327 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
75328 + grsec_enable_chroot_double = 1;
75329 +#endif
75330 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
75331 + grsec_enable_chroot_pivot = 1;
75332 +#endif
75333 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
75334 + grsec_enable_chroot_chdir = 1;
75335 +#endif
75336 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
75337 + grsec_enable_chroot_chmod = 1;
75338 +#endif
75339 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
75340 + grsec_enable_chroot_mknod = 1;
75341 +#endif
75342 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
75343 + grsec_enable_chroot_nice = 1;
75344 +#endif
75345 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
75346 + grsec_enable_chroot_execlog = 1;
75347 +#endif
75348 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
75349 + grsec_enable_chroot_caps = 1;
75350 +#endif
75351 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
75352 + grsec_enable_chroot_sysctl = 1;
75353 +#endif
75354 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
75355 + grsec_enable_symlinkown = 1;
75356 + grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
75357 +#endif
75358 +#ifdef CONFIG_GRKERNSEC_TPE
75359 + grsec_enable_tpe = 1;
75360 + grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
75361 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
75362 + grsec_enable_tpe_all = 1;
75363 +#endif
75364 +#endif
75365 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
75366 + grsec_enable_socket_all = 1;
75367 + grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
75368 +#endif
75369 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
75370 + grsec_enable_socket_client = 1;
75371 + grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
75372 +#endif
75373 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75374 + grsec_enable_socket_server = 1;
75375 + grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
75376 +#endif
75377 +#endif
75378 +#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
75379 + grsec_deny_new_usb = 1;
75380 +#endif
75381 +
75382 + return;
75383 +}
75384 diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
75385 new file mode 100644
75386 index 0000000..1773300
75387 --- /dev/null
75388 +++ b/grsecurity/grsec_ipc.c
75389 @@ -0,0 +1,48 @@
75390 +#include <linux/kernel.h>
75391 +#include <linux/mm.h>
75392 +#include <linux/sched.h>
75393 +#include <linux/file.h>
75394 +#include <linux/ipc.h>
75395 +#include <linux/ipc_namespace.h>
75396 +#include <linux/grsecurity.h>
75397 +#include <linux/grinternal.h>
75398 +
75399 +int
75400 +gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
75401 +{
75402 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
75403 + int write;
75404 + int orig_granted_mode;
75405 + kuid_t euid;
75406 + kgid_t egid;
75407 +
75408 + if (!grsec_enable_harden_ipc)
75409 + return 1;
75410 +
75411 + euid = current_euid();
75412 + egid = current_egid();
75413 +
75414 + write = requested_mode & 00002;
75415 + orig_granted_mode = ipcp->mode;
75416 +
75417 + if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
75418 + orig_granted_mode >>= 6;
75419 + else {
75420 + /* if likely wrong permissions, lock to user */
75421 + if (orig_granted_mode & 0007)
75422 + orig_granted_mode = 0;
75423 + /* otherwise do a egid-only check */
75424 + else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
75425 + orig_granted_mode >>= 3;
75426 + /* otherwise, no access */
75427 + else
75428 + orig_granted_mode = 0;
75429 + }
75430 + if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
75431 + !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
75432 + gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
75433 + return 0;
75434 + }
75435 +#endif
75436 + return 1;
75437 +}
75438 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
75439 new file mode 100644
75440 index 0000000..5e05e20
75441 --- /dev/null
75442 +++ b/grsecurity/grsec_link.c
75443 @@ -0,0 +1,58 @@
75444 +#include <linux/kernel.h>
75445 +#include <linux/sched.h>
75446 +#include <linux/fs.h>
75447 +#include <linux/file.h>
75448 +#include <linux/grinternal.h>
75449 +
75450 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
75451 +{
75452 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
75453 + const struct inode *link_inode = link->dentry->d_inode;
75454 +
75455 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
75456 + /* ignore root-owned links, e.g. /proc/self */
75457 + gr_is_global_nonroot(link_inode->i_uid) && target &&
75458 + !uid_eq(link_inode->i_uid, target->i_uid)) {
75459 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
75460 + return 1;
75461 + }
75462 +#endif
75463 + return 0;
75464 +}
75465 +
75466 +int
75467 +gr_handle_follow_link(const struct inode *parent,
75468 + const struct inode *inode,
75469 + const struct dentry *dentry, const struct vfsmount *mnt)
75470 +{
75471 +#ifdef CONFIG_GRKERNSEC_LINK
75472 + const struct cred *cred = current_cred();
75473 +
75474 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
75475 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
75476 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
75477 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
75478 + return -EACCES;
75479 + }
75480 +#endif
75481 + return 0;
75482 +}
75483 +
75484 +int
75485 +gr_handle_hardlink(const struct dentry *dentry,
75486 + const struct vfsmount *mnt,
75487 + struct inode *inode, const int mode, const struct filename *to)
75488 +{
75489 +#ifdef CONFIG_GRKERNSEC_LINK
75490 + const struct cred *cred = current_cred();
75491 +
75492 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
75493 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
75494 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
75495 + !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
75496 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
75497 + return -EPERM;
75498 + }
75499 +#endif
75500 + return 0;
75501 +}
75502 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
75503 new file mode 100644
75504 index 0000000..dbe0a6b
75505 --- /dev/null
75506 +++ b/grsecurity/grsec_log.c
75507 @@ -0,0 +1,341 @@
75508 +#include <linux/kernel.h>
75509 +#include <linux/sched.h>
75510 +#include <linux/file.h>
75511 +#include <linux/tty.h>
75512 +#include <linux/fs.h>
75513 +#include <linux/mm.h>
75514 +#include <linux/grinternal.h>
75515 +
75516 +#ifdef CONFIG_TREE_PREEMPT_RCU
75517 +#define DISABLE_PREEMPT() preempt_disable()
75518 +#define ENABLE_PREEMPT() preempt_enable()
75519 +#else
75520 +#define DISABLE_PREEMPT()
75521 +#define ENABLE_PREEMPT()
75522 +#endif
75523 +
75524 +#define BEGIN_LOCKS(x) \
75525 + DISABLE_PREEMPT(); \
75526 + rcu_read_lock(); \
75527 + read_lock(&tasklist_lock); \
75528 + read_lock(&grsec_exec_file_lock); \
75529 + if (x != GR_DO_AUDIT) \
75530 + spin_lock(&grsec_alert_lock); \
75531 + else \
75532 + spin_lock(&grsec_audit_lock)
75533 +
75534 +#define END_LOCKS(x) \
75535 + if (x != GR_DO_AUDIT) \
75536 + spin_unlock(&grsec_alert_lock); \
75537 + else \
75538 + spin_unlock(&grsec_audit_lock); \
75539 + read_unlock(&grsec_exec_file_lock); \
75540 + read_unlock(&tasklist_lock); \
75541 + rcu_read_unlock(); \
75542 + ENABLE_PREEMPT(); \
75543 + if (x == GR_DONT_AUDIT) \
75544 + gr_handle_alertkill(current)
75545 +
75546 +enum {
75547 + FLOODING,
75548 + NO_FLOODING
75549 +};
75550 +
75551 +extern char *gr_alert_log_fmt;
75552 +extern char *gr_audit_log_fmt;
75553 +extern char *gr_alert_log_buf;
75554 +extern char *gr_audit_log_buf;
75555 +
75556 +static int gr_log_start(int audit)
75557 +{
75558 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
75559 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
75560 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75561 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
75562 + unsigned long curr_secs = get_seconds();
75563 +
75564 + if (audit == GR_DO_AUDIT)
75565 + goto set_fmt;
75566 +
75567 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
75568 + grsec_alert_wtime = curr_secs;
75569 + grsec_alert_fyet = 0;
75570 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
75571 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
75572 + grsec_alert_fyet++;
75573 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
75574 + grsec_alert_wtime = curr_secs;
75575 + grsec_alert_fyet++;
75576 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
75577 + return FLOODING;
75578 + }
75579 + else return FLOODING;
75580 +
75581 +set_fmt:
75582 +#endif
75583 + memset(buf, 0, PAGE_SIZE);
75584 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
75585 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
75586 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
75587 + } else if (current->signal->curr_ip) {
75588 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
75589 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
75590 + } else if (gr_acl_is_enabled()) {
75591 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
75592 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
75593 + } else {
75594 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
75595 + strcpy(buf, fmt);
75596 + }
75597 +
75598 + return NO_FLOODING;
75599 +}
75600 +
75601 +static void gr_log_middle(int audit, const char *msg, va_list ap)
75602 + __attribute__ ((format (printf, 2, 0)));
75603 +
75604 +static void gr_log_middle(int audit, const char *msg, va_list ap)
75605 +{
75606 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75607 + unsigned int len = strlen(buf);
75608 +
75609 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
75610 +
75611 + return;
75612 +}
75613 +
75614 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
75615 + __attribute__ ((format (printf, 2, 3)));
75616 +
75617 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
75618 +{
75619 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75620 + unsigned int len = strlen(buf);
75621 + va_list ap;
75622 +
75623 + va_start(ap, msg);
75624 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
75625 + va_end(ap);
75626 +
75627 + return;
75628 +}
75629 +
75630 +static void gr_log_end(int audit, int append_default)
75631 +{
75632 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75633 + if (append_default) {
75634 + struct task_struct *task = current;
75635 + struct task_struct *parent = task->real_parent;
75636 + const struct cred *cred = __task_cred(task);
75637 + const struct cred *pcred = __task_cred(parent);
75638 + unsigned int len = strlen(buf);
75639 +
75640 + 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));
75641 + }
75642 +
75643 + printk("%s\n", buf);
75644 +
75645 + return;
75646 +}
75647 +
75648 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
75649 +{
75650 + int logtype;
75651 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
75652 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
75653 + void *voidptr = NULL;
75654 + int num1 = 0, num2 = 0;
75655 + unsigned long ulong1 = 0, ulong2 = 0;
75656 + struct dentry *dentry = NULL;
75657 + struct vfsmount *mnt = NULL;
75658 + struct file *file = NULL;
75659 + struct task_struct *task = NULL;
75660 + struct vm_area_struct *vma = NULL;
75661 + const struct cred *cred, *pcred;
75662 + va_list ap;
75663 +
75664 + BEGIN_LOCKS(audit);
75665 + logtype = gr_log_start(audit);
75666 + if (logtype == FLOODING) {
75667 + END_LOCKS(audit);
75668 + return;
75669 + }
75670 + va_start(ap, argtypes);
75671 + switch (argtypes) {
75672 + case GR_TTYSNIFF:
75673 + task = va_arg(ap, struct task_struct *);
75674 + 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));
75675 + break;
75676 + case GR_SYSCTL_HIDDEN:
75677 + str1 = va_arg(ap, char *);
75678 + gr_log_middle_varargs(audit, msg, result, str1);
75679 + break;
75680 + case GR_RBAC:
75681 + dentry = va_arg(ap, struct dentry *);
75682 + mnt = va_arg(ap, struct vfsmount *);
75683 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
75684 + break;
75685 + case GR_RBAC_STR:
75686 + dentry = va_arg(ap, struct dentry *);
75687 + mnt = va_arg(ap, struct vfsmount *);
75688 + str1 = va_arg(ap, char *);
75689 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
75690 + break;
75691 + case GR_STR_RBAC:
75692 + str1 = va_arg(ap, char *);
75693 + dentry = va_arg(ap, struct dentry *);
75694 + mnt = va_arg(ap, struct vfsmount *);
75695 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
75696 + break;
75697 + case GR_RBAC_MODE2:
75698 + dentry = va_arg(ap, struct dentry *);
75699 + mnt = va_arg(ap, struct vfsmount *);
75700 + str1 = va_arg(ap, char *);
75701 + str2 = va_arg(ap, char *);
75702 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
75703 + break;
75704 + case GR_RBAC_MODE3:
75705 + dentry = va_arg(ap, struct dentry *);
75706 + mnt = va_arg(ap, struct vfsmount *);
75707 + str1 = va_arg(ap, char *);
75708 + str2 = va_arg(ap, char *);
75709 + str3 = va_arg(ap, char *);
75710 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
75711 + break;
75712 + case GR_FILENAME:
75713 + dentry = va_arg(ap, struct dentry *);
75714 + mnt = va_arg(ap, struct vfsmount *);
75715 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
75716 + break;
75717 + case GR_STR_FILENAME:
75718 + str1 = va_arg(ap, char *);
75719 + dentry = va_arg(ap, struct dentry *);
75720 + mnt = va_arg(ap, struct vfsmount *);
75721 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
75722 + break;
75723 + case GR_FILENAME_STR:
75724 + dentry = va_arg(ap, struct dentry *);
75725 + mnt = va_arg(ap, struct vfsmount *);
75726 + str1 = va_arg(ap, char *);
75727 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
75728 + break;
75729 + case GR_FILENAME_TWO_INT:
75730 + dentry = va_arg(ap, struct dentry *);
75731 + mnt = va_arg(ap, struct vfsmount *);
75732 + num1 = va_arg(ap, int);
75733 + num2 = va_arg(ap, int);
75734 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
75735 + break;
75736 + case GR_FILENAME_TWO_INT_STR:
75737 + dentry = va_arg(ap, struct dentry *);
75738 + mnt = va_arg(ap, struct vfsmount *);
75739 + num1 = va_arg(ap, int);
75740 + num2 = va_arg(ap, int);
75741 + str1 = va_arg(ap, char *);
75742 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
75743 + break;
75744 + case GR_TEXTREL:
75745 + file = va_arg(ap, struct file *);
75746 + ulong1 = va_arg(ap, unsigned long);
75747 + ulong2 = va_arg(ap, unsigned long);
75748 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
75749 + break;
75750 + case GR_PTRACE:
75751 + task = va_arg(ap, struct task_struct *);
75752 + 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));
75753 + break;
75754 + case GR_RESOURCE:
75755 + task = va_arg(ap, struct task_struct *);
75756 + cred = __task_cred(task);
75757 + pcred = __task_cred(task->real_parent);
75758 + ulong1 = va_arg(ap, unsigned long);
75759 + str1 = va_arg(ap, char *);
75760 + ulong2 = va_arg(ap, unsigned long);
75761 + 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));
75762 + break;
75763 + case GR_CAP:
75764 + task = va_arg(ap, struct task_struct *);
75765 + cred = __task_cred(task);
75766 + pcred = __task_cred(task->real_parent);
75767 + str1 = va_arg(ap, char *);
75768 + 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));
75769 + break;
75770 + case GR_SIG:
75771 + str1 = va_arg(ap, char *);
75772 + voidptr = va_arg(ap, void *);
75773 + gr_log_middle_varargs(audit, msg, str1, voidptr);
75774 + break;
75775 + case GR_SIG2:
75776 + task = va_arg(ap, struct task_struct *);
75777 + cred = __task_cred(task);
75778 + pcred = __task_cred(task->real_parent);
75779 + num1 = va_arg(ap, int);
75780 + 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));
75781 + break;
75782 + case GR_CRASH1:
75783 + task = va_arg(ap, struct task_struct *);
75784 + cred = __task_cred(task);
75785 + pcred = __task_cred(task->real_parent);
75786 + ulong1 = va_arg(ap, unsigned long);
75787 + 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);
75788 + break;
75789 + case GR_CRASH2:
75790 + task = va_arg(ap, struct task_struct *);
75791 + cred = __task_cred(task);
75792 + pcred = __task_cred(task->real_parent);
75793 + ulong1 = va_arg(ap, unsigned long);
75794 + 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);
75795 + break;
75796 + case GR_RWXMAP:
75797 + file = va_arg(ap, struct file *);
75798 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
75799 + break;
75800 + case GR_RWXMAPVMA:
75801 + vma = va_arg(ap, struct vm_area_struct *);
75802 + if (vma->vm_file)
75803 + str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
75804 + else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
75805 + str1 = "<stack>";
75806 + else if (vma->vm_start <= current->mm->brk &&
75807 + vma->vm_end >= current->mm->start_brk)
75808 + str1 = "<heap>";
75809 + else
75810 + str1 = "<anonymous mapping>";
75811 + gr_log_middle_varargs(audit, msg, str1);
75812 + break;
75813 + case GR_PSACCT:
75814 + {
75815 + unsigned int wday, cday;
75816 + __u8 whr, chr;
75817 + __u8 wmin, cmin;
75818 + __u8 wsec, csec;
75819 + char cur_tty[64] = { 0 };
75820 + char parent_tty[64] = { 0 };
75821 +
75822 + task = va_arg(ap, struct task_struct *);
75823 + wday = va_arg(ap, unsigned int);
75824 + cday = va_arg(ap, unsigned int);
75825 + whr = va_arg(ap, int);
75826 + chr = va_arg(ap, int);
75827 + wmin = va_arg(ap, int);
75828 + cmin = va_arg(ap, int);
75829 + wsec = va_arg(ap, int);
75830 + csec = va_arg(ap, int);
75831 + ulong1 = va_arg(ap, unsigned long);
75832 + cred = __task_cred(task);
75833 + pcred = __task_cred(task->real_parent);
75834 +
75835 + 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));
75836 + }
75837 + break;
75838 + default:
75839 + gr_log_middle(audit, msg, ap);
75840 + }
75841 + va_end(ap);
75842 + // these don't need DEFAULTSECARGS printed on the end
75843 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
75844 + gr_log_end(audit, 0);
75845 + else
75846 + gr_log_end(audit, 1);
75847 + END_LOCKS(audit);
75848 +}
75849 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
75850 new file mode 100644
75851 index 0000000..0e39d8c
75852 --- /dev/null
75853 +++ b/grsecurity/grsec_mem.c
75854 @@ -0,0 +1,48 @@
75855 +#include <linux/kernel.h>
75856 +#include <linux/sched.h>
75857 +#include <linux/mm.h>
75858 +#include <linux/mman.h>
75859 +#include <linux/module.h>
75860 +#include <linux/grinternal.h>
75861 +
75862 +void gr_handle_msr_write(void)
75863 +{
75864 + gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
75865 + return;
75866 +}
75867 +EXPORT_SYMBOL_GPL(gr_handle_msr_write);
75868 +
75869 +void
75870 +gr_handle_ioperm(void)
75871 +{
75872 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
75873 + return;
75874 +}
75875 +
75876 +void
75877 +gr_handle_iopl(void)
75878 +{
75879 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
75880 + return;
75881 +}
75882 +
75883 +void
75884 +gr_handle_mem_readwrite(u64 from, u64 to)
75885 +{
75886 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
75887 + return;
75888 +}
75889 +
75890 +void
75891 +gr_handle_vm86(void)
75892 +{
75893 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
75894 + return;
75895 +}
75896 +
75897 +void
75898 +gr_log_badprocpid(const char *entry)
75899 +{
75900 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
75901 + return;
75902 +}
75903 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
75904 new file mode 100644
75905 index 0000000..cd9e124
75906 --- /dev/null
75907 +++ b/grsecurity/grsec_mount.c
75908 @@ -0,0 +1,65 @@
75909 +#include <linux/kernel.h>
75910 +#include <linux/sched.h>
75911 +#include <linux/mount.h>
75912 +#include <linux/major.h>
75913 +#include <linux/grsecurity.h>
75914 +#include <linux/grinternal.h>
75915 +
75916 +void
75917 +gr_log_remount(const char *devname, const int retval)
75918 +{
75919 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75920 + if (grsec_enable_mount && (retval >= 0))
75921 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
75922 +#endif
75923 + return;
75924 +}
75925 +
75926 +void
75927 +gr_log_unmount(const char *devname, const int retval)
75928 +{
75929 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75930 + if (grsec_enable_mount && (retval >= 0))
75931 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
75932 +#endif
75933 + return;
75934 +}
75935 +
75936 +void
75937 +gr_log_mount(const char *from, const char *to, const int retval)
75938 +{
75939 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75940 + if (grsec_enable_mount && (retval >= 0))
75941 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
75942 +#endif
75943 + return;
75944 +}
75945 +
75946 +int
75947 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
75948 +{
75949 +#ifdef CONFIG_GRKERNSEC_ROFS
75950 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
75951 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
75952 + return -EPERM;
75953 + } else
75954 + return 0;
75955 +#endif
75956 + return 0;
75957 +}
75958 +
75959 +int
75960 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
75961 +{
75962 +#ifdef CONFIG_GRKERNSEC_ROFS
75963 + struct inode *inode = dentry->d_inode;
75964 +
75965 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
75966 + inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
75967 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
75968 + return -EPERM;
75969 + } else
75970 + return 0;
75971 +#endif
75972 + return 0;
75973 +}
75974 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
75975 new file mode 100644
75976 index 0000000..6ee9d50
75977 --- /dev/null
75978 +++ b/grsecurity/grsec_pax.c
75979 @@ -0,0 +1,45 @@
75980 +#include <linux/kernel.h>
75981 +#include <linux/sched.h>
75982 +#include <linux/mm.h>
75983 +#include <linux/file.h>
75984 +#include <linux/grinternal.h>
75985 +#include <linux/grsecurity.h>
75986 +
75987 +void
75988 +gr_log_textrel(struct vm_area_struct * vma)
75989 +{
75990 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75991 + if (grsec_enable_log_rwxmaps)
75992 + gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
75993 +#endif
75994 + return;
75995 +}
75996 +
75997 +void gr_log_ptgnustack(struct file *file)
75998 +{
75999 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
76000 + if (grsec_enable_log_rwxmaps)
76001 + gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
76002 +#endif
76003 + return;
76004 +}
76005 +
76006 +void
76007 +gr_log_rwxmmap(struct file *file)
76008 +{
76009 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
76010 + if (grsec_enable_log_rwxmaps)
76011 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
76012 +#endif
76013 + return;
76014 +}
76015 +
76016 +void
76017 +gr_log_rwxmprotect(struct vm_area_struct *vma)
76018 +{
76019 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
76020 + if (grsec_enable_log_rwxmaps)
76021 + gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
76022 +#endif
76023 + return;
76024 +}
76025 diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
76026 new file mode 100644
76027 index 0000000..2005a3a
76028 --- /dev/null
76029 +++ b/grsecurity/grsec_proc.c
76030 @@ -0,0 +1,20 @@
76031 +#include <linux/kernel.h>
76032 +#include <linux/sched.h>
76033 +#include <linux/grsecurity.h>
76034 +#include <linux/grinternal.h>
76035 +
76036 +int gr_proc_is_restricted(void)
76037 +{
76038 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
76039 + const struct cred *cred = current_cred();
76040 +#endif
76041 +
76042 +#ifdef CONFIG_GRKERNSEC_PROC_USER
76043 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
76044 + return -EACCES;
76045 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
76046 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
76047 + return -EACCES;
76048 +#endif
76049 + return 0;
76050 +}
76051 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
76052 new file mode 100644
76053 index 0000000..f7f29aa
76054 --- /dev/null
76055 +++ b/grsecurity/grsec_ptrace.c
76056 @@ -0,0 +1,30 @@
76057 +#include <linux/kernel.h>
76058 +#include <linux/sched.h>
76059 +#include <linux/grinternal.h>
76060 +#include <linux/security.h>
76061 +
76062 +void
76063 +gr_audit_ptrace(struct task_struct *task)
76064 +{
76065 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
76066 + if (grsec_enable_audit_ptrace)
76067 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
76068 +#endif
76069 + return;
76070 +}
76071 +
76072 +int
76073 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
76074 +{
76075 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
76076 + const struct dentry *dentry = file->f_path.dentry;
76077 + const struct vfsmount *mnt = file->f_path.mnt;
76078 +
76079 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
76080 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
76081 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
76082 + return -EACCES;
76083 + }
76084 +#endif
76085 + return 0;
76086 +}
76087 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
76088 new file mode 100644
76089 index 0000000..3860c7e
76090 --- /dev/null
76091 +++ b/grsecurity/grsec_sig.c
76092 @@ -0,0 +1,236 @@
76093 +#include <linux/kernel.h>
76094 +#include <linux/sched.h>
76095 +#include <linux/fs.h>
76096 +#include <linux/delay.h>
76097 +#include <linux/grsecurity.h>
76098 +#include <linux/grinternal.h>
76099 +#include <linux/hardirq.h>
76100 +
76101 +char *signames[] = {
76102 + [SIGSEGV] = "Segmentation fault",
76103 + [SIGILL] = "Illegal instruction",
76104 + [SIGABRT] = "Abort",
76105 + [SIGBUS] = "Invalid alignment/Bus error"
76106 +};
76107 +
76108 +void
76109 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
76110 +{
76111 +#ifdef CONFIG_GRKERNSEC_SIGNAL
76112 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
76113 + (sig == SIGABRT) || (sig == SIGBUS))) {
76114 + if (task_pid_nr(t) == task_pid_nr(current)) {
76115 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
76116 + } else {
76117 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
76118 + }
76119 + }
76120 +#endif
76121 + return;
76122 +}
76123 +
76124 +int
76125 +gr_handle_signal(const struct task_struct *p, const int sig)
76126 +{
76127 +#ifdef CONFIG_GRKERNSEC
76128 + /* ignore the 0 signal for protected task checks */
76129 + if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
76130 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
76131 + return -EPERM;
76132 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
76133 + return -EPERM;
76134 + }
76135 +#endif
76136 + return 0;
76137 +}
76138 +
76139 +#ifdef CONFIG_GRKERNSEC
76140 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
76141 +
76142 +int gr_fake_force_sig(int sig, struct task_struct *t)
76143 +{
76144 + unsigned long int flags;
76145 + int ret, blocked, ignored;
76146 + struct k_sigaction *action;
76147 +
76148 + spin_lock_irqsave(&t->sighand->siglock, flags);
76149 + action = &t->sighand->action[sig-1];
76150 + ignored = action->sa.sa_handler == SIG_IGN;
76151 + blocked = sigismember(&t->blocked, sig);
76152 + if (blocked || ignored) {
76153 + action->sa.sa_handler = SIG_DFL;
76154 + if (blocked) {
76155 + sigdelset(&t->blocked, sig);
76156 + recalc_sigpending_and_wake(t);
76157 + }
76158 + }
76159 + if (action->sa.sa_handler == SIG_DFL)
76160 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
76161 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
76162 +
76163 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
76164 +
76165 + return ret;
76166 +}
76167 +#endif
76168 +
76169 +#define GR_USER_BAN_TIME (15 * 60)
76170 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
76171 +
76172 +void gr_handle_brute_attach(int dumpable)
76173 +{
76174 +#ifdef CONFIG_GRKERNSEC_BRUTE
76175 + struct task_struct *p = current;
76176 + kuid_t uid = GLOBAL_ROOT_UID;
76177 + int daemon = 0;
76178 +
76179 + if (!grsec_enable_brute)
76180 + return;
76181 +
76182 + rcu_read_lock();
76183 + read_lock(&tasklist_lock);
76184 + read_lock(&grsec_exec_file_lock);
76185 + if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
76186 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
76187 + p->real_parent->brute = 1;
76188 + daemon = 1;
76189 + } else {
76190 + const struct cred *cred = __task_cred(p), *cred2;
76191 + struct task_struct *tsk, *tsk2;
76192 +
76193 + if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
76194 + struct user_struct *user;
76195 +
76196 + uid = cred->uid;
76197 +
76198 + /* this is put upon execution past expiration */
76199 + user = find_user(uid);
76200 + if (user == NULL)
76201 + goto unlock;
76202 + user->suid_banned = 1;
76203 + user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
76204 + if (user->suid_ban_expires == ~0UL)
76205 + user->suid_ban_expires--;
76206 +
76207 + /* only kill other threads of the same binary, from the same user */
76208 + do_each_thread(tsk2, tsk) {
76209 + cred2 = __task_cred(tsk);
76210 + if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
76211 + gr_fake_force_sig(SIGKILL, tsk);
76212 + } while_each_thread(tsk2, tsk);
76213 + }
76214 + }
76215 +unlock:
76216 + read_unlock(&grsec_exec_file_lock);
76217 + read_unlock(&tasklist_lock);
76218 + rcu_read_unlock();
76219 +
76220 + if (gr_is_global_nonroot(uid))
76221 + 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);
76222 + else if (daemon)
76223 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
76224 +
76225 +#endif
76226 + return;
76227 +}
76228 +
76229 +void gr_handle_brute_check(void)
76230 +{
76231 +#ifdef CONFIG_GRKERNSEC_BRUTE
76232 + struct task_struct *p = current;
76233 +
76234 + if (unlikely(p->brute)) {
76235 + if (!grsec_enable_brute)
76236 + p->brute = 0;
76237 + else if (time_before(get_seconds(), p->brute_expires))
76238 + msleep(30 * 1000);
76239 + }
76240 +#endif
76241 + return;
76242 +}
76243 +
76244 +void gr_handle_kernel_exploit(void)
76245 +{
76246 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
76247 + const struct cred *cred;
76248 + struct task_struct *tsk, *tsk2;
76249 + struct user_struct *user;
76250 + kuid_t uid;
76251 +
76252 + if (in_irq() || in_serving_softirq() || in_nmi())
76253 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
76254 +
76255 + uid = current_uid();
76256 +
76257 + if (gr_is_global_root(uid))
76258 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
76259 + else {
76260 + /* kill all the processes of this user, hold a reference
76261 + to their creds struct, and prevent them from creating
76262 + another process until system reset
76263 + */
76264 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
76265 + GR_GLOBAL_UID(uid));
76266 + /* we intentionally leak this ref */
76267 + user = get_uid(current->cred->user);
76268 + if (user)
76269 + user->kernel_banned = 1;
76270 +
76271 + /* kill all processes of this user */
76272 + read_lock(&tasklist_lock);
76273 + do_each_thread(tsk2, tsk) {
76274 + cred = __task_cred(tsk);
76275 + if (uid_eq(cred->uid, uid))
76276 + gr_fake_force_sig(SIGKILL, tsk);
76277 + } while_each_thread(tsk2, tsk);
76278 + read_unlock(&tasklist_lock);
76279 + }
76280 +#endif
76281 +}
76282 +
76283 +#ifdef CONFIG_GRKERNSEC_BRUTE
76284 +static bool suid_ban_expired(struct user_struct *user)
76285 +{
76286 + if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
76287 + user->suid_banned = 0;
76288 + user->suid_ban_expires = 0;
76289 + free_uid(user);
76290 + return true;
76291 + }
76292 +
76293 + return false;
76294 +}
76295 +#endif
76296 +
76297 +int gr_process_kernel_exec_ban(void)
76298 +{
76299 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
76300 + if (unlikely(current->cred->user->kernel_banned))
76301 + return -EPERM;
76302 +#endif
76303 + return 0;
76304 +}
76305 +
76306 +int gr_process_kernel_setuid_ban(struct user_struct *user)
76307 +{
76308 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
76309 + if (unlikely(user->kernel_banned))
76310 + gr_fake_force_sig(SIGKILL, current);
76311 +#endif
76312 + return 0;
76313 +}
76314 +
76315 +int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
76316 +{
76317 +#ifdef CONFIG_GRKERNSEC_BRUTE
76318 + struct user_struct *user = current->cred->user;
76319 + if (unlikely(user->suid_banned)) {
76320 + if (suid_ban_expired(user))
76321 + return 0;
76322 + /* disallow execution of suid binaries only */
76323 + else if (!uid_eq(bprm->cred->euid, current->cred->uid))
76324 + return -EPERM;
76325 + }
76326 +#endif
76327 + return 0;
76328 +}
76329 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
76330 new file mode 100644
76331 index 0000000..c0aef3a
76332 --- /dev/null
76333 +++ b/grsecurity/grsec_sock.c
76334 @@ -0,0 +1,244 @@
76335 +#include <linux/kernel.h>
76336 +#include <linux/module.h>
76337 +#include <linux/sched.h>
76338 +#include <linux/file.h>
76339 +#include <linux/net.h>
76340 +#include <linux/in.h>
76341 +#include <linux/ip.h>
76342 +#include <net/sock.h>
76343 +#include <net/inet_sock.h>
76344 +#include <linux/grsecurity.h>
76345 +#include <linux/grinternal.h>
76346 +#include <linux/gracl.h>
76347 +
76348 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
76349 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
76350 +
76351 +EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
76352 +EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
76353 +
76354 +#ifdef CONFIG_UNIX_MODULE
76355 +EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
76356 +EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
76357 +EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
76358 +EXPORT_SYMBOL_GPL(gr_handle_create);
76359 +#endif
76360 +
76361 +#ifdef CONFIG_GRKERNSEC
76362 +#define gr_conn_table_size 32749
76363 +struct conn_table_entry {
76364 + struct conn_table_entry *next;
76365 + struct signal_struct *sig;
76366 +};
76367 +
76368 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
76369 +DEFINE_SPINLOCK(gr_conn_table_lock);
76370 +
76371 +extern const char * gr_socktype_to_name(unsigned char type);
76372 +extern const char * gr_proto_to_name(unsigned char proto);
76373 +extern const char * gr_sockfamily_to_name(unsigned char family);
76374 +
76375 +static __inline__ int
76376 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
76377 +{
76378 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
76379 +}
76380 +
76381 +static __inline__ int
76382 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
76383 + __u16 sport, __u16 dport)
76384 +{
76385 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
76386 + sig->gr_sport == sport && sig->gr_dport == dport))
76387 + return 1;
76388 + else
76389 + return 0;
76390 +}
76391 +
76392 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
76393 +{
76394 + struct conn_table_entry **match;
76395 + unsigned int index;
76396 +
76397 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
76398 + sig->gr_sport, sig->gr_dport,
76399 + gr_conn_table_size);
76400 +
76401 + newent->sig = sig;
76402 +
76403 + match = &gr_conn_table[index];
76404 + newent->next = *match;
76405 + *match = newent;
76406 +
76407 + return;
76408 +}
76409 +
76410 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
76411 +{
76412 + struct conn_table_entry *match, *last = NULL;
76413 + unsigned int index;
76414 +
76415 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
76416 + sig->gr_sport, sig->gr_dport,
76417 + gr_conn_table_size);
76418 +
76419 + match = gr_conn_table[index];
76420 + while (match && !conn_match(match->sig,
76421 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
76422 + sig->gr_dport)) {
76423 + last = match;
76424 + match = match->next;
76425 + }
76426 +
76427 + if (match) {
76428 + if (last)
76429 + last->next = match->next;
76430 + else
76431 + gr_conn_table[index] = NULL;
76432 + kfree(match);
76433 + }
76434 +
76435 + return;
76436 +}
76437 +
76438 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
76439 + __u16 sport, __u16 dport)
76440 +{
76441 + struct conn_table_entry *match;
76442 + unsigned int index;
76443 +
76444 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
76445 +
76446 + match = gr_conn_table[index];
76447 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
76448 + match = match->next;
76449 +
76450 + if (match)
76451 + return match->sig;
76452 + else
76453 + return NULL;
76454 +}
76455 +
76456 +#endif
76457 +
76458 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
76459 +{
76460 +#ifdef CONFIG_GRKERNSEC
76461 + struct signal_struct *sig = task->signal;
76462 + struct conn_table_entry *newent;
76463 +
76464 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
76465 + if (newent == NULL)
76466 + return;
76467 + /* no bh lock needed since we are called with bh disabled */
76468 + spin_lock(&gr_conn_table_lock);
76469 + gr_del_task_from_ip_table_nolock(sig);
76470 + sig->gr_saddr = inet->inet_rcv_saddr;
76471 + sig->gr_daddr = inet->inet_daddr;
76472 + sig->gr_sport = inet->inet_sport;
76473 + sig->gr_dport = inet->inet_dport;
76474 + gr_add_to_task_ip_table_nolock(sig, newent);
76475 + spin_unlock(&gr_conn_table_lock);
76476 +#endif
76477 + return;
76478 +}
76479 +
76480 +void gr_del_task_from_ip_table(struct task_struct *task)
76481 +{
76482 +#ifdef CONFIG_GRKERNSEC
76483 + spin_lock_bh(&gr_conn_table_lock);
76484 + gr_del_task_from_ip_table_nolock(task->signal);
76485 + spin_unlock_bh(&gr_conn_table_lock);
76486 +#endif
76487 + return;
76488 +}
76489 +
76490 +void
76491 +gr_attach_curr_ip(const struct sock *sk)
76492 +{
76493 +#ifdef CONFIG_GRKERNSEC
76494 + struct signal_struct *p, *set;
76495 + const struct inet_sock *inet = inet_sk(sk);
76496 +
76497 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
76498 + return;
76499 +
76500 + set = current->signal;
76501 +
76502 + spin_lock_bh(&gr_conn_table_lock);
76503 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
76504 + inet->inet_dport, inet->inet_sport);
76505 + if (unlikely(p != NULL)) {
76506 + set->curr_ip = p->curr_ip;
76507 + set->used_accept = 1;
76508 + gr_del_task_from_ip_table_nolock(p);
76509 + spin_unlock_bh(&gr_conn_table_lock);
76510 + return;
76511 + }
76512 + spin_unlock_bh(&gr_conn_table_lock);
76513 +
76514 + set->curr_ip = inet->inet_daddr;
76515 + set->used_accept = 1;
76516 +#endif
76517 + return;
76518 +}
76519 +
76520 +int
76521 +gr_handle_sock_all(const int family, const int type, const int protocol)
76522 +{
76523 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
76524 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
76525 + (family != AF_UNIX)) {
76526 + if (family == AF_INET)
76527 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
76528 + else
76529 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
76530 + return -EACCES;
76531 + }
76532 +#endif
76533 + return 0;
76534 +}
76535 +
76536 +int
76537 +gr_handle_sock_server(const struct sockaddr *sck)
76538 +{
76539 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76540 + if (grsec_enable_socket_server &&
76541 + in_group_p(grsec_socket_server_gid) &&
76542 + sck && (sck->sa_family != AF_UNIX) &&
76543 + (sck->sa_family != AF_LOCAL)) {
76544 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
76545 + return -EACCES;
76546 + }
76547 +#endif
76548 + return 0;
76549 +}
76550 +
76551 +int
76552 +gr_handle_sock_server_other(const struct sock *sck)
76553 +{
76554 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76555 + if (grsec_enable_socket_server &&
76556 + in_group_p(grsec_socket_server_gid) &&
76557 + sck && (sck->sk_family != AF_UNIX) &&
76558 + (sck->sk_family != AF_LOCAL)) {
76559 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
76560 + return -EACCES;
76561 + }
76562 +#endif
76563 + return 0;
76564 +}
76565 +
76566 +int
76567 +gr_handle_sock_client(const struct sockaddr *sck)
76568 +{
76569 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
76570 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
76571 + sck && (sck->sa_family != AF_UNIX) &&
76572 + (sck->sa_family != AF_LOCAL)) {
76573 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
76574 + return -EACCES;
76575 + }
76576 +#endif
76577 + return 0;
76578 +}
76579 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
76580 new file mode 100644
76581 index 0000000..8159888
76582 --- /dev/null
76583 +++ b/grsecurity/grsec_sysctl.c
76584 @@ -0,0 +1,479 @@
76585 +#include <linux/kernel.h>
76586 +#include <linux/sched.h>
76587 +#include <linux/sysctl.h>
76588 +#include <linux/grsecurity.h>
76589 +#include <linux/grinternal.h>
76590 +
76591 +int
76592 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
76593 +{
76594 +#ifdef CONFIG_GRKERNSEC_SYSCTL
76595 + if (dirname == NULL || name == NULL)
76596 + return 0;
76597 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
76598 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
76599 + return -EACCES;
76600 + }
76601 +#endif
76602 + return 0;
76603 +}
76604 +
76605 +#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
76606 +static int __maybe_unused __read_only one = 1;
76607 +#endif
76608 +
76609 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
76610 + defined(CONFIG_GRKERNSEC_DENYUSB)
76611 +struct ctl_table grsecurity_table[] = {
76612 +#ifdef CONFIG_GRKERNSEC_SYSCTL
76613 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
76614 +#ifdef CONFIG_GRKERNSEC_IO
76615 + {
76616 + .procname = "disable_priv_io",
76617 + .data = &grsec_disable_privio,
76618 + .maxlen = sizeof(int),
76619 + .mode = 0600,
76620 + .proc_handler = &proc_dointvec,
76621 + },
76622 +#endif
76623 +#endif
76624 +#ifdef CONFIG_GRKERNSEC_LINK
76625 + {
76626 + .procname = "linking_restrictions",
76627 + .data = &grsec_enable_link,
76628 + .maxlen = sizeof(int),
76629 + .mode = 0600,
76630 + .proc_handler = &proc_dointvec,
76631 + },
76632 +#endif
76633 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
76634 + {
76635 + .procname = "enforce_symlinksifowner",
76636 + .data = &grsec_enable_symlinkown,
76637 + .maxlen = sizeof(int),
76638 + .mode = 0600,
76639 + .proc_handler = &proc_dointvec,
76640 + },
76641 + {
76642 + .procname = "symlinkown_gid",
76643 + .data = &grsec_symlinkown_gid,
76644 + .maxlen = sizeof(int),
76645 + .mode = 0600,
76646 + .proc_handler = &proc_dointvec,
76647 + },
76648 +#endif
76649 +#ifdef CONFIG_GRKERNSEC_BRUTE
76650 + {
76651 + .procname = "deter_bruteforce",
76652 + .data = &grsec_enable_brute,
76653 + .maxlen = sizeof(int),
76654 + .mode = 0600,
76655 + .proc_handler = &proc_dointvec,
76656 + },
76657 +#endif
76658 +#ifdef CONFIG_GRKERNSEC_FIFO
76659 + {
76660 + .procname = "fifo_restrictions",
76661 + .data = &grsec_enable_fifo,
76662 + .maxlen = sizeof(int),
76663 + .mode = 0600,
76664 + .proc_handler = &proc_dointvec,
76665 + },
76666 +#endif
76667 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
76668 + {
76669 + .procname = "ptrace_readexec",
76670 + .data = &grsec_enable_ptrace_readexec,
76671 + .maxlen = sizeof(int),
76672 + .mode = 0600,
76673 + .proc_handler = &proc_dointvec,
76674 + },
76675 +#endif
76676 +#ifdef CONFIG_GRKERNSEC_SETXID
76677 + {
76678 + .procname = "consistent_setxid",
76679 + .data = &grsec_enable_setxid,
76680 + .maxlen = sizeof(int),
76681 + .mode = 0600,
76682 + .proc_handler = &proc_dointvec,
76683 + },
76684 +#endif
76685 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76686 + {
76687 + .procname = "ip_blackhole",
76688 + .data = &grsec_enable_blackhole,
76689 + .maxlen = sizeof(int),
76690 + .mode = 0600,
76691 + .proc_handler = &proc_dointvec,
76692 + },
76693 + {
76694 + .procname = "lastack_retries",
76695 + .data = &grsec_lastack_retries,
76696 + .maxlen = sizeof(int),
76697 + .mode = 0600,
76698 + .proc_handler = &proc_dointvec,
76699 + },
76700 +#endif
76701 +#ifdef CONFIG_GRKERNSEC_EXECLOG
76702 + {
76703 + .procname = "exec_logging",
76704 + .data = &grsec_enable_execlog,
76705 + .maxlen = sizeof(int),
76706 + .mode = 0600,
76707 + .proc_handler = &proc_dointvec,
76708 + },
76709 +#endif
76710 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
76711 + {
76712 + .procname = "rwxmap_logging",
76713 + .data = &grsec_enable_log_rwxmaps,
76714 + .maxlen = sizeof(int),
76715 + .mode = 0600,
76716 + .proc_handler = &proc_dointvec,
76717 + },
76718 +#endif
76719 +#ifdef CONFIG_GRKERNSEC_SIGNAL
76720 + {
76721 + .procname = "signal_logging",
76722 + .data = &grsec_enable_signal,
76723 + .maxlen = sizeof(int),
76724 + .mode = 0600,
76725 + .proc_handler = &proc_dointvec,
76726 + },
76727 +#endif
76728 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
76729 + {
76730 + .procname = "forkfail_logging",
76731 + .data = &grsec_enable_forkfail,
76732 + .maxlen = sizeof(int),
76733 + .mode = 0600,
76734 + .proc_handler = &proc_dointvec,
76735 + },
76736 +#endif
76737 +#ifdef CONFIG_GRKERNSEC_TIME
76738 + {
76739 + .procname = "timechange_logging",
76740 + .data = &grsec_enable_time,
76741 + .maxlen = sizeof(int),
76742 + .mode = 0600,
76743 + .proc_handler = &proc_dointvec,
76744 + },
76745 +#endif
76746 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
76747 + {
76748 + .procname = "chroot_deny_shmat",
76749 + .data = &grsec_enable_chroot_shmat,
76750 + .maxlen = sizeof(int),
76751 + .mode = 0600,
76752 + .proc_handler = &proc_dointvec,
76753 + },
76754 +#endif
76755 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
76756 + {
76757 + .procname = "chroot_deny_unix",
76758 + .data = &grsec_enable_chroot_unix,
76759 + .maxlen = sizeof(int),
76760 + .mode = 0600,
76761 + .proc_handler = &proc_dointvec,
76762 + },
76763 +#endif
76764 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
76765 + {
76766 + .procname = "chroot_deny_mount",
76767 + .data = &grsec_enable_chroot_mount,
76768 + .maxlen = sizeof(int),
76769 + .mode = 0600,
76770 + .proc_handler = &proc_dointvec,
76771 + },
76772 +#endif
76773 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76774 + {
76775 + .procname = "chroot_deny_fchdir",
76776 + .data = &grsec_enable_chroot_fchdir,
76777 + .maxlen = sizeof(int),
76778 + .mode = 0600,
76779 + .proc_handler = &proc_dointvec,
76780 + },
76781 +#endif
76782 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
76783 + {
76784 + .procname = "chroot_deny_chroot",
76785 + .data = &grsec_enable_chroot_double,
76786 + .maxlen = sizeof(int),
76787 + .mode = 0600,
76788 + .proc_handler = &proc_dointvec,
76789 + },
76790 +#endif
76791 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
76792 + {
76793 + .procname = "chroot_deny_pivot",
76794 + .data = &grsec_enable_chroot_pivot,
76795 + .maxlen = sizeof(int),
76796 + .mode = 0600,
76797 + .proc_handler = &proc_dointvec,
76798 + },
76799 +#endif
76800 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
76801 + {
76802 + .procname = "chroot_enforce_chdir",
76803 + .data = &grsec_enable_chroot_chdir,
76804 + .maxlen = sizeof(int),
76805 + .mode = 0600,
76806 + .proc_handler = &proc_dointvec,
76807 + },
76808 +#endif
76809 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
76810 + {
76811 + .procname = "chroot_deny_chmod",
76812 + .data = &grsec_enable_chroot_chmod,
76813 + .maxlen = sizeof(int),
76814 + .mode = 0600,
76815 + .proc_handler = &proc_dointvec,
76816 + },
76817 +#endif
76818 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
76819 + {
76820 + .procname = "chroot_deny_mknod",
76821 + .data = &grsec_enable_chroot_mknod,
76822 + .maxlen = sizeof(int),
76823 + .mode = 0600,
76824 + .proc_handler = &proc_dointvec,
76825 + },
76826 +#endif
76827 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76828 + {
76829 + .procname = "chroot_restrict_nice",
76830 + .data = &grsec_enable_chroot_nice,
76831 + .maxlen = sizeof(int),
76832 + .mode = 0600,
76833 + .proc_handler = &proc_dointvec,
76834 + },
76835 +#endif
76836 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
76837 + {
76838 + .procname = "chroot_execlog",
76839 + .data = &grsec_enable_chroot_execlog,
76840 + .maxlen = sizeof(int),
76841 + .mode = 0600,
76842 + .proc_handler = &proc_dointvec,
76843 + },
76844 +#endif
76845 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76846 + {
76847 + .procname = "chroot_caps",
76848 + .data = &grsec_enable_chroot_caps,
76849 + .maxlen = sizeof(int),
76850 + .mode = 0600,
76851 + .proc_handler = &proc_dointvec,
76852 + },
76853 +#endif
76854 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
76855 + {
76856 + .procname = "chroot_deny_sysctl",
76857 + .data = &grsec_enable_chroot_sysctl,
76858 + .maxlen = sizeof(int),
76859 + .mode = 0600,
76860 + .proc_handler = &proc_dointvec,
76861 + },
76862 +#endif
76863 +#ifdef CONFIG_GRKERNSEC_TPE
76864 + {
76865 + .procname = "tpe",
76866 + .data = &grsec_enable_tpe,
76867 + .maxlen = sizeof(int),
76868 + .mode = 0600,
76869 + .proc_handler = &proc_dointvec,
76870 + },
76871 + {
76872 + .procname = "tpe_gid",
76873 + .data = &grsec_tpe_gid,
76874 + .maxlen = sizeof(int),
76875 + .mode = 0600,
76876 + .proc_handler = &proc_dointvec,
76877 + },
76878 +#endif
76879 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
76880 + {
76881 + .procname = "tpe_invert",
76882 + .data = &grsec_enable_tpe_invert,
76883 + .maxlen = sizeof(int),
76884 + .mode = 0600,
76885 + .proc_handler = &proc_dointvec,
76886 + },
76887 +#endif
76888 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
76889 + {
76890 + .procname = "tpe_restrict_all",
76891 + .data = &grsec_enable_tpe_all,
76892 + .maxlen = sizeof(int),
76893 + .mode = 0600,
76894 + .proc_handler = &proc_dointvec,
76895 + },
76896 +#endif
76897 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
76898 + {
76899 + .procname = "socket_all",
76900 + .data = &grsec_enable_socket_all,
76901 + .maxlen = sizeof(int),
76902 + .mode = 0600,
76903 + .proc_handler = &proc_dointvec,
76904 + },
76905 + {
76906 + .procname = "socket_all_gid",
76907 + .data = &grsec_socket_all_gid,
76908 + .maxlen = sizeof(int),
76909 + .mode = 0600,
76910 + .proc_handler = &proc_dointvec,
76911 + },
76912 +#endif
76913 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
76914 + {
76915 + .procname = "socket_client",
76916 + .data = &grsec_enable_socket_client,
76917 + .maxlen = sizeof(int),
76918 + .mode = 0600,
76919 + .proc_handler = &proc_dointvec,
76920 + },
76921 + {
76922 + .procname = "socket_client_gid",
76923 + .data = &grsec_socket_client_gid,
76924 + .maxlen = sizeof(int),
76925 + .mode = 0600,
76926 + .proc_handler = &proc_dointvec,
76927 + },
76928 +#endif
76929 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76930 + {
76931 + .procname = "socket_server",
76932 + .data = &grsec_enable_socket_server,
76933 + .maxlen = sizeof(int),
76934 + .mode = 0600,
76935 + .proc_handler = &proc_dointvec,
76936 + },
76937 + {
76938 + .procname = "socket_server_gid",
76939 + .data = &grsec_socket_server_gid,
76940 + .maxlen = sizeof(int),
76941 + .mode = 0600,
76942 + .proc_handler = &proc_dointvec,
76943 + },
76944 +#endif
76945 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
76946 + {
76947 + .procname = "audit_group",
76948 + .data = &grsec_enable_group,
76949 + .maxlen = sizeof(int),
76950 + .mode = 0600,
76951 + .proc_handler = &proc_dointvec,
76952 + },
76953 + {
76954 + .procname = "audit_gid",
76955 + .data = &grsec_audit_gid,
76956 + .maxlen = sizeof(int),
76957 + .mode = 0600,
76958 + .proc_handler = &proc_dointvec,
76959 + },
76960 +#endif
76961 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
76962 + {
76963 + .procname = "audit_chdir",
76964 + .data = &grsec_enable_chdir,
76965 + .maxlen = sizeof(int),
76966 + .mode = 0600,
76967 + .proc_handler = &proc_dointvec,
76968 + },
76969 +#endif
76970 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
76971 + {
76972 + .procname = "audit_mount",
76973 + .data = &grsec_enable_mount,
76974 + .maxlen = sizeof(int),
76975 + .mode = 0600,
76976 + .proc_handler = &proc_dointvec,
76977 + },
76978 +#endif
76979 +#ifdef CONFIG_GRKERNSEC_DMESG
76980 + {
76981 + .procname = "dmesg",
76982 + .data = &grsec_enable_dmesg,
76983 + .maxlen = sizeof(int),
76984 + .mode = 0600,
76985 + .proc_handler = &proc_dointvec,
76986 + },
76987 +#endif
76988 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76989 + {
76990 + .procname = "chroot_findtask",
76991 + .data = &grsec_enable_chroot_findtask,
76992 + .maxlen = sizeof(int),
76993 + .mode = 0600,
76994 + .proc_handler = &proc_dointvec,
76995 + },
76996 +#endif
76997 +#ifdef CONFIG_GRKERNSEC_RESLOG
76998 + {
76999 + .procname = "resource_logging",
77000 + .data = &grsec_resource_logging,
77001 + .maxlen = sizeof(int),
77002 + .mode = 0600,
77003 + .proc_handler = &proc_dointvec,
77004 + },
77005 +#endif
77006 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
77007 + {
77008 + .procname = "audit_ptrace",
77009 + .data = &grsec_enable_audit_ptrace,
77010 + .maxlen = sizeof(int),
77011 + .mode = 0600,
77012 + .proc_handler = &proc_dointvec,
77013 + },
77014 +#endif
77015 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
77016 + {
77017 + .procname = "harden_ptrace",
77018 + .data = &grsec_enable_harden_ptrace,
77019 + .maxlen = sizeof(int),
77020 + .mode = 0600,
77021 + .proc_handler = &proc_dointvec,
77022 + },
77023 +#endif
77024 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
77025 + {
77026 + .procname = "harden_ipc",
77027 + .data = &grsec_enable_harden_ipc,
77028 + .maxlen = sizeof(int),
77029 + .mode = 0600,
77030 + .proc_handler = &proc_dointvec,
77031 + },
77032 +#endif
77033 + {
77034 + .procname = "grsec_lock",
77035 + .data = &grsec_lock,
77036 + .maxlen = sizeof(int),
77037 + .mode = 0600,
77038 + .proc_handler = &proc_dointvec,
77039 + },
77040 +#endif
77041 +#ifdef CONFIG_GRKERNSEC_ROFS
77042 + {
77043 + .procname = "romount_protect",
77044 + .data = &grsec_enable_rofs,
77045 + .maxlen = sizeof(int),
77046 + .mode = 0600,
77047 + .proc_handler = &proc_dointvec_minmax,
77048 + .extra1 = &one,
77049 + .extra2 = &one,
77050 + },
77051 +#endif
77052 +#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
77053 + {
77054 + .procname = "deny_new_usb",
77055 + .data = &grsec_deny_new_usb,
77056 + .maxlen = sizeof(int),
77057 + .mode = 0600,
77058 + .proc_handler = &proc_dointvec,
77059 + },
77060 +#endif
77061 + { }
77062 +};
77063 +#endif
77064 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
77065 new file mode 100644
77066 index 0000000..61b514e
77067 --- /dev/null
77068 +++ b/grsecurity/grsec_time.c
77069 @@ -0,0 +1,16 @@
77070 +#include <linux/kernel.h>
77071 +#include <linux/sched.h>
77072 +#include <linux/grinternal.h>
77073 +#include <linux/module.h>
77074 +
77075 +void
77076 +gr_log_timechange(void)
77077 +{
77078 +#ifdef CONFIG_GRKERNSEC_TIME
77079 + if (grsec_enable_time)
77080 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
77081 +#endif
77082 + return;
77083 +}
77084 +
77085 +EXPORT_SYMBOL_GPL(gr_log_timechange);
77086 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
77087 new file mode 100644
77088 index 0000000..d1953de
77089 --- /dev/null
77090 +++ b/grsecurity/grsec_tpe.c
77091 @@ -0,0 +1,78 @@
77092 +#include <linux/kernel.h>
77093 +#include <linux/sched.h>
77094 +#include <linux/file.h>
77095 +#include <linux/fs.h>
77096 +#include <linux/grinternal.h>
77097 +
77098 +extern int gr_acl_tpe_check(void);
77099 +
77100 +int
77101 +gr_tpe_allow(const struct file *file)
77102 +{
77103 +#ifdef CONFIG_GRKERNSEC
77104 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
77105 + struct inode *file_inode = file->f_path.dentry->d_inode;
77106 + const struct cred *cred = current_cred();
77107 + char *msg = NULL;
77108 + char *msg2 = NULL;
77109 +
77110 + // never restrict root
77111 + if (gr_is_global_root(cred->uid))
77112 + return 1;
77113 +
77114 + if (grsec_enable_tpe) {
77115 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
77116 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
77117 + msg = "not being in trusted group";
77118 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
77119 + msg = "being in untrusted group";
77120 +#else
77121 + if (in_group_p(grsec_tpe_gid))
77122 + msg = "being in untrusted group";
77123 +#endif
77124 + }
77125 + if (!msg && gr_acl_tpe_check())
77126 + msg = "being in untrusted role";
77127 +
77128 + // not in any affected group/role
77129 + if (!msg)
77130 + goto next_check;
77131 +
77132 + if (gr_is_global_nonroot(inode->i_uid))
77133 + msg2 = "file in non-root-owned directory";
77134 + else if (inode->i_mode & S_IWOTH)
77135 + msg2 = "file in world-writable directory";
77136 + else if (inode->i_mode & S_IWGRP)
77137 + msg2 = "file in group-writable directory";
77138 + else if (file_inode->i_mode & S_IWOTH)
77139 + msg2 = "file is world-writable";
77140 +
77141 + if (msg && msg2) {
77142 + char fullmsg[70] = {0};
77143 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
77144 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
77145 + return 0;
77146 + }
77147 + msg = NULL;
77148 +next_check:
77149 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
77150 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
77151 + return 1;
77152 +
77153 + if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
77154 + msg = "directory not owned by user";
77155 + else if (inode->i_mode & S_IWOTH)
77156 + msg = "file in world-writable directory";
77157 + else if (inode->i_mode & S_IWGRP)
77158 + msg = "file in group-writable directory";
77159 + else if (file_inode->i_mode & S_IWOTH)
77160 + msg = "file is world-writable";
77161 +
77162 + if (msg) {
77163 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
77164 + return 0;
77165 + }
77166 +#endif
77167 +#endif
77168 + return 1;
77169 +}
77170 diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
77171 new file mode 100644
77172 index 0000000..ae02d8e
77173 --- /dev/null
77174 +++ b/grsecurity/grsec_usb.c
77175 @@ -0,0 +1,15 @@
77176 +#include <linux/kernel.h>
77177 +#include <linux/grinternal.h>
77178 +#include <linux/module.h>
77179 +
77180 +int gr_handle_new_usb(void)
77181 +{
77182 +#ifdef CONFIG_GRKERNSEC_DENYUSB
77183 + if (grsec_deny_new_usb) {
77184 + printk(KERN_ALERT "grsec: denied insert of new USB device\n");
77185 + return 1;
77186 + }
77187 +#endif
77188 + return 0;
77189 +}
77190 +EXPORT_SYMBOL_GPL(gr_handle_new_usb);
77191 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
77192 new file mode 100644
77193 index 0000000..158b330
77194 --- /dev/null
77195 +++ b/grsecurity/grsum.c
77196 @@ -0,0 +1,64 @@
77197 +#include <linux/err.h>
77198 +#include <linux/kernel.h>
77199 +#include <linux/sched.h>
77200 +#include <linux/mm.h>
77201 +#include <linux/scatterlist.h>
77202 +#include <linux/crypto.h>
77203 +#include <linux/gracl.h>
77204 +
77205 +
77206 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
77207 +#error "crypto and sha256 must be built into the kernel"
77208 +#endif
77209 +
77210 +int
77211 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
77212 +{
77213 + struct crypto_hash *tfm;
77214 + struct hash_desc desc;
77215 + struct scatterlist sg[2];
77216 + unsigned char temp_sum[GR_SHA_LEN] __attribute__((aligned(__alignof__(unsigned long))));
77217 + unsigned long *tmpsumptr = (unsigned long *)temp_sum;
77218 + unsigned long *sumptr = (unsigned long *)sum;
77219 + int cryptres;
77220 + int retval = 1;
77221 + volatile int mismatched = 0;
77222 + volatile int dummy = 0;
77223 + unsigned int i;
77224 +
77225 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
77226 + if (IS_ERR(tfm)) {
77227 + /* should never happen, since sha256 should be built in */
77228 + memset(entry->pw, 0, GR_PW_LEN);
77229 + return 1;
77230 + }
77231 +
77232 + sg_init_table(sg, 2);
77233 + sg_set_buf(&sg[0], salt, GR_SALT_LEN);
77234 + sg_set_buf(&sg[1], entry->pw, strlen(entry->pw));
77235 +
77236 + desc.tfm = tfm;
77237 + desc.flags = 0;
77238 +
77239 + cryptres = crypto_hash_digest(&desc, sg, GR_SALT_LEN + strlen(entry->pw),
77240 + temp_sum);
77241 +
77242 + memset(entry->pw, 0, GR_PW_LEN);
77243 +
77244 + if (cryptres)
77245 + goto out;
77246 +
77247 + for (i = 0; i < GR_SHA_LEN/sizeof(tmpsumptr[0]); i++)
77248 + if (sumptr[i] != tmpsumptr[i])
77249 + mismatched = 1;
77250 + else
77251 + dummy = 1; // waste a cycle
77252 +
77253 + if (!mismatched)
77254 + retval = dummy - 1;
77255 +
77256 +out:
77257 + crypto_free_hash(tfm);
77258 +
77259 + return retval;
77260 +}
77261 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
77262 index 77ff547..181834f 100644
77263 --- a/include/asm-generic/4level-fixup.h
77264 +++ b/include/asm-generic/4level-fixup.h
77265 @@ -13,8 +13,10 @@
77266 #define pmd_alloc(mm, pud, address) \
77267 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
77268 NULL: pmd_offset(pud, address))
77269 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
77270
77271 #define pud_alloc(mm, pgd, address) (pgd)
77272 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
77273 #define pud_offset(pgd, start) (pgd)
77274 #define pud_none(pud) 0
77275 #define pud_bad(pud) 0
77276 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
77277 index b7babf0..97f4c4f 100644
77278 --- a/include/asm-generic/atomic-long.h
77279 +++ b/include/asm-generic/atomic-long.h
77280 @@ -22,6 +22,12 @@
77281
77282 typedef atomic64_t atomic_long_t;
77283
77284 +#ifdef CONFIG_PAX_REFCOUNT
77285 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
77286 +#else
77287 +typedef atomic64_t atomic_long_unchecked_t;
77288 +#endif
77289 +
77290 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
77291
77292 static inline long atomic_long_read(atomic_long_t *l)
77293 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
77294 return (long)atomic64_read(v);
77295 }
77296
77297 +#ifdef CONFIG_PAX_REFCOUNT
77298 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
77299 +{
77300 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77301 +
77302 + return (long)atomic64_read_unchecked(v);
77303 +}
77304 +#endif
77305 +
77306 static inline void atomic_long_set(atomic_long_t *l, long i)
77307 {
77308 atomic64_t *v = (atomic64_t *)l;
77309 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
77310 atomic64_set(v, i);
77311 }
77312
77313 +#ifdef CONFIG_PAX_REFCOUNT
77314 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
77315 +{
77316 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77317 +
77318 + atomic64_set_unchecked(v, i);
77319 +}
77320 +#endif
77321 +
77322 static inline void atomic_long_inc(atomic_long_t *l)
77323 {
77324 atomic64_t *v = (atomic64_t *)l;
77325 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
77326 atomic64_inc(v);
77327 }
77328
77329 +#ifdef CONFIG_PAX_REFCOUNT
77330 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
77331 +{
77332 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77333 +
77334 + atomic64_inc_unchecked(v);
77335 +}
77336 +#endif
77337 +
77338 static inline void atomic_long_dec(atomic_long_t *l)
77339 {
77340 atomic64_t *v = (atomic64_t *)l;
77341 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
77342 atomic64_dec(v);
77343 }
77344
77345 +#ifdef CONFIG_PAX_REFCOUNT
77346 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
77347 +{
77348 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77349 +
77350 + atomic64_dec_unchecked(v);
77351 +}
77352 +#endif
77353 +
77354 static inline void atomic_long_add(long i, atomic_long_t *l)
77355 {
77356 atomic64_t *v = (atomic64_t *)l;
77357 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
77358 atomic64_add(i, v);
77359 }
77360
77361 +#ifdef CONFIG_PAX_REFCOUNT
77362 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
77363 +{
77364 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77365 +
77366 + atomic64_add_unchecked(i, v);
77367 +}
77368 +#endif
77369 +
77370 static inline void atomic_long_sub(long i, atomic_long_t *l)
77371 {
77372 atomic64_t *v = (atomic64_t *)l;
77373 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
77374 atomic64_sub(i, v);
77375 }
77376
77377 +#ifdef CONFIG_PAX_REFCOUNT
77378 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
77379 +{
77380 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77381 +
77382 + atomic64_sub_unchecked(i, v);
77383 +}
77384 +#endif
77385 +
77386 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
77387 {
77388 atomic64_t *v = (atomic64_t *)l;
77389 @@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
77390 return atomic64_add_negative(i, v);
77391 }
77392
77393 -static inline long atomic_long_add_return(long i, atomic_long_t *l)
77394 +static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
77395 {
77396 atomic64_t *v = (atomic64_t *)l;
77397
77398 return (long)atomic64_add_return(i, v);
77399 }
77400
77401 +#ifdef CONFIG_PAX_REFCOUNT
77402 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
77403 +{
77404 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77405 +
77406 + return (long)atomic64_add_return_unchecked(i, v);
77407 +}
77408 +#endif
77409 +
77410 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
77411 {
77412 atomic64_t *v = (atomic64_t *)l;
77413 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
77414 return (long)atomic64_inc_return(v);
77415 }
77416
77417 +#ifdef CONFIG_PAX_REFCOUNT
77418 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
77419 +{
77420 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77421 +
77422 + return (long)atomic64_inc_return_unchecked(v);
77423 +}
77424 +#endif
77425 +
77426 static inline long atomic_long_dec_return(atomic_long_t *l)
77427 {
77428 atomic64_t *v = (atomic64_t *)l;
77429 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
77430
77431 typedef atomic_t atomic_long_t;
77432
77433 +#ifdef CONFIG_PAX_REFCOUNT
77434 +typedef atomic_unchecked_t atomic_long_unchecked_t;
77435 +#else
77436 +typedef atomic_t atomic_long_unchecked_t;
77437 +#endif
77438 +
77439 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
77440 static inline long atomic_long_read(atomic_long_t *l)
77441 {
77442 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
77443 return (long)atomic_read(v);
77444 }
77445
77446 +#ifdef CONFIG_PAX_REFCOUNT
77447 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
77448 +{
77449 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77450 +
77451 + return (long)atomic_read_unchecked(v);
77452 +}
77453 +#endif
77454 +
77455 static inline void atomic_long_set(atomic_long_t *l, long i)
77456 {
77457 atomic_t *v = (atomic_t *)l;
77458 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
77459 atomic_set(v, i);
77460 }
77461
77462 +#ifdef CONFIG_PAX_REFCOUNT
77463 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
77464 +{
77465 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77466 +
77467 + atomic_set_unchecked(v, i);
77468 +}
77469 +#endif
77470 +
77471 static inline void atomic_long_inc(atomic_long_t *l)
77472 {
77473 atomic_t *v = (atomic_t *)l;
77474 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
77475 atomic_inc(v);
77476 }
77477
77478 +#ifdef CONFIG_PAX_REFCOUNT
77479 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
77480 +{
77481 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77482 +
77483 + atomic_inc_unchecked(v);
77484 +}
77485 +#endif
77486 +
77487 static inline void atomic_long_dec(atomic_long_t *l)
77488 {
77489 atomic_t *v = (atomic_t *)l;
77490 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
77491 atomic_dec(v);
77492 }
77493
77494 +#ifdef CONFIG_PAX_REFCOUNT
77495 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
77496 +{
77497 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77498 +
77499 + atomic_dec_unchecked(v);
77500 +}
77501 +#endif
77502 +
77503 static inline void atomic_long_add(long i, atomic_long_t *l)
77504 {
77505 atomic_t *v = (atomic_t *)l;
77506 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
77507 atomic_add(i, v);
77508 }
77509
77510 +#ifdef CONFIG_PAX_REFCOUNT
77511 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
77512 +{
77513 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77514 +
77515 + atomic_add_unchecked(i, v);
77516 +}
77517 +#endif
77518 +
77519 static inline void atomic_long_sub(long i, atomic_long_t *l)
77520 {
77521 atomic_t *v = (atomic_t *)l;
77522 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
77523 atomic_sub(i, v);
77524 }
77525
77526 +#ifdef CONFIG_PAX_REFCOUNT
77527 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
77528 +{
77529 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77530 +
77531 + atomic_sub_unchecked(i, v);
77532 +}
77533 +#endif
77534 +
77535 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
77536 {
77537 atomic_t *v = (atomic_t *)l;
77538 @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
77539 return (long)atomic_add_return(i, v);
77540 }
77541
77542 +#ifdef CONFIG_PAX_REFCOUNT
77543 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
77544 +{
77545 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77546 +
77547 + return (long)atomic_add_return_unchecked(i, v);
77548 +}
77549 +
77550 +#endif
77551 +
77552 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
77553 {
77554 atomic_t *v = (atomic_t *)l;
77555 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
77556 return (long)atomic_inc_return(v);
77557 }
77558
77559 +#ifdef CONFIG_PAX_REFCOUNT
77560 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
77561 +{
77562 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77563 +
77564 + return (long)atomic_inc_return_unchecked(v);
77565 +}
77566 +#endif
77567 +
77568 static inline long atomic_long_dec_return(atomic_long_t *l)
77569 {
77570 atomic_t *v = (atomic_t *)l;
77571 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
77572
77573 #endif /* BITS_PER_LONG == 64 */
77574
77575 +#ifdef CONFIG_PAX_REFCOUNT
77576 +static inline void pax_refcount_needs_these_functions(void)
77577 +{
77578 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
77579 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
77580 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
77581 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
77582 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
77583 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
77584 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
77585 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
77586 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
77587 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
77588 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
77589 +#ifdef CONFIG_X86
77590 + atomic_clear_mask_unchecked(0, NULL);
77591 + atomic_set_mask_unchecked(0, NULL);
77592 +#endif
77593 +
77594 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
77595 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
77596 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
77597 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
77598 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
77599 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
77600 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
77601 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
77602 +}
77603 +#else
77604 +#define atomic_read_unchecked(v) atomic_read(v)
77605 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
77606 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
77607 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
77608 +#define atomic_inc_unchecked(v) atomic_inc(v)
77609 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
77610 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
77611 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
77612 +#define atomic_dec_unchecked(v) atomic_dec(v)
77613 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
77614 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
77615 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
77616 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
77617 +
77618 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
77619 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
77620 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
77621 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
77622 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
77623 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
77624 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
77625 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
77626 +#endif
77627 +
77628 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
77629 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
77630 index 33bd2de..f31bff97 100644
77631 --- a/include/asm-generic/atomic.h
77632 +++ b/include/asm-generic/atomic.h
77633 @@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
77634 * Atomically clears the bits set in @mask from @v
77635 */
77636 #ifndef atomic_clear_mask
77637 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
77638 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
77639 {
77640 unsigned long flags;
77641
77642 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
77643 index b18ce4f..2ee2843 100644
77644 --- a/include/asm-generic/atomic64.h
77645 +++ b/include/asm-generic/atomic64.h
77646 @@ -16,6 +16,8 @@ typedef struct {
77647 long long counter;
77648 } atomic64_t;
77649
77650 +typedef atomic64_t atomic64_unchecked_t;
77651 +
77652 #define ATOMIC64_INIT(i) { (i) }
77653
77654 extern long long atomic64_read(const atomic64_t *v);
77655 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
77656 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
77657 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
77658
77659 +#define atomic64_read_unchecked(v) atomic64_read(v)
77660 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
77661 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
77662 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
77663 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
77664 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
77665 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
77666 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
77667 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
77668 +
77669 #endif /* _ASM_GENERIC_ATOMIC64_H */
77670 diff --git a/include/asm-generic/barrier.h b/include/asm-generic/barrier.h
77671 index 6f692f8..2ad9dd2 100644
77672 --- a/include/asm-generic/barrier.h
77673 +++ b/include/asm-generic/barrier.h
77674 @@ -66,7 +66,7 @@
77675 do { \
77676 compiletime_assert_atomic_type(*p); \
77677 smp_mb(); \
77678 - ACCESS_ONCE(*p) = (v); \
77679 + ACCESS_ONCE_RW(*p) = (v); \
77680 } while (0)
77681
77682 #define smp_load_acquire(p) \
77683 diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
77684 index a60a7cc..0fe12f2 100644
77685 --- a/include/asm-generic/bitops/__fls.h
77686 +++ b/include/asm-generic/bitops/__fls.h
77687 @@ -9,7 +9,7 @@
77688 *
77689 * Undefined if no set bit exists, so code should check against 0 first.
77690 */
77691 -static __always_inline unsigned long __fls(unsigned long word)
77692 +static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
77693 {
77694 int num = BITS_PER_LONG - 1;
77695
77696 diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
77697 index 0576d1f..dad6c71 100644
77698 --- a/include/asm-generic/bitops/fls.h
77699 +++ b/include/asm-generic/bitops/fls.h
77700 @@ -9,7 +9,7 @@
77701 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
77702 */
77703
77704 -static __always_inline int fls(int x)
77705 +static __always_inline int __intentional_overflow(-1) fls(int x)
77706 {
77707 int r = 32;
77708
77709 diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
77710 index b097cf8..3d40e14 100644
77711 --- a/include/asm-generic/bitops/fls64.h
77712 +++ b/include/asm-generic/bitops/fls64.h
77713 @@ -15,7 +15,7 @@
77714 * at position 64.
77715 */
77716 #if BITS_PER_LONG == 32
77717 -static __always_inline int fls64(__u64 x)
77718 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
77719 {
77720 __u32 h = x >> 32;
77721 if (h)
77722 @@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
77723 return fls(x);
77724 }
77725 #elif BITS_PER_LONG == 64
77726 -static __always_inline int fls64(__u64 x)
77727 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
77728 {
77729 if (x == 0)
77730 return 0;
77731 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
77732 index 1bfcfe5..e04c5c9 100644
77733 --- a/include/asm-generic/cache.h
77734 +++ b/include/asm-generic/cache.h
77735 @@ -6,7 +6,7 @@
77736 * cache lines need to provide their own cache.h.
77737 */
77738
77739 -#define L1_CACHE_SHIFT 5
77740 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
77741 +#define L1_CACHE_SHIFT 5UL
77742 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
77743
77744 #endif /* __ASM_GENERIC_CACHE_H */
77745 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
77746 index 0d68a1e..b74a761 100644
77747 --- a/include/asm-generic/emergency-restart.h
77748 +++ b/include/asm-generic/emergency-restart.h
77749 @@ -1,7 +1,7 @@
77750 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
77751 #define _ASM_GENERIC_EMERGENCY_RESTART_H
77752
77753 -static inline void machine_emergency_restart(void)
77754 +static inline __noreturn void machine_emergency_restart(void)
77755 {
77756 machine_restart(NULL);
77757 }
77758 diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
77759 index 975e1cc..0b8a083 100644
77760 --- a/include/asm-generic/io.h
77761 +++ b/include/asm-generic/io.h
77762 @@ -289,7 +289,7 @@ static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
77763 * These are pretty trivial
77764 */
77765 #ifndef virt_to_phys
77766 -static inline unsigned long virt_to_phys(volatile void *address)
77767 +static inline unsigned long __intentional_overflow(-1) virt_to_phys(volatile void *address)
77768 {
77769 return __pa((unsigned long)address);
77770 }
77771 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
77772 index 90f99c7..00ce236 100644
77773 --- a/include/asm-generic/kmap_types.h
77774 +++ b/include/asm-generic/kmap_types.h
77775 @@ -2,9 +2,9 @@
77776 #define _ASM_GENERIC_KMAP_TYPES_H
77777
77778 #ifdef __WITH_KM_FENCE
77779 -# define KM_TYPE_NR 41
77780 +# define KM_TYPE_NR 42
77781 #else
77782 -# define KM_TYPE_NR 20
77783 +# define KM_TYPE_NR 21
77784 #endif
77785
77786 #endif
77787 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
77788 index 9ceb03b..62b0b8f 100644
77789 --- a/include/asm-generic/local.h
77790 +++ b/include/asm-generic/local.h
77791 @@ -23,24 +23,37 @@ typedef struct
77792 atomic_long_t a;
77793 } local_t;
77794
77795 +typedef struct {
77796 + atomic_long_unchecked_t a;
77797 +} local_unchecked_t;
77798 +
77799 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
77800
77801 #define local_read(l) atomic_long_read(&(l)->a)
77802 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
77803 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
77804 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
77805 #define local_inc(l) atomic_long_inc(&(l)->a)
77806 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
77807 #define local_dec(l) atomic_long_dec(&(l)->a)
77808 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
77809 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
77810 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
77811 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
77812 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
77813
77814 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
77815 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
77816 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
77817 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
77818 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
77819 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
77820 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
77821 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
77822 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
77823
77824 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
77825 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
77826 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
77827 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
77828 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
77829 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
77830 index 725612b..9cc513a 100644
77831 --- a/include/asm-generic/pgtable-nopmd.h
77832 +++ b/include/asm-generic/pgtable-nopmd.h
77833 @@ -1,14 +1,19 @@
77834 #ifndef _PGTABLE_NOPMD_H
77835 #define _PGTABLE_NOPMD_H
77836
77837 -#ifndef __ASSEMBLY__
77838 -
77839 #include <asm-generic/pgtable-nopud.h>
77840
77841 -struct mm_struct;
77842 -
77843 #define __PAGETABLE_PMD_FOLDED
77844
77845 +#define PMD_SHIFT PUD_SHIFT
77846 +#define PTRS_PER_PMD 1
77847 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
77848 +#define PMD_MASK (~(PMD_SIZE-1))
77849 +
77850 +#ifndef __ASSEMBLY__
77851 +
77852 +struct mm_struct;
77853 +
77854 /*
77855 * Having the pmd type consist of a pud gets the size right, and allows
77856 * us to conceptually access the pud entry that this pmd is folded into
77857 @@ -16,11 +21,6 @@ struct mm_struct;
77858 */
77859 typedef struct { pud_t pud; } pmd_t;
77860
77861 -#define PMD_SHIFT PUD_SHIFT
77862 -#define PTRS_PER_PMD 1
77863 -#define PMD_SIZE (1UL << PMD_SHIFT)
77864 -#define PMD_MASK (~(PMD_SIZE-1))
77865 -
77866 /*
77867 * The "pud_xxx()" functions here are trivial for a folded two-level
77868 * setup: the pmd is never bad, and a pmd always exists (as it's folded
77869 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
77870 index 810431d..0ec4804f 100644
77871 --- a/include/asm-generic/pgtable-nopud.h
77872 +++ b/include/asm-generic/pgtable-nopud.h
77873 @@ -1,10 +1,15 @@
77874 #ifndef _PGTABLE_NOPUD_H
77875 #define _PGTABLE_NOPUD_H
77876
77877 -#ifndef __ASSEMBLY__
77878 -
77879 #define __PAGETABLE_PUD_FOLDED
77880
77881 +#define PUD_SHIFT PGDIR_SHIFT
77882 +#define PTRS_PER_PUD 1
77883 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
77884 +#define PUD_MASK (~(PUD_SIZE-1))
77885 +
77886 +#ifndef __ASSEMBLY__
77887 +
77888 /*
77889 * Having the pud type consist of a pgd gets the size right, and allows
77890 * us to conceptually access the pgd entry that this pud is folded into
77891 @@ -12,11 +17,6 @@
77892 */
77893 typedef struct { pgd_t pgd; } pud_t;
77894
77895 -#define PUD_SHIFT PGDIR_SHIFT
77896 -#define PTRS_PER_PUD 1
77897 -#define PUD_SIZE (1UL << PUD_SHIFT)
77898 -#define PUD_MASK (~(PUD_SIZE-1))
77899 -
77900 /*
77901 * The "pgd_xxx()" functions here are trivial for a folded two-level
77902 * setup: the pud is never bad, and a pud always exists (as it's folded
77903 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
77904 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
77905
77906 #define pgd_populate(mm, pgd, pud) do { } while (0)
77907 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
77908 /*
77909 * (puds are folded into pgds so this doesn't get actually called,
77910 * but the define is needed for a generic inline function.)
77911 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
77912 index a8015a7..7a4407b 100644
77913 --- a/include/asm-generic/pgtable.h
77914 +++ b/include/asm-generic/pgtable.h
77915 @@ -815,6 +815,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
77916 }
77917 #endif /* CONFIG_NUMA_BALANCING */
77918
77919 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
77920 +#ifdef CONFIG_PAX_KERNEXEC
77921 +#error KERNEXEC requires pax_open_kernel
77922 +#else
77923 +static inline unsigned long pax_open_kernel(void) { return 0; }
77924 +#endif
77925 +#endif
77926 +
77927 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
77928 +#ifdef CONFIG_PAX_KERNEXEC
77929 +#error KERNEXEC requires pax_close_kernel
77930 +#else
77931 +static inline unsigned long pax_close_kernel(void) { return 0; }
77932 +#endif
77933 +#endif
77934 +
77935 #endif /* CONFIG_MMU */
77936
77937 #endif /* !__ASSEMBLY__ */
77938 diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
77939 index 72d8803..cb9749c 100644
77940 --- a/include/asm-generic/uaccess.h
77941 +++ b/include/asm-generic/uaccess.h
77942 @@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
77943 return __clear_user(to, n);
77944 }
77945
77946 +#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
77947 +#ifdef CONFIG_PAX_MEMORY_UDEREF
77948 +#error UDEREF requires pax_open_userland
77949 +#else
77950 +static inline unsigned long pax_open_userland(void) { return 0; }
77951 +#endif
77952 +#endif
77953 +
77954 +#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
77955 +#ifdef CONFIG_PAX_MEMORY_UDEREF
77956 +#error UDEREF requires pax_close_userland
77957 +#else
77958 +static inline unsigned long pax_close_userland(void) { return 0; }
77959 +#endif
77960 +#endif
77961 +
77962 #endif /* __ASM_GENERIC_UACCESS_H */
77963 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
77964 index 146e4ff..f4f9609 100644
77965 --- a/include/asm-generic/vmlinux.lds.h
77966 +++ b/include/asm-generic/vmlinux.lds.h
77967 @@ -251,6 +251,7 @@
77968 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
77969 VMLINUX_SYMBOL(__start_rodata) = .; \
77970 *(.rodata) *(.rodata.*) \
77971 + *(.data..read_only) \
77972 *(__vermagic) /* Kernel version magic */ \
77973 . = ALIGN(8); \
77974 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
77975 @@ -737,17 +738,18 @@
77976 * section in the linker script will go there too. @phdr should have
77977 * a leading colon.
77978 *
77979 - * Note that this macros defines __per_cpu_load as an absolute symbol.
77980 + * Note that this macros defines per_cpu_load as an absolute symbol.
77981 * If there is no need to put the percpu section at a predetermined
77982 * address, use PERCPU_SECTION.
77983 */
77984 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
77985 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
77986 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
77987 + per_cpu_load = .; \
77988 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
77989 - LOAD_OFFSET) { \
77990 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
77991 PERCPU_INPUT(cacheline) \
77992 } phdr \
77993 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
77994 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
77995
77996 /**
77997 * PERCPU_SECTION - define output section for percpu area, simple version
77998 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
77999 index 016c2f1..c4baa98 100644
78000 --- a/include/crypto/algapi.h
78001 +++ b/include/crypto/algapi.h
78002 @@ -34,7 +34,7 @@ struct crypto_type {
78003 unsigned int maskclear;
78004 unsigned int maskset;
78005 unsigned int tfmsize;
78006 -};
78007 +} __do_const;
78008
78009 struct crypto_instance {
78010 struct crypto_alg alg;
78011 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
78012 index a7c2a86..078f1b6 100644
78013 --- a/include/drm/drmP.h
78014 +++ b/include/drm/drmP.h
78015 @@ -68,6 +68,7 @@
78016 #include <linux/workqueue.h>
78017 #include <linux/poll.h>
78018 #include <asm/pgalloc.h>
78019 +#include <asm/local.h>
78020 #include <drm/drm.h>
78021 #include <drm/drm_sarea.h>
78022 #include <drm/drm_vma_manager.h>
78023 @@ -268,10 +269,12 @@ do { \
78024 * \param cmd command.
78025 * \param arg argument.
78026 */
78027 -typedef int drm_ioctl_t(struct drm_device *dev, void *data,
78028 +typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
78029 + struct drm_file *file_priv);
78030 +typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
78031 struct drm_file *file_priv);
78032
78033 -typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
78034 +typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
78035 unsigned long arg);
78036
78037 #define DRM_IOCTL_NR(n) _IOC_NR(n)
78038 @@ -287,10 +290,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
78039 struct drm_ioctl_desc {
78040 unsigned int cmd;
78041 int flags;
78042 - drm_ioctl_t *func;
78043 + drm_ioctl_t func;
78044 unsigned int cmd_drv;
78045 const char *name;
78046 -};
78047 +} __do_const;
78048
78049 /**
78050 * Creates a driver or general drm_ioctl_desc array entry for the given
78051 @@ -1001,7 +1004,8 @@ struct drm_info_list {
78052 int (*show)(struct seq_file*, void*); /** show callback */
78053 u32 driver_features; /**< Required driver features for this entry */
78054 void *data;
78055 -};
78056 +} __do_const;
78057 +typedef struct drm_info_list __no_const drm_info_list_no_const;
78058
78059 /**
78060 * debugfs node structure. This structure represents a debugfs file.
78061 @@ -1083,7 +1087,7 @@ struct drm_device {
78062
78063 /** \name Usage Counters */
78064 /*@{ */
78065 - int open_count; /**< Outstanding files open */
78066 + local_t open_count; /**< Outstanding files open */
78067 int buf_use; /**< Buffers in use -- cannot alloc */
78068 atomic_t buf_alloc; /**< Buffer allocation in progress */
78069 /*@} */
78070 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
78071 index 36a5feb..d9f01aa 100644
78072 --- a/include/drm/drm_crtc_helper.h
78073 +++ b/include/drm/drm_crtc_helper.h
78074 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
78075 struct drm_connector *connector);
78076 /* disable encoder when not in use - more explicit than dpms off */
78077 void (*disable)(struct drm_encoder *encoder);
78078 -};
78079 +} __no_const;
78080
78081 /**
78082 * drm_connector_helper_funcs - helper operations for connectors
78083 diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
78084 index 012d58f..d0a0642 100644
78085 --- a/include/drm/i915_pciids.h
78086 +++ b/include/drm/i915_pciids.h
78087 @@ -37,7 +37,7 @@
78088 */
78089 #define INTEL_VGA_DEVICE(id, info) { \
78090 0x8086, id, \
78091 - ~0, ~0, \
78092 + PCI_ANY_ID, PCI_ANY_ID, \
78093 0x030000, 0xff0000, \
78094 (unsigned long) info }
78095
78096 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
78097 index 72dcbe8..8db58d7 100644
78098 --- a/include/drm/ttm/ttm_memory.h
78099 +++ b/include/drm/ttm/ttm_memory.h
78100 @@ -48,7 +48,7 @@
78101
78102 struct ttm_mem_shrink {
78103 int (*do_shrink) (struct ttm_mem_shrink *);
78104 -};
78105 +} __no_const;
78106
78107 /**
78108 * struct ttm_mem_global - Global memory accounting structure.
78109 diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
78110 index 49a8284..9643967 100644
78111 --- a/include/drm/ttm/ttm_page_alloc.h
78112 +++ b/include/drm/ttm/ttm_page_alloc.h
78113 @@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
78114 */
78115 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
78116
78117 +struct device;
78118 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
78119 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
78120
78121 diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
78122 index 4b840e8..155d235 100644
78123 --- a/include/keys/asymmetric-subtype.h
78124 +++ b/include/keys/asymmetric-subtype.h
78125 @@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
78126 /* Verify the signature on a key of this subtype (optional) */
78127 int (*verify_signature)(const struct key *key,
78128 const struct public_key_signature *sig);
78129 -};
78130 +} __do_const;
78131
78132 /**
78133 * asymmetric_key_subtype - Get the subtype from an asymmetric key
78134 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
78135 index c1da539..1dcec55 100644
78136 --- a/include/linux/atmdev.h
78137 +++ b/include/linux/atmdev.h
78138 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
78139 #endif
78140
78141 struct k_atm_aal_stats {
78142 -#define __HANDLE_ITEM(i) atomic_t i
78143 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
78144 __AAL_STAT_ITEMS
78145 #undef __HANDLE_ITEM
78146 };
78147 @@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
78148 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
78149 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
78150 struct module *owner;
78151 -};
78152 +} __do_const ;
78153
78154 struct atmphy_ops {
78155 int (*start)(struct atm_dev *dev);
78156 diff --git a/include/linux/audit.h b/include/linux/audit.h
78157 index 22cfddb..ab759e8 100644
78158 --- a/include/linux/audit.h
78159 +++ b/include/linux/audit.h
78160 @@ -210,7 +210,7 @@ static inline void audit_ptrace(struct task_struct *t)
78161 extern unsigned int audit_serial(void);
78162 extern int auditsc_get_stamp(struct audit_context *ctx,
78163 struct timespec *t, unsigned int *serial);
78164 -extern int audit_set_loginuid(kuid_t loginuid);
78165 +extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
78166
78167 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
78168 {
78169 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
78170 index 61f29e5..e67c658 100644
78171 --- a/include/linux/binfmts.h
78172 +++ b/include/linux/binfmts.h
78173 @@ -44,7 +44,7 @@ struct linux_binprm {
78174 unsigned interp_flags;
78175 unsigned interp_data;
78176 unsigned long loader, exec;
78177 -};
78178 +} __randomize_layout;
78179
78180 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
78181 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
78182 @@ -73,8 +73,10 @@ struct linux_binfmt {
78183 int (*load_binary)(struct linux_binprm *);
78184 int (*load_shlib)(struct file *);
78185 int (*core_dump)(struct coredump_params *cprm);
78186 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
78187 + void (*handle_mmap)(struct file *);
78188 unsigned long min_coredump; /* minimal dump size */
78189 -};
78190 +} __do_const __randomize_layout;
78191
78192 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
78193
78194 diff --git a/include/linux/bitops.h b/include/linux/bitops.h
78195 index be5fd38..d71192a 100644
78196 --- a/include/linux/bitops.h
78197 +++ b/include/linux/bitops.h
78198 @@ -102,7 +102,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
78199 * @word: value to rotate
78200 * @shift: bits to roll
78201 */
78202 -static inline __u32 rol32(__u32 word, unsigned int shift)
78203 +static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
78204 {
78205 return (word << shift) | (word >> (32 - shift));
78206 }
78207 @@ -112,7 +112,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
78208 * @word: value to rotate
78209 * @shift: bits to roll
78210 */
78211 -static inline __u32 ror32(__u32 word, unsigned int shift)
78212 +static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
78213 {
78214 return (word >> shift) | (word << (32 - shift));
78215 }
78216 @@ -168,7 +168,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
78217 return (__s32)(value << shift) >> shift;
78218 }
78219
78220 -static inline unsigned fls_long(unsigned long l)
78221 +static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
78222 {
78223 if (sizeof(l) == 4)
78224 return fls(l);
78225 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
78226 index 0d84981..bb741c0 100644
78227 --- a/include/linux/blkdev.h
78228 +++ b/include/linux/blkdev.h
78229 @@ -1584,7 +1584,7 @@ struct block_device_operations {
78230 /* this callback is with swap_lock and sometimes page table lock held */
78231 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
78232 struct module *owner;
78233 -};
78234 +} __do_const;
78235
78236 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
78237 unsigned long);
78238 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
78239 index afc1343..9735539 100644
78240 --- a/include/linux/blktrace_api.h
78241 +++ b/include/linux/blktrace_api.h
78242 @@ -25,7 +25,7 @@ struct blk_trace {
78243 struct dentry *dropped_file;
78244 struct dentry *msg_file;
78245 struct list_head running_list;
78246 - atomic_t dropped;
78247 + atomic_unchecked_t dropped;
78248 };
78249
78250 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
78251 diff --git a/include/linux/cache.h b/include/linux/cache.h
78252 index 17e7e82..1d7da26 100644
78253 --- a/include/linux/cache.h
78254 +++ b/include/linux/cache.h
78255 @@ -16,6 +16,14 @@
78256 #define __read_mostly
78257 #endif
78258
78259 +#ifndef __read_only
78260 +#ifdef CONFIG_PAX_KERNEXEC
78261 +#error KERNEXEC requires __read_only
78262 +#else
78263 +#define __read_only __read_mostly
78264 +#endif
78265 +#endif
78266 +
78267 #ifndef ____cacheline_aligned
78268 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
78269 #endif
78270 diff --git a/include/linux/capability.h b/include/linux/capability.h
78271 index 84b13ad..172cdee 100644
78272 --- a/include/linux/capability.h
78273 +++ b/include/linux/capability.h
78274 @@ -211,9 +211,14 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
78275 extern bool capable(int cap);
78276 extern bool ns_capable(struct user_namespace *ns, int cap);
78277 extern bool capable_wrt_inode_uidgid(const struct inode *inode, int cap);
78278 +extern bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap);
78279 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
78280 +extern bool capable_nolog(int cap);
78281 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
78282
78283 /* audit system wants to get cap info from files as well */
78284 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
78285
78286 +extern int is_privileged_binary(const struct dentry *dentry);
78287 +
78288 #endif /* !_LINUX_CAPABILITY_H */
78289 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
78290 index 8609d57..86e4d79 100644
78291 --- a/include/linux/cdrom.h
78292 +++ b/include/linux/cdrom.h
78293 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
78294
78295 /* driver specifications */
78296 const int capability; /* capability flags */
78297 - int n_minors; /* number of active minor devices */
78298 /* handle uniform packets for scsi type devices (scsi,atapi) */
78299 int (*generic_packet) (struct cdrom_device_info *,
78300 struct packet_command *);
78301 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
78302 index 4ce9056..86caac6 100644
78303 --- a/include/linux/cleancache.h
78304 +++ b/include/linux/cleancache.h
78305 @@ -31,7 +31,7 @@ struct cleancache_ops {
78306 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
78307 void (*invalidate_inode)(int, struct cleancache_filekey);
78308 void (*invalidate_fs)(int);
78309 -};
78310 +} __no_const;
78311
78312 extern struct cleancache_ops *
78313 cleancache_register_ops(struct cleancache_ops *ops);
78314 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
78315 index 5119174..8e264f8 100644
78316 --- a/include/linux/clk-provider.h
78317 +++ b/include/linux/clk-provider.h
78318 @@ -174,6 +174,7 @@ struct clk_ops {
78319 void (*init)(struct clk_hw *hw);
78320 int (*debug_init)(struct clk_hw *hw, struct dentry *dentry);
78321 };
78322 +typedef struct clk_ops __no_const clk_ops_no_const;
78323
78324 /**
78325 * struct clk_init_data - holds init data that's common to all clocks and is
78326 diff --git a/include/linux/compat.h b/include/linux/compat.h
78327 index e649426..a74047b 100644
78328 --- a/include/linux/compat.h
78329 +++ b/include/linux/compat.h
78330 @@ -316,7 +316,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
78331 compat_size_t __user *len_ptr);
78332
78333 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
78334 -asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
78335 +asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
78336 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
78337 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
78338 compat_ssize_t msgsz, int msgflg);
78339 @@ -436,7 +436,7 @@ extern int compat_ptrace_request(struct task_struct *child,
78340 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
78341 compat_ulong_t addr, compat_ulong_t data);
78342 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
78343 - compat_long_t addr, compat_long_t data);
78344 + compat_ulong_t addr, compat_ulong_t data);
78345
78346 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
78347 /*
78348 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
78349 index 2507fd2..55203f8 100644
78350 --- a/include/linux/compiler-gcc4.h
78351 +++ b/include/linux/compiler-gcc4.h
78352 @@ -39,9 +39,34 @@
78353 # define __compiletime_warning(message) __attribute__((warning(message)))
78354 # define __compiletime_error(message) __attribute__((error(message)))
78355 #endif /* __CHECKER__ */
78356 +
78357 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
78358 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
78359 +#define __bos0(ptr) __bos((ptr), 0)
78360 +#define __bos1(ptr) __bos((ptr), 1)
78361 #endif /* GCC_VERSION >= 40300 */
78362
78363 #if GCC_VERSION >= 40500
78364 +
78365 +#ifdef RANDSTRUCT_PLUGIN
78366 +#define __randomize_layout __attribute__((randomize_layout))
78367 +#define __no_randomize_layout __attribute__((no_randomize_layout))
78368 +#endif
78369 +
78370 +#ifdef CONSTIFY_PLUGIN
78371 +#define __no_const __attribute__((no_const))
78372 +#define __do_const __attribute__((do_const))
78373 +#endif
78374 +
78375 +#ifdef SIZE_OVERFLOW_PLUGIN
78376 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
78377 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
78378 +#endif
78379 +
78380 +#ifdef LATENT_ENTROPY_PLUGIN
78381 +#define __latent_entropy __attribute__((latent_entropy))
78382 +#endif
78383 +
78384 /*
78385 * Mark a position in code as unreachable. This can be used to
78386 * suppress control flow warnings after asm blocks that transfer
78387 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
78388 index ee7239e..7c11769 100644
78389 --- a/include/linux/compiler.h
78390 +++ b/include/linux/compiler.h
78391 @@ -5,11 +5,14 @@
78392
78393 #ifdef __CHECKER__
78394 # define __user __attribute__((noderef, address_space(1)))
78395 +# define __force_user __force __user
78396 # define __kernel __attribute__((address_space(0)))
78397 +# define __force_kernel __force __kernel
78398 # define __safe __attribute__((safe))
78399 # define __force __attribute__((force))
78400 # define __nocast __attribute__((nocast))
78401 # define __iomem __attribute__((noderef, address_space(2)))
78402 +# define __force_iomem __force __iomem
78403 # define __must_hold(x) __attribute__((context(x,1,1)))
78404 # define __acquires(x) __attribute__((context(x,0,1)))
78405 # define __releases(x) __attribute__((context(x,1,0)))
78406 @@ -17,20 +20,37 @@
78407 # define __release(x) __context__(x,-1)
78408 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
78409 # define __percpu __attribute__((noderef, address_space(3)))
78410 +# define __force_percpu __force __percpu
78411 #ifdef CONFIG_SPARSE_RCU_POINTER
78412 # define __rcu __attribute__((noderef, address_space(4)))
78413 +# define __force_rcu __force __rcu
78414 #else
78415 # define __rcu
78416 +# define __force_rcu
78417 #endif
78418 extern void __chk_user_ptr(const volatile void __user *);
78419 extern void __chk_io_ptr(const volatile void __iomem *);
78420 #else
78421 -# define __user
78422 -# define __kernel
78423 +# ifdef CHECKER_PLUGIN
78424 +//# define __user
78425 +//# define __force_user
78426 +//# define __kernel
78427 +//# define __force_kernel
78428 +# else
78429 +# ifdef STRUCTLEAK_PLUGIN
78430 +# define __user __attribute__((user))
78431 +# else
78432 +# define __user
78433 +# endif
78434 +# define __force_user
78435 +# define __kernel
78436 +# define __force_kernel
78437 +# endif
78438 # define __safe
78439 # define __force
78440 # define __nocast
78441 # define __iomem
78442 +# define __force_iomem
78443 # define __chk_user_ptr(x) (void)0
78444 # define __chk_io_ptr(x) (void)0
78445 # define __builtin_warning(x, y...) (1)
78446 @@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
78447 # define __release(x) (void)0
78448 # define __cond_lock(x,c) (c)
78449 # define __percpu
78450 +# define __force_percpu
78451 # define __rcu
78452 +# define __force_rcu
78453 #endif
78454
78455 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
78456 @@ -286,6 +308,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
78457 # define __attribute_const__ /* unimplemented */
78458 #endif
78459
78460 +#ifndef __randomize_layout
78461 +# define __randomize_layout
78462 +#endif
78463 +
78464 +#ifndef __no_randomize_layout
78465 +# define __no_randomize_layout
78466 +#endif
78467 +
78468 +#ifndef __no_const
78469 +# define __no_const
78470 +#endif
78471 +
78472 +#ifndef __do_const
78473 +# define __do_const
78474 +#endif
78475 +
78476 +#ifndef __size_overflow
78477 +# define __size_overflow(...)
78478 +#endif
78479 +
78480 +#ifndef __intentional_overflow
78481 +# define __intentional_overflow(...)
78482 +#endif
78483 +
78484 +#ifndef __latent_entropy
78485 +# define __latent_entropy
78486 +#endif
78487 +
78488 /*
78489 * Tell gcc if a function is cold. The compiler will assume any path
78490 * directly leading to the call is unlikely.
78491 @@ -295,6 +345,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
78492 #define __cold
78493 #endif
78494
78495 +#ifndef __alloc_size
78496 +#define __alloc_size(...)
78497 +#endif
78498 +
78499 +#ifndef __bos
78500 +#define __bos(ptr, arg)
78501 +#endif
78502 +
78503 +#ifndef __bos0
78504 +#define __bos0(ptr)
78505 +#endif
78506 +
78507 +#ifndef __bos1
78508 +#define __bos1(ptr)
78509 +#endif
78510 +
78511 /* Simple shorthand for a section definition */
78512 #ifndef __section
78513 # define __section(S) __attribute__ ((__section__(#S)))
78514 @@ -369,7 +435,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
78515 * use is to mediate communication between process-level code and irq/NMI
78516 * handlers, all running on the same CPU.
78517 */
78518 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
78519 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
78520 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
78521
78522 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
78523 #ifdef CONFIG_KPROBES
78524 diff --git a/include/linux/completion.h b/include/linux/completion.h
78525 index 5d5aaae..0ea9b84 100644
78526 --- a/include/linux/completion.h
78527 +++ b/include/linux/completion.h
78528 @@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
78529
78530 extern void wait_for_completion(struct completion *);
78531 extern void wait_for_completion_io(struct completion *);
78532 -extern int wait_for_completion_interruptible(struct completion *x);
78533 -extern int wait_for_completion_killable(struct completion *x);
78534 +extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
78535 +extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
78536 extern unsigned long wait_for_completion_timeout(struct completion *x,
78537 - unsigned long timeout);
78538 + unsigned long timeout) __intentional_overflow(-1);
78539 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
78540 - unsigned long timeout);
78541 + unsigned long timeout) __intentional_overflow(-1);
78542 extern long wait_for_completion_interruptible_timeout(
78543 - struct completion *x, unsigned long timeout);
78544 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
78545 extern long wait_for_completion_killable_timeout(
78546 - struct completion *x, unsigned long timeout);
78547 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
78548 extern bool try_wait_for_completion(struct completion *x);
78549 extern bool completion_done(struct completion *x);
78550
78551 diff --git a/include/linux/configfs.h b/include/linux/configfs.h
78552 index 34025df..d94bbbc 100644
78553 --- a/include/linux/configfs.h
78554 +++ b/include/linux/configfs.h
78555 @@ -125,7 +125,7 @@ struct configfs_attribute {
78556 const char *ca_name;
78557 struct module *ca_owner;
78558 umode_t ca_mode;
78559 -};
78560 +} __do_const;
78561
78562 /*
78563 * Users often need to create attribute structures for their configurable
78564 diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
78565 index 5ae5100..b809662 100644
78566 --- a/include/linux/cpufreq.h
78567 +++ b/include/linux/cpufreq.h
78568 @@ -200,6 +200,7 @@ struct global_attr {
78569 ssize_t (*store)(struct kobject *a, struct attribute *b,
78570 const char *c, size_t count);
78571 };
78572 +typedef struct global_attr __no_const global_attr_no_const;
78573
78574 #define define_one_global_ro(_name) \
78575 static struct global_attr _name = \
78576 @@ -242,7 +243,7 @@ struct cpufreq_driver {
78577 bool boost_supported;
78578 bool boost_enabled;
78579 int (*set_boost) (int state);
78580 -};
78581 +} __do_const;
78582
78583 /* flags */
78584 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
78585 diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
78586 index b0238cb..db89e1e 100644
78587 --- a/include/linux/cpuidle.h
78588 +++ b/include/linux/cpuidle.h
78589 @@ -50,7 +50,8 @@ struct cpuidle_state {
78590 int index);
78591
78592 int (*enter_dead) (struct cpuidle_device *dev, int index);
78593 -};
78594 +} __do_const;
78595 +typedef struct cpuidle_state __no_const cpuidle_state_no_const;
78596
78597 /* Idle State Flags */
78598 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
78599 @@ -211,7 +212,7 @@ struct cpuidle_governor {
78600 void (*reflect) (struct cpuidle_device *dev, int index);
78601
78602 struct module *owner;
78603 -};
78604 +} __do_const;
78605
78606 #ifdef CONFIG_CPU_IDLE
78607 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
78608 diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
78609 index d08e4d2..95fad61 100644
78610 --- a/include/linux/cpumask.h
78611 +++ b/include/linux/cpumask.h
78612 @@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
78613 }
78614
78615 /* Valid inputs for n are -1 and 0. */
78616 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
78617 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
78618 {
78619 return n+1;
78620 }
78621
78622 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
78623 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
78624 {
78625 return n+1;
78626 }
78627
78628 -static inline unsigned int cpumask_next_and(int n,
78629 +static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
78630 const struct cpumask *srcp,
78631 const struct cpumask *andp)
78632 {
78633 @@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
78634 *
78635 * Returns >= nr_cpu_ids if no further cpus set.
78636 */
78637 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
78638 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
78639 {
78640 /* -1 is a legal arg here. */
78641 if (n != -1)
78642 @@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
78643 *
78644 * Returns >= nr_cpu_ids if no further cpus unset.
78645 */
78646 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
78647 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
78648 {
78649 /* -1 is a legal arg here. */
78650 if (n != -1)
78651 @@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
78652 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
78653 }
78654
78655 -int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
78656 +int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
78657 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
78658
78659 /**
78660 diff --git a/include/linux/cred.h b/include/linux/cred.h
78661 index f61d6c8..d372d95 100644
78662 --- a/include/linux/cred.h
78663 +++ b/include/linux/cred.h
78664 @@ -35,7 +35,7 @@ struct group_info {
78665 int nblocks;
78666 kgid_t small_block[NGROUPS_SMALL];
78667 kgid_t *blocks[0];
78668 -};
78669 +} __randomize_layout;
78670
78671 /**
78672 * get_group_info - Get a reference to a group info structure
78673 @@ -136,7 +136,7 @@ struct cred {
78674 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
78675 struct group_info *group_info; /* supplementary groups for euid/fsgid */
78676 struct rcu_head rcu; /* RCU deletion hook */
78677 -};
78678 +} __randomize_layout;
78679
78680 extern void __put_cred(struct cred *);
78681 extern void exit_creds(struct task_struct *);
78682 @@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
78683 static inline void validate_process_creds(void)
78684 {
78685 }
78686 +static inline void validate_task_creds(struct task_struct *task)
78687 +{
78688 +}
78689 #endif
78690
78691 /**
78692 @@ -322,6 +325,7 @@ static inline void put_cred(const struct cred *_cred)
78693
78694 #define task_uid(task) (task_cred_xxx((task), uid))
78695 #define task_euid(task) (task_cred_xxx((task), euid))
78696 +#define task_securebits(task) (task_cred_xxx((task), securebits))
78697
78698 #define current_cred_xxx(xxx) \
78699 ({ \
78700 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
78701 index b92eadf..b4ecdc1 100644
78702 --- a/include/linux/crypto.h
78703 +++ b/include/linux/crypto.h
78704 @@ -373,7 +373,7 @@ struct cipher_tfm {
78705 const u8 *key, unsigned int keylen);
78706 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
78707 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
78708 -};
78709 +} __no_const;
78710
78711 struct hash_tfm {
78712 int (*init)(struct hash_desc *desc);
78713 @@ -394,13 +394,13 @@ struct compress_tfm {
78714 int (*cot_decompress)(struct crypto_tfm *tfm,
78715 const u8 *src, unsigned int slen,
78716 u8 *dst, unsigned int *dlen);
78717 -};
78718 +} __no_const;
78719
78720 struct rng_tfm {
78721 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
78722 unsigned int dlen);
78723 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
78724 -};
78725 +} __no_const;
78726
78727 #define crt_ablkcipher crt_u.ablkcipher
78728 #define crt_aead crt_u.aead
78729 diff --git a/include/linux/ctype.h b/include/linux/ctype.h
78730 index 653589e..4ef254a 100644
78731 --- a/include/linux/ctype.h
78732 +++ b/include/linux/ctype.h
78733 @@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
78734 * Fast implementation of tolower() for internal usage. Do not use in your
78735 * code.
78736 */
78737 -static inline char _tolower(const char c)
78738 +static inline unsigned char _tolower(const unsigned char c)
78739 {
78740 return c | 0x20;
78741 }
78742 diff --git a/include/linux/dcache.h b/include/linux/dcache.h
78743 index 3c7ec32..4ca97cc 100644
78744 --- a/include/linux/dcache.h
78745 +++ b/include/linux/dcache.h
78746 @@ -133,7 +133,7 @@ struct dentry {
78747 } d_u;
78748 struct list_head d_subdirs; /* our children */
78749 struct hlist_node d_alias; /* inode alias list */
78750 -};
78751 +} __randomize_layout;
78752
78753 /*
78754 * dentry->d_lock spinlock nesting subclasses:
78755 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
78756 index 7925bf0..d5143d2 100644
78757 --- a/include/linux/decompress/mm.h
78758 +++ b/include/linux/decompress/mm.h
78759 @@ -77,7 +77,7 @@ static void free(void *where)
78760 * warnings when not needed (indeed large_malloc / large_free are not
78761 * needed by inflate */
78762
78763 -#define malloc(a) kmalloc(a, GFP_KERNEL)
78764 +#define malloc(a) kmalloc((a), GFP_KERNEL)
78765 #define free(a) kfree(a)
78766
78767 #define large_malloc(a) vmalloc(a)
78768 diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
78769 index d48dc00..211ee54 100644
78770 --- a/include/linux/devfreq.h
78771 +++ b/include/linux/devfreq.h
78772 @@ -114,7 +114,7 @@ struct devfreq_governor {
78773 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
78774 int (*event_handler)(struct devfreq *devfreq,
78775 unsigned int event, void *data);
78776 -};
78777 +} __do_const;
78778
78779 /**
78780 * struct devfreq - Device devfreq structure
78781 diff --git a/include/linux/device.h b/include/linux/device.h
78782 index d1d1c05..a90fdb0 100644
78783 --- a/include/linux/device.h
78784 +++ b/include/linux/device.h
78785 @@ -310,7 +310,7 @@ struct subsys_interface {
78786 struct list_head node;
78787 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
78788 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
78789 -};
78790 +} __do_const;
78791
78792 int subsys_interface_register(struct subsys_interface *sif);
78793 void subsys_interface_unregister(struct subsys_interface *sif);
78794 @@ -506,7 +506,7 @@ struct device_type {
78795 void (*release)(struct device *dev);
78796
78797 const struct dev_pm_ops *pm;
78798 -};
78799 +} __do_const;
78800
78801 /* interface for exporting device attributes */
78802 struct device_attribute {
78803 @@ -516,11 +516,12 @@ struct device_attribute {
78804 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
78805 const char *buf, size_t count);
78806 };
78807 +typedef struct device_attribute __no_const device_attribute_no_const;
78808
78809 struct dev_ext_attribute {
78810 struct device_attribute attr;
78811 void *var;
78812 -};
78813 +} __do_const;
78814
78815 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
78816 char *buf);
78817 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
78818 index fd4aee2..1f28db9 100644
78819 --- a/include/linux/dma-mapping.h
78820 +++ b/include/linux/dma-mapping.h
78821 @@ -54,7 +54,7 @@ struct dma_map_ops {
78822 u64 (*get_required_mask)(struct device *dev);
78823 #endif
78824 int is_phys;
78825 -};
78826 +} __do_const;
78827
78828 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
78829
78830 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
78831 index 72cb0dd..7fe9a4b 100644
78832 --- a/include/linux/dmaengine.h
78833 +++ b/include/linux/dmaengine.h
78834 @@ -1147,9 +1147,9 @@ struct dma_pinned_list {
78835 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
78836 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
78837
78838 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
78839 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
78840 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
78841 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
78842 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
78843 struct dma_pinned_list *pinned_list, struct page *page,
78844 unsigned int offset, size_t len);
78845
78846 diff --git a/include/linux/efi.h b/include/linux/efi.h
78847 index 6c100ff..e3289b4 100644
78848 --- a/include/linux/efi.h
78849 +++ b/include/linux/efi.h
78850 @@ -1009,6 +1009,7 @@ struct efivar_operations {
78851 efi_set_variable_t *set_variable;
78852 efi_query_variable_store_t *query_variable_store;
78853 };
78854 +typedef struct efivar_operations __no_const efivar_operations_no_const;
78855
78856 struct efivars {
78857 /*
78858 diff --git a/include/linux/elf.h b/include/linux/elf.h
78859 index 67a5fa7..b817372 100644
78860 --- a/include/linux/elf.h
78861 +++ b/include/linux/elf.h
78862 @@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
78863 #define elf_note elf32_note
78864 #define elf_addr_t Elf32_Off
78865 #define Elf_Half Elf32_Half
78866 +#define elf_dyn Elf32_Dyn
78867
78868 #else
78869
78870 @@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
78871 #define elf_note elf64_note
78872 #define elf_addr_t Elf64_Off
78873 #define Elf_Half Elf64_Half
78874 +#define elf_dyn Elf64_Dyn
78875
78876 #endif
78877
78878 diff --git a/include/linux/err.h b/include/linux/err.h
78879 index a729120..6ede2c9 100644
78880 --- a/include/linux/err.h
78881 +++ b/include/linux/err.h
78882 @@ -20,12 +20,12 @@
78883
78884 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
78885
78886 -static inline void * __must_check ERR_PTR(long error)
78887 +static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
78888 {
78889 return (void *) error;
78890 }
78891
78892 -static inline long __must_check PTR_ERR(__force const void *ptr)
78893 +static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
78894 {
78895 return (long) ptr;
78896 }
78897 diff --git a/include/linux/extcon.h b/include/linux/extcon.h
78898 index f488145..3b6b04e 100644
78899 --- a/include/linux/extcon.h
78900 +++ b/include/linux/extcon.h
78901 @@ -135,7 +135,7 @@ struct extcon_dev {
78902 /* /sys/class/extcon/.../mutually_exclusive/... */
78903 struct attribute_group attr_g_muex;
78904 struct attribute **attrs_muex;
78905 - struct device_attribute *d_attrs_muex;
78906 + device_attribute_no_const *d_attrs_muex;
78907 };
78908
78909 /**
78910 diff --git a/include/linux/fb.h b/include/linux/fb.h
78911 index fe6ac95..898d41d 100644
78912 --- a/include/linux/fb.h
78913 +++ b/include/linux/fb.h
78914 @@ -304,7 +304,7 @@ struct fb_ops {
78915 /* called at KDB enter and leave time to prepare the console */
78916 int (*fb_debug_enter)(struct fb_info *info);
78917 int (*fb_debug_leave)(struct fb_info *info);
78918 -};
78919 +} __do_const;
78920
78921 #ifdef CONFIG_FB_TILEBLITTING
78922 #define FB_TILE_CURSOR_NONE 0
78923 diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
78924 index 230f87b..1fd0485 100644
78925 --- a/include/linux/fdtable.h
78926 +++ b/include/linux/fdtable.h
78927 @@ -100,7 +100,7 @@ struct files_struct *get_files_struct(struct task_struct *);
78928 void put_files_struct(struct files_struct *fs);
78929 void reset_files_struct(struct files_struct *);
78930 int unshare_files(struct files_struct **);
78931 -struct files_struct *dup_fd(struct files_struct *, int *);
78932 +struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
78933 void do_close_on_exec(struct files_struct *);
78934 int iterate_fd(struct files_struct *, unsigned,
78935 int (*)(const void *, struct file *, unsigned),
78936 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
78937 index 8293262..2b3b8bd 100644
78938 --- a/include/linux/frontswap.h
78939 +++ b/include/linux/frontswap.h
78940 @@ -11,7 +11,7 @@ struct frontswap_ops {
78941 int (*load)(unsigned, pgoff_t, struct page *);
78942 void (*invalidate_page)(unsigned, pgoff_t);
78943 void (*invalidate_area)(unsigned);
78944 -};
78945 +} __no_const;
78946
78947 extern bool frontswap_enabled;
78948 extern struct frontswap_ops *
78949 diff --git a/include/linux/fs.h b/include/linux/fs.h
78950 index 8780312..425cc22 100644
78951 --- a/include/linux/fs.h
78952 +++ b/include/linux/fs.h
78953 @@ -398,7 +398,7 @@ struct address_space {
78954 spinlock_t private_lock; /* for use by the address_space */
78955 struct list_head private_list; /* ditto */
78956 void *private_data; /* ditto */
78957 -} __attribute__((aligned(sizeof(long))));
78958 +} __attribute__((aligned(sizeof(long)))) __randomize_layout;
78959 /*
78960 * On most architectures that alignment is already the case; but
78961 * must be enforced here for CRIS, to let the least significant bit
78962 @@ -441,7 +441,7 @@ struct block_device {
78963 int bd_fsfreeze_count;
78964 /* Mutex for freeze */
78965 struct mutex bd_fsfreeze_mutex;
78966 -};
78967 +} __randomize_layout;
78968
78969 /*
78970 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
78971 @@ -585,7 +585,7 @@ struct inode {
78972 #endif
78973
78974 void *i_private; /* fs or device private pointer */
78975 -};
78976 +} __randomize_layout;
78977
78978 static inline int inode_unhashed(struct inode *inode)
78979 {
78980 @@ -778,7 +778,7 @@ struct file {
78981 struct list_head f_tfile_llink;
78982 #endif /* #ifdef CONFIG_EPOLL */
78983 struct address_space *f_mapping;
78984 -} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
78985 +} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
78986
78987 struct file_handle {
78988 __u32 handle_bytes;
78989 @@ -906,7 +906,7 @@ struct file_lock {
78990 int state; /* state of grant or error if -ve */
78991 } afs;
78992 } fl_u;
78993 -};
78994 +} __randomize_layout;
78995
78996 /* The following constant reflects the upper bound of the file/locking space */
78997 #ifndef OFFSET_MAX
78998 @@ -1255,7 +1255,7 @@ struct super_block {
78999 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
79000 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
79001 struct rcu_head rcu;
79002 -};
79003 +} __randomize_layout;
79004
79005 extern struct timespec current_fs_time(struct super_block *sb);
79006
79007 @@ -1477,7 +1477,8 @@ struct file_operations {
79008 long (*fallocate)(struct file *file, int mode, loff_t offset,
79009 loff_t len);
79010 int (*show_fdinfo)(struct seq_file *m, struct file *f);
79011 -};
79012 +} __do_const __randomize_layout;
79013 +typedef struct file_operations __no_const file_operations_no_const;
79014
79015 struct inode_operations {
79016 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
79017 @@ -2757,4 +2758,14 @@ static inline bool dir_relax(struct inode *inode)
79018 return !IS_DEADDIR(inode);
79019 }
79020
79021 +static inline bool is_sidechannel_device(const struct inode *inode)
79022 +{
79023 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
79024 + umode_t mode = inode->i_mode;
79025 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
79026 +#else
79027 + return false;
79028 +#endif
79029 +}
79030 +
79031 #endif /* _LINUX_FS_H */
79032 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
79033 index 0efc3e6..fd23610 100644
79034 --- a/include/linux/fs_struct.h
79035 +++ b/include/linux/fs_struct.h
79036 @@ -6,13 +6,13 @@
79037 #include <linux/seqlock.h>
79038
79039 struct fs_struct {
79040 - int users;
79041 + atomic_t users;
79042 spinlock_t lock;
79043 seqcount_t seq;
79044 int umask;
79045 int in_exec;
79046 struct path root, pwd;
79047 -};
79048 +} __randomize_layout;
79049
79050 extern struct kmem_cache *fs_cachep;
79051
79052 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
79053 index 7714849..a4a5c7a 100644
79054 --- a/include/linux/fscache-cache.h
79055 +++ b/include/linux/fscache-cache.h
79056 @@ -113,7 +113,7 @@ struct fscache_operation {
79057 fscache_operation_release_t release;
79058 };
79059
79060 -extern atomic_t fscache_op_debug_id;
79061 +extern atomic_unchecked_t fscache_op_debug_id;
79062 extern void fscache_op_work_func(struct work_struct *work);
79063
79064 extern void fscache_enqueue_operation(struct fscache_operation *);
79065 @@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
79066 INIT_WORK(&op->work, fscache_op_work_func);
79067 atomic_set(&op->usage, 1);
79068 op->state = FSCACHE_OP_ST_INITIALISED;
79069 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
79070 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
79071 op->processor = processor;
79072 op->release = release;
79073 INIT_LIST_HEAD(&op->pend_link);
79074 diff --git a/include/linux/fscache.h b/include/linux/fscache.h
79075 index 115bb81..e7b812b 100644
79076 --- a/include/linux/fscache.h
79077 +++ b/include/linux/fscache.h
79078 @@ -152,7 +152,7 @@ struct fscache_cookie_def {
79079 * - this is mandatory for any object that may have data
79080 */
79081 void (*now_uncached)(void *cookie_netfs_data);
79082 -};
79083 +} __do_const;
79084
79085 /*
79086 * fscache cached network filesystem type
79087 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
79088 index 1c804b0..1432c2b 100644
79089 --- a/include/linux/fsnotify.h
79090 +++ b/include/linux/fsnotify.h
79091 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
79092 struct inode *inode = file_inode(file);
79093 __u32 mask = FS_ACCESS;
79094
79095 + if (is_sidechannel_device(inode))
79096 + return;
79097 +
79098 if (S_ISDIR(inode->i_mode))
79099 mask |= FS_ISDIR;
79100
79101 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
79102 struct inode *inode = file_inode(file);
79103 __u32 mask = FS_MODIFY;
79104
79105 + if (is_sidechannel_device(inode))
79106 + return;
79107 +
79108 if (S_ISDIR(inode->i_mode))
79109 mask |= FS_ISDIR;
79110
79111 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
79112 */
79113 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
79114 {
79115 - return kstrdup(name, GFP_KERNEL);
79116 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
79117 }
79118
79119 /*
79120 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
79121 index 9f3c275..8bdff5d 100644
79122 --- a/include/linux/genhd.h
79123 +++ b/include/linux/genhd.h
79124 @@ -194,7 +194,7 @@ struct gendisk {
79125 struct kobject *slave_dir;
79126
79127 struct timer_rand_state *random;
79128 - atomic_t sync_io; /* RAID */
79129 + atomic_unchecked_t sync_io; /* RAID */
79130 struct disk_events *ev;
79131 #ifdef CONFIG_BLK_DEV_INTEGRITY
79132 struct blk_integrity *integrity;
79133 @@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
79134 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
79135
79136 /* drivers/char/random.c */
79137 -extern void add_disk_randomness(struct gendisk *disk);
79138 +extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
79139 extern void rand_initialize_disk(struct gendisk *disk);
79140
79141 static inline sector_t get_start_sect(struct block_device *bdev)
79142 diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
79143 index c0894dd..2fbf10c 100644
79144 --- a/include/linux/genl_magic_func.h
79145 +++ b/include/linux/genl_magic_func.h
79146 @@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
79147 },
79148
79149 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
79150 -static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
79151 +static struct genl_ops ZZZ_genl_ops[] = {
79152 #include GENL_MAGIC_INCLUDE_FILE
79153 };
79154
79155 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
79156 index 39b81dc..819dc51 100644
79157 --- a/include/linux/gfp.h
79158 +++ b/include/linux/gfp.h
79159 @@ -36,6 +36,13 @@ struct vm_area_struct;
79160 #define ___GFP_NO_KSWAPD 0x400000u
79161 #define ___GFP_OTHER_NODE 0x800000u
79162 #define ___GFP_WRITE 0x1000000u
79163 +
79164 +#ifdef CONFIG_PAX_USERCOPY_SLABS
79165 +#define ___GFP_USERCOPY 0x2000000u
79166 +#else
79167 +#define ___GFP_USERCOPY 0
79168 +#endif
79169 +
79170 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
79171
79172 /*
79173 @@ -93,6 +100,7 @@ struct vm_area_struct;
79174 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
79175 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
79176 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
79177 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
79178
79179 /*
79180 * This may seem redundant, but it's a way of annotating false positives vs.
79181 @@ -100,7 +108,7 @@ struct vm_area_struct;
79182 */
79183 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
79184
79185 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
79186 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
79187 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
79188
79189 /* This equals 0, but use constants in case they ever change */
79190 @@ -158,6 +166,8 @@ struct vm_area_struct;
79191 /* 4GB DMA on some platforms */
79192 #define GFP_DMA32 __GFP_DMA32
79193
79194 +#define GFP_USERCOPY __GFP_USERCOPY
79195 +
79196 /* Convert GFP flags to their corresponding migrate type */
79197 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
79198 {
79199 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
79200 new file mode 100644
79201 index 0000000..edb2cb6
79202 --- /dev/null
79203 +++ b/include/linux/gracl.h
79204 @@ -0,0 +1,340 @@
79205 +#ifndef GR_ACL_H
79206 +#define GR_ACL_H
79207 +
79208 +#include <linux/grdefs.h>
79209 +#include <linux/resource.h>
79210 +#include <linux/capability.h>
79211 +#include <linux/dcache.h>
79212 +#include <asm/resource.h>
79213 +
79214 +/* Major status information */
79215 +
79216 +#define GR_VERSION "grsecurity 3.0"
79217 +#define GRSECURITY_VERSION 0x3000
79218 +
79219 +enum {
79220 + GR_SHUTDOWN = 0,
79221 + GR_ENABLE = 1,
79222 + GR_SPROLE = 2,
79223 + GR_OLDRELOAD = 3,
79224 + GR_SEGVMOD = 4,
79225 + GR_STATUS = 5,
79226 + GR_UNSPROLE = 6,
79227 + GR_PASSSET = 7,
79228 + GR_SPROLEPAM = 8,
79229 + GR_RELOAD = 9,
79230 +};
79231 +
79232 +/* Password setup definitions
79233 + * kernel/grhash.c */
79234 +enum {
79235 + GR_PW_LEN = 128,
79236 + GR_SALT_LEN = 16,
79237 + GR_SHA_LEN = 32,
79238 +};
79239 +
79240 +enum {
79241 + GR_SPROLE_LEN = 64,
79242 +};
79243 +
79244 +enum {
79245 + GR_NO_GLOB = 0,
79246 + GR_REG_GLOB,
79247 + GR_CREATE_GLOB
79248 +};
79249 +
79250 +#define GR_NLIMITS 32
79251 +
79252 +/* Begin Data Structures */
79253 +
79254 +struct sprole_pw {
79255 + unsigned char *rolename;
79256 + unsigned char salt[GR_SALT_LEN];
79257 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
79258 +};
79259 +
79260 +struct name_entry {
79261 + __u32 key;
79262 + ino_t inode;
79263 + dev_t device;
79264 + char *name;
79265 + __u16 len;
79266 + __u8 deleted;
79267 + struct name_entry *prev;
79268 + struct name_entry *next;
79269 +};
79270 +
79271 +struct inodev_entry {
79272 + struct name_entry *nentry;
79273 + struct inodev_entry *prev;
79274 + struct inodev_entry *next;
79275 +};
79276 +
79277 +struct acl_role_db {
79278 + struct acl_role_label **r_hash;
79279 + __u32 r_size;
79280 +};
79281 +
79282 +struct inodev_db {
79283 + struct inodev_entry **i_hash;
79284 + __u32 i_size;
79285 +};
79286 +
79287 +struct name_db {
79288 + struct name_entry **n_hash;
79289 + __u32 n_size;
79290 +};
79291 +
79292 +struct crash_uid {
79293 + uid_t uid;
79294 + unsigned long expires;
79295 +};
79296 +
79297 +struct gr_hash_struct {
79298 + void **table;
79299 + void **nametable;
79300 + void *first;
79301 + __u32 table_size;
79302 + __u32 used_size;
79303 + int type;
79304 +};
79305 +
79306 +/* Userspace Grsecurity ACL data structures */
79307 +
79308 +struct acl_subject_label {
79309 + char *filename;
79310 + ino_t inode;
79311 + dev_t device;
79312 + __u32 mode;
79313 + kernel_cap_t cap_mask;
79314 + kernel_cap_t cap_lower;
79315 + kernel_cap_t cap_invert_audit;
79316 +
79317 + struct rlimit res[GR_NLIMITS];
79318 + __u32 resmask;
79319 +
79320 + __u8 user_trans_type;
79321 + __u8 group_trans_type;
79322 + uid_t *user_transitions;
79323 + gid_t *group_transitions;
79324 + __u16 user_trans_num;
79325 + __u16 group_trans_num;
79326 +
79327 + __u32 sock_families[2];
79328 + __u32 ip_proto[8];
79329 + __u32 ip_type;
79330 + struct acl_ip_label **ips;
79331 + __u32 ip_num;
79332 + __u32 inaddr_any_override;
79333 +
79334 + __u32 crashes;
79335 + unsigned long expires;
79336 +
79337 + struct acl_subject_label *parent_subject;
79338 + struct gr_hash_struct *hash;
79339 + struct acl_subject_label *prev;
79340 + struct acl_subject_label *next;
79341 +
79342 + struct acl_object_label **obj_hash;
79343 + __u32 obj_hash_size;
79344 + __u16 pax_flags;
79345 +};
79346 +
79347 +struct role_allowed_ip {
79348 + __u32 addr;
79349 + __u32 netmask;
79350 +
79351 + struct role_allowed_ip *prev;
79352 + struct role_allowed_ip *next;
79353 +};
79354 +
79355 +struct role_transition {
79356 + char *rolename;
79357 +
79358 + struct role_transition *prev;
79359 + struct role_transition *next;
79360 +};
79361 +
79362 +struct acl_role_label {
79363 + char *rolename;
79364 + uid_t uidgid;
79365 + __u16 roletype;
79366 +
79367 + __u16 auth_attempts;
79368 + unsigned long expires;
79369 +
79370 + struct acl_subject_label *root_label;
79371 + struct gr_hash_struct *hash;
79372 +
79373 + struct acl_role_label *prev;
79374 + struct acl_role_label *next;
79375 +
79376 + struct role_transition *transitions;
79377 + struct role_allowed_ip *allowed_ips;
79378 + uid_t *domain_children;
79379 + __u16 domain_child_num;
79380 +
79381 + umode_t umask;
79382 +
79383 + struct acl_subject_label **subj_hash;
79384 + __u32 subj_hash_size;
79385 +};
79386 +
79387 +struct user_acl_role_db {
79388 + struct acl_role_label **r_table;
79389 + __u32 num_pointers; /* Number of allocations to track */
79390 + __u32 num_roles; /* Number of roles */
79391 + __u32 num_domain_children; /* Number of domain children */
79392 + __u32 num_subjects; /* Number of subjects */
79393 + __u32 num_objects; /* Number of objects */
79394 +};
79395 +
79396 +struct acl_object_label {
79397 + char *filename;
79398 + ino_t inode;
79399 + dev_t device;
79400 + __u32 mode;
79401 +
79402 + struct acl_subject_label *nested;
79403 + struct acl_object_label *globbed;
79404 +
79405 + /* next two structures not used */
79406 +
79407 + struct acl_object_label *prev;
79408 + struct acl_object_label *next;
79409 +};
79410 +
79411 +struct acl_ip_label {
79412 + char *iface;
79413 + __u32 addr;
79414 + __u32 netmask;
79415 + __u16 low, high;
79416 + __u8 mode;
79417 + __u32 type;
79418 + __u32 proto[8];
79419 +
79420 + /* next two structures not used */
79421 +
79422 + struct acl_ip_label *prev;
79423 + struct acl_ip_label *next;
79424 +};
79425 +
79426 +struct gr_arg {
79427 + struct user_acl_role_db role_db;
79428 + unsigned char pw[GR_PW_LEN];
79429 + unsigned char salt[GR_SALT_LEN];
79430 + unsigned char sum[GR_SHA_LEN];
79431 + unsigned char sp_role[GR_SPROLE_LEN];
79432 + struct sprole_pw *sprole_pws;
79433 + dev_t segv_device;
79434 + ino_t segv_inode;
79435 + uid_t segv_uid;
79436 + __u16 num_sprole_pws;
79437 + __u16 mode;
79438 +};
79439 +
79440 +struct gr_arg_wrapper {
79441 + struct gr_arg *arg;
79442 + __u32 version;
79443 + __u32 size;
79444 +};
79445 +
79446 +struct subject_map {
79447 + struct acl_subject_label *user;
79448 + struct acl_subject_label *kernel;
79449 + struct subject_map *prev;
79450 + struct subject_map *next;
79451 +};
79452 +
79453 +struct acl_subj_map_db {
79454 + struct subject_map **s_hash;
79455 + __u32 s_size;
79456 +};
79457 +
79458 +struct gr_policy_state {
79459 + struct sprole_pw **acl_special_roles;
79460 + __u16 num_sprole_pws;
79461 + struct acl_role_label *kernel_role;
79462 + struct acl_role_label *role_list;
79463 + struct acl_role_label *default_role;
79464 + struct acl_role_db acl_role_set;
79465 + struct acl_subj_map_db subj_map_set;
79466 + struct name_db name_set;
79467 + struct inodev_db inodev_set;
79468 +};
79469 +
79470 +struct gr_alloc_state {
79471 + unsigned long alloc_stack_next;
79472 + unsigned long alloc_stack_size;
79473 + void **alloc_stack;
79474 +};
79475 +
79476 +struct gr_reload_state {
79477 + struct gr_policy_state oldpolicy;
79478 + struct gr_alloc_state oldalloc;
79479 + struct gr_policy_state newpolicy;
79480 + struct gr_alloc_state newalloc;
79481 + struct gr_policy_state *oldpolicy_ptr;
79482 + struct gr_alloc_state *oldalloc_ptr;
79483 + unsigned char oldmode;
79484 +};
79485 +
79486 +/* End Data Structures Section */
79487 +
79488 +/* Hash functions generated by empirical testing by Brad Spengler
79489 + Makes good use of the low bits of the inode. Generally 0-1 times
79490 + in loop for successful match. 0-3 for unsuccessful match.
79491 + Shift/add algorithm with modulus of table size and an XOR*/
79492 +
79493 +static __inline__ unsigned int
79494 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
79495 +{
79496 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
79497 +}
79498 +
79499 + static __inline__ unsigned int
79500 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
79501 +{
79502 + return ((const unsigned long)userp % sz);
79503 +}
79504 +
79505 +static __inline__ unsigned int
79506 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
79507 +{
79508 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
79509 +}
79510 +
79511 +static __inline__ unsigned int
79512 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
79513 +{
79514 + return full_name_hash((const unsigned char *)name, len) % sz;
79515 +}
79516 +
79517 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
79518 + subj = NULL; \
79519 + iter = 0; \
79520 + while (iter < role->subj_hash_size) { \
79521 + if (subj == NULL) \
79522 + subj = role->subj_hash[iter]; \
79523 + if (subj == NULL) { \
79524 + iter++; \
79525 + continue; \
79526 + }
79527 +
79528 +#define FOR_EACH_SUBJECT_END(subj,iter) \
79529 + subj = subj->next; \
79530 + if (subj == NULL) \
79531 + iter++; \
79532 + }
79533 +
79534 +
79535 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
79536 + subj = role->hash->first; \
79537 + while (subj != NULL) {
79538 +
79539 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
79540 + subj = subj->next; \
79541 + }
79542 +
79543 +#endif
79544 +
79545 diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
79546 new file mode 100644
79547 index 0000000..33ebd1f
79548 --- /dev/null
79549 +++ b/include/linux/gracl_compat.h
79550 @@ -0,0 +1,156 @@
79551 +#ifndef GR_ACL_COMPAT_H
79552 +#define GR_ACL_COMPAT_H
79553 +
79554 +#include <linux/resource.h>
79555 +#include <asm/resource.h>
79556 +
79557 +struct sprole_pw_compat {
79558 + compat_uptr_t rolename;
79559 + unsigned char salt[GR_SALT_LEN];
79560 + unsigned char sum[GR_SHA_LEN];
79561 +};
79562 +
79563 +struct gr_hash_struct_compat {
79564 + compat_uptr_t table;
79565 + compat_uptr_t nametable;
79566 + compat_uptr_t first;
79567 + __u32 table_size;
79568 + __u32 used_size;
79569 + int type;
79570 +};
79571 +
79572 +struct acl_subject_label_compat {
79573 + compat_uptr_t filename;
79574 + compat_ino_t inode;
79575 + __u32 device;
79576 + __u32 mode;
79577 + kernel_cap_t cap_mask;
79578 + kernel_cap_t cap_lower;
79579 + kernel_cap_t cap_invert_audit;
79580 +
79581 + struct compat_rlimit res[GR_NLIMITS];
79582 + __u32 resmask;
79583 +
79584 + __u8 user_trans_type;
79585 + __u8 group_trans_type;
79586 + compat_uptr_t user_transitions;
79587 + compat_uptr_t group_transitions;
79588 + __u16 user_trans_num;
79589 + __u16 group_trans_num;
79590 +
79591 + __u32 sock_families[2];
79592 + __u32 ip_proto[8];
79593 + __u32 ip_type;
79594 + compat_uptr_t ips;
79595 + __u32 ip_num;
79596 + __u32 inaddr_any_override;
79597 +
79598 + __u32 crashes;
79599 + compat_ulong_t expires;
79600 +
79601 + compat_uptr_t parent_subject;
79602 + compat_uptr_t hash;
79603 + compat_uptr_t prev;
79604 + compat_uptr_t next;
79605 +
79606 + compat_uptr_t obj_hash;
79607 + __u32 obj_hash_size;
79608 + __u16 pax_flags;
79609 +};
79610 +
79611 +struct role_allowed_ip_compat {
79612 + __u32 addr;
79613 + __u32 netmask;
79614 +
79615 + compat_uptr_t prev;
79616 + compat_uptr_t next;
79617 +};
79618 +
79619 +struct role_transition_compat {
79620 + compat_uptr_t rolename;
79621 +
79622 + compat_uptr_t prev;
79623 + compat_uptr_t next;
79624 +};
79625 +
79626 +struct acl_role_label_compat {
79627 + compat_uptr_t rolename;
79628 + uid_t uidgid;
79629 + __u16 roletype;
79630 +
79631 + __u16 auth_attempts;
79632 + compat_ulong_t expires;
79633 +
79634 + compat_uptr_t root_label;
79635 + compat_uptr_t hash;
79636 +
79637 + compat_uptr_t prev;
79638 + compat_uptr_t next;
79639 +
79640 + compat_uptr_t transitions;
79641 + compat_uptr_t allowed_ips;
79642 + compat_uptr_t domain_children;
79643 + __u16 domain_child_num;
79644 +
79645 + umode_t umask;
79646 +
79647 + compat_uptr_t subj_hash;
79648 + __u32 subj_hash_size;
79649 +};
79650 +
79651 +struct user_acl_role_db_compat {
79652 + compat_uptr_t r_table;
79653 + __u32 num_pointers;
79654 + __u32 num_roles;
79655 + __u32 num_domain_children;
79656 + __u32 num_subjects;
79657 + __u32 num_objects;
79658 +};
79659 +
79660 +struct acl_object_label_compat {
79661 + compat_uptr_t filename;
79662 + compat_ino_t inode;
79663 + __u32 device;
79664 + __u32 mode;
79665 +
79666 + compat_uptr_t nested;
79667 + compat_uptr_t globbed;
79668 +
79669 + compat_uptr_t prev;
79670 + compat_uptr_t next;
79671 +};
79672 +
79673 +struct acl_ip_label_compat {
79674 + compat_uptr_t iface;
79675 + __u32 addr;
79676 + __u32 netmask;
79677 + __u16 low, high;
79678 + __u8 mode;
79679 + __u32 type;
79680 + __u32 proto[8];
79681 +
79682 + compat_uptr_t prev;
79683 + compat_uptr_t next;
79684 +};
79685 +
79686 +struct gr_arg_compat {
79687 + struct user_acl_role_db_compat role_db;
79688 + unsigned char pw[GR_PW_LEN];
79689 + unsigned char salt[GR_SALT_LEN];
79690 + unsigned char sum[GR_SHA_LEN];
79691 + unsigned char sp_role[GR_SPROLE_LEN];
79692 + compat_uptr_t sprole_pws;
79693 + __u32 segv_device;
79694 + compat_ino_t segv_inode;
79695 + uid_t segv_uid;
79696 + __u16 num_sprole_pws;
79697 + __u16 mode;
79698 +};
79699 +
79700 +struct gr_arg_wrapper_compat {
79701 + compat_uptr_t arg;
79702 + __u32 version;
79703 + __u32 size;
79704 +};
79705 +
79706 +#endif
79707 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
79708 new file mode 100644
79709 index 0000000..323ecf2
79710 --- /dev/null
79711 +++ b/include/linux/gralloc.h
79712 @@ -0,0 +1,9 @@
79713 +#ifndef __GRALLOC_H
79714 +#define __GRALLOC_H
79715 +
79716 +void acl_free_all(void);
79717 +int acl_alloc_stack_init(unsigned long size);
79718 +void *acl_alloc(unsigned long len);
79719 +void *acl_alloc_num(unsigned long num, unsigned long len);
79720 +
79721 +#endif
79722 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
79723 new file mode 100644
79724 index 0000000..be66033
79725 --- /dev/null
79726 +++ b/include/linux/grdefs.h
79727 @@ -0,0 +1,140 @@
79728 +#ifndef GRDEFS_H
79729 +#define GRDEFS_H
79730 +
79731 +/* Begin grsecurity status declarations */
79732 +
79733 +enum {
79734 + GR_READY = 0x01,
79735 + GR_STATUS_INIT = 0x00 // disabled state
79736 +};
79737 +
79738 +/* Begin ACL declarations */
79739 +
79740 +/* Role flags */
79741 +
79742 +enum {
79743 + GR_ROLE_USER = 0x0001,
79744 + GR_ROLE_GROUP = 0x0002,
79745 + GR_ROLE_DEFAULT = 0x0004,
79746 + GR_ROLE_SPECIAL = 0x0008,
79747 + GR_ROLE_AUTH = 0x0010,
79748 + GR_ROLE_NOPW = 0x0020,
79749 + GR_ROLE_GOD = 0x0040,
79750 + GR_ROLE_LEARN = 0x0080,
79751 + GR_ROLE_TPE = 0x0100,
79752 + GR_ROLE_DOMAIN = 0x0200,
79753 + GR_ROLE_PAM = 0x0400,
79754 + GR_ROLE_PERSIST = 0x0800
79755 +};
79756 +
79757 +/* ACL Subject and Object mode flags */
79758 +enum {
79759 + GR_DELETED = 0x80000000
79760 +};
79761 +
79762 +/* ACL Object-only mode flags */
79763 +enum {
79764 + GR_READ = 0x00000001,
79765 + GR_APPEND = 0x00000002,
79766 + GR_WRITE = 0x00000004,
79767 + GR_EXEC = 0x00000008,
79768 + GR_FIND = 0x00000010,
79769 + GR_INHERIT = 0x00000020,
79770 + GR_SETID = 0x00000040,
79771 + GR_CREATE = 0x00000080,
79772 + GR_DELETE = 0x00000100,
79773 + GR_LINK = 0x00000200,
79774 + GR_AUDIT_READ = 0x00000400,
79775 + GR_AUDIT_APPEND = 0x00000800,
79776 + GR_AUDIT_WRITE = 0x00001000,
79777 + GR_AUDIT_EXEC = 0x00002000,
79778 + GR_AUDIT_FIND = 0x00004000,
79779 + GR_AUDIT_INHERIT= 0x00008000,
79780 + GR_AUDIT_SETID = 0x00010000,
79781 + GR_AUDIT_CREATE = 0x00020000,
79782 + GR_AUDIT_DELETE = 0x00040000,
79783 + GR_AUDIT_LINK = 0x00080000,
79784 + GR_PTRACERD = 0x00100000,
79785 + GR_NOPTRACE = 0x00200000,
79786 + GR_SUPPRESS = 0x00400000,
79787 + GR_NOLEARN = 0x00800000,
79788 + GR_INIT_TRANSFER= 0x01000000
79789 +};
79790 +
79791 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
79792 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
79793 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
79794 +
79795 +/* ACL subject-only mode flags */
79796 +enum {
79797 + GR_KILL = 0x00000001,
79798 + GR_VIEW = 0x00000002,
79799 + GR_PROTECTED = 0x00000004,
79800 + GR_LEARN = 0x00000008,
79801 + GR_OVERRIDE = 0x00000010,
79802 + /* just a placeholder, this mode is only used in userspace */
79803 + GR_DUMMY = 0x00000020,
79804 + GR_PROTSHM = 0x00000040,
79805 + GR_KILLPROC = 0x00000080,
79806 + GR_KILLIPPROC = 0x00000100,
79807 + /* just a placeholder, this mode is only used in userspace */
79808 + GR_NOTROJAN = 0x00000200,
79809 + GR_PROTPROCFD = 0x00000400,
79810 + GR_PROCACCT = 0x00000800,
79811 + GR_RELAXPTRACE = 0x00001000,
79812 + //GR_NESTED = 0x00002000,
79813 + GR_INHERITLEARN = 0x00004000,
79814 + GR_PROCFIND = 0x00008000,
79815 + GR_POVERRIDE = 0x00010000,
79816 + GR_KERNELAUTH = 0x00020000,
79817 + GR_ATSECURE = 0x00040000,
79818 + GR_SHMEXEC = 0x00080000
79819 +};
79820 +
79821 +enum {
79822 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
79823 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
79824 + GR_PAX_ENABLE_MPROTECT = 0x0004,
79825 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
79826 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
79827 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
79828 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
79829 + GR_PAX_DISABLE_MPROTECT = 0x0400,
79830 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
79831 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
79832 +};
79833 +
79834 +enum {
79835 + GR_ID_USER = 0x01,
79836 + GR_ID_GROUP = 0x02,
79837 +};
79838 +
79839 +enum {
79840 + GR_ID_ALLOW = 0x01,
79841 + GR_ID_DENY = 0x02,
79842 +};
79843 +
79844 +#define GR_CRASH_RES 31
79845 +#define GR_UIDTABLE_MAX 500
79846 +
79847 +/* begin resource learning section */
79848 +enum {
79849 + GR_RLIM_CPU_BUMP = 60,
79850 + GR_RLIM_FSIZE_BUMP = 50000,
79851 + GR_RLIM_DATA_BUMP = 10000,
79852 + GR_RLIM_STACK_BUMP = 1000,
79853 + GR_RLIM_CORE_BUMP = 10000,
79854 + GR_RLIM_RSS_BUMP = 500000,
79855 + GR_RLIM_NPROC_BUMP = 1,
79856 + GR_RLIM_NOFILE_BUMP = 5,
79857 + GR_RLIM_MEMLOCK_BUMP = 50000,
79858 + GR_RLIM_AS_BUMP = 500000,
79859 + GR_RLIM_LOCKS_BUMP = 2,
79860 + GR_RLIM_SIGPENDING_BUMP = 5,
79861 + GR_RLIM_MSGQUEUE_BUMP = 10000,
79862 + GR_RLIM_NICE_BUMP = 1,
79863 + GR_RLIM_RTPRIO_BUMP = 1,
79864 + GR_RLIM_RTTIME_BUMP = 1000000
79865 +};
79866 +
79867 +#endif
79868 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
79869 new file mode 100644
79870 index 0000000..d25522e
79871 --- /dev/null
79872 +++ b/include/linux/grinternal.h
79873 @@ -0,0 +1,229 @@
79874 +#ifndef __GRINTERNAL_H
79875 +#define __GRINTERNAL_H
79876 +
79877 +#ifdef CONFIG_GRKERNSEC
79878 +
79879 +#include <linux/fs.h>
79880 +#include <linux/mnt_namespace.h>
79881 +#include <linux/nsproxy.h>
79882 +#include <linux/gracl.h>
79883 +#include <linux/grdefs.h>
79884 +#include <linux/grmsg.h>
79885 +
79886 +void gr_add_learn_entry(const char *fmt, ...)
79887 + __attribute__ ((format (printf, 1, 2)));
79888 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
79889 + const struct vfsmount *mnt);
79890 +__u32 gr_check_create(const struct dentry *new_dentry,
79891 + const struct dentry *parent,
79892 + const struct vfsmount *mnt, const __u32 mode);
79893 +int gr_check_protected_task(const struct task_struct *task);
79894 +__u32 to_gr_audit(const __u32 reqmode);
79895 +int gr_set_acls(const int type);
79896 +int gr_acl_is_enabled(void);
79897 +char gr_roletype_to_char(void);
79898 +
79899 +void gr_handle_alertkill(struct task_struct *task);
79900 +char *gr_to_filename(const struct dentry *dentry,
79901 + const struct vfsmount *mnt);
79902 +char *gr_to_filename1(const struct dentry *dentry,
79903 + const struct vfsmount *mnt);
79904 +char *gr_to_filename2(const struct dentry *dentry,
79905 + const struct vfsmount *mnt);
79906 +char *gr_to_filename3(const struct dentry *dentry,
79907 + const struct vfsmount *mnt);
79908 +
79909 +extern int grsec_enable_ptrace_readexec;
79910 +extern int grsec_enable_harden_ptrace;
79911 +extern int grsec_enable_link;
79912 +extern int grsec_enable_fifo;
79913 +extern int grsec_enable_execve;
79914 +extern int grsec_enable_shm;
79915 +extern int grsec_enable_execlog;
79916 +extern int grsec_enable_signal;
79917 +extern int grsec_enable_audit_ptrace;
79918 +extern int grsec_enable_forkfail;
79919 +extern int grsec_enable_time;
79920 +extern int grsec_enable_rofs;
79921 +extern int grsec_deny_new_usb;
79922 +extern int grsec_enable_chroot_shmat;
79923 +extern int grsec_enable_chroot_mount;
79924 +extern int grsec_enable_chroot_double;
79925 +extern int grsec_enable_chroot_pivot;
79926 +extern int grsec_enable_chroot_chdir;
79927 +extern int grsec_enable_chroot_chmod;
79928 +extern int grsec_enable_chroot_mknod;
79929 +extern int grsec_enable_chroot_fchdir;
79930 +extern int grsec_enable_chroot_nice;
79931 +extern int grsec_enable_chroot_execlog;
79932 +extern int grsec_enable_chroot_caps;
79933 +extern int grsec_enable_chroot_sysctl;
79934 +extern int grsec_enable_chroot_unix;
79935 +extern int grsec_enable_symlinkown;
79936 +extern kgid_t grsec_symlinkown_gid;
79937 +extern int grsec_enable_tpe;
79938 +extern kgid_t grsec_tpe_gid;
79939 +extern int grsec_enable_tpe_all;
79940 +extern int grsec_enable_tpe_invert;
79941 +extern int grsec_enable_socket_all;
79942 +extern kgid_t grsec_socket_all_gid;
79943 +extern int grsec_enable_socket_client;
79944 +extern kgid_t grsec_socket_client_gid;
79945 +extern int grsec_enable_socket_server;
79946 +extern kgid_t grsec_socket_server_gid;
79947 +extern kgid_t grsec_audit_gid;
79948 +extern int grsec_enable_group;
79949 +extern int grsec_enable_log_rwxmaps;
79950 +extern int grsec_enable_mount;
79951 +extern int grsec_enable_chdir;
79952 +extern int grsec_resource_logging;
79953 +extern int grsec_enable_blackhole;
79954 +extern int grsec_lastack_retries;
79955 +extern int grsec_enable_brute;
79956 +extern int grsec_enable_harden_ipc;
79957 +extern int grsec_lock;
79958 +
79959 +extern spinlock_t grsec_alert_lock;
79960 +extern unsigned long grsec_alert_wtime;
79961 +extern unsigned long grsec_alert_fyet;
79962 +
79963 +extern spinlock_t grsec_audit_lock;
79964 +
79965 +extern rwlock_t grsec_exec_file_lock;
79966 +
79967 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
79968 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
79969 + (tsk)->exec_file->f_path.mnt) : "/")
79970 +
79971 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
79972 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
79973 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
79974 +
79975 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
79976 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
79977 + (tsk)->exec_file->f_path.mnt) : "/")
79978 +
79979 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
79980 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
79981 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
79982 +
79983 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
79984 +
79985 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
79986 +
79987 +static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
79988 +{
79989 + if (file1 && file2) {
79990 + const struct inode *inode1 = file1->f_path.dentry->d_inode;
79991 + const struct inode *inode2 = file2->f_path.dentry->d_inode;
79992 + if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
79993 + return true;
79994 + }
79995 +
79996 + return false;
79997 +}
79998 +
79999 +#define GR_CHROOT_CAPS {{ \
80000 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
80001 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
80002 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
80003 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
80004 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
80005 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
80006 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
80007 +
80008 +#define security_learn(normal_msg,args...) \
80009 +({ \
80010 + read_lock(&grsec_exec_file_lock); \
80011 + gr_add_learn_entry(normal_msg "\n", ## args); \
80012 + read_unlock(&grsec_exec_file_lock); \
80013 +})
80014 +
80015 +enum {
80016 + GR_DO_AUDIT,
80017 + GR_DONT_AUDIT,
80018 + /* used for non-audit messages that we shouldn't kill the task on */
80019 + GR_DONT_AUDIT_GOOD
80020 +};
80021 +
80022 +enum {
80023 + GR_TTYSNIFF,
80024 + GR_RBAC,
80025 + GR_RBAC_STR,
80026 + GR_STR_RBAC,
80027 + GR_RBAC_MODE2,
80028 + GR_RBAC_MODE3,
80029 + GR_FILENAME,
80030 + GR_SYSCTL_HIDDEN,
80031 + GR_NOARGS,
80032 + GR_ONE_INT,
80033 + GR_ONE_INT_TWO_STR,
80034 + GR_ONE_STR,
80035 + GR_STR_INT,
80036 + GR_TWO_STR_INT,
80037 + GR_TWO_INT,
80038 + GR_TWO_U64,
80039 + GR_THREE_INT,
80040 + GR_FIVE_INT_TWO_STR,
80041 + GR_TWO_STR,
80042 + GR_THREE_STR,
80043 + GR_FOUR_STR,
80044 + GR_STR_FILENAME,
80045 + GR_FILENAME_STR,
80046 + GR_FILENAME_TWO_INT,
80047 + GR_FILENAME_TWO_INT_STR,
80048 + GR_TEXTREL,
80049 + GR_PTRACE,
80050 + GR_RESOURCE,
80051 + GR_CAP,
80052 + GR_SIG,
80053 + GR_SIG2,
80054 + GR_CRASH1,
80055 + GR_CRASH2,
80056 + GR_PSACCT,
80057 + GR_RWXMAP,
80058 + GR_RWXMAPVMA
80059 +};
80060 +
80061 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
80062 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
80063 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
80064 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
80065 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
80066 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
80067 +#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)
80068 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
80069 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
80070 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
80071 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
80072 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
80073 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
80074 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
80075 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
80076 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
80077 +#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)
80078 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
80079 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
80080 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
80081 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
80082 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
80083 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
80084 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
80085 +#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)
80086 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
80087 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
80088 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
80089 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
80090 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
80091 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
80092 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
80093 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
80094 +#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)
80095 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
80096 +#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
80097 +
80098 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
80099 +
80100 +#endif
80101 +
80102 +#endif
80103 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
80104 new file mode 100644
80105 index 0000000..b02ba9d
80106 --- /dev/null
80107 +++ b/include/linux/grmsg.h
80108 @@ -0,0 +1,117 @@
80109 +#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"
80110 +#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"
80111 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
80112 +#define GR_STOPMOD_MSG "denied modification of module state by "
80113 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
80114 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
80115 +#define GR_IOPERM_MSG "denied use of ioperm() by "
80116 +#define GR_IOPL_MSG "denied use of iopl() by "
80117 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
80118 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
80119 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
80120 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
80121 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
80122 +#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"
80123 +#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"
80124 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
80125 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
80126 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
80127 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
80128 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
80129 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
80130 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
80131 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
80132 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
80133 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
80134 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
80135 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
80136 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
80137 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
80138 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
80139 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
80140 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
80141 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
80142 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
80143 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
80144 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
80145 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
80146 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
80147 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
80148 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
80149 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
80150 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
80151 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
80152 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
80153 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
80154 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
80155 +#define GR_CHROOT_FHANDLE_MSG "denied use of file handles inside chroot by "
80156 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
80157 +#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
80158 +#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
80159 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
80160 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
80161 +#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"
80162 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
80163 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
80164 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
80165 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
80166 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
80167 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
80168 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
80169 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
80170 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
80171 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
80172 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
80173 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
80174 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
80175 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
80176 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
80177 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
80178 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
80179 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
80180 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
80181 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
80182 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
80183 +#define GR_NICE_CHROOT_MSG "denied priority change by "
80184 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
80185 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
80186 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
80187 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
80188 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
80189 +#define GR_TIME_MSG "time set by "
80190 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
80191 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
80192 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
80193 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
80194 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
80195 +#define GR_BIND_MSG "denied bind() by "
80196 +#define GR_CONNECT_MSG "denied connect() by "
80197 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
80198 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
80199 +#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"
80200 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
80201 +#define GR_CAP_ACL_MSG "use of %s denied for "
80202 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
80203 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
80204 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
80205 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
80206 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
80207 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
80208 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
80209 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
80210 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
80211 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
80212 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
80213 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
80214 +#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
80215 +#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
80216 +#define GR_VM86_MSG "denied use of vm86 by "
80217 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
80218 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
80219 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
80220 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
80221 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
80222 +#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 "
80223 +#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 "
80224 +#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
80225 +#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
80226 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
80227 new file mode 100644
80228 index 0000000..e6d120f
80229 --- /dev/null
80230 +++ b/include/linux/grsecurity.h
80231 @@ -0,0 +1,252 @@
80232 +#ifndef GR_SECURITY_H
80233 +#define GR_SECURITY_H
80234 +#include <linux/fs.h>
80235 +#include <linux/fs_struct.h>
80236 +#include <linux/binfmts.h>
80237 +#include <linux/gracl.h>
80238 +
80239 +/* notify of brain-dead configs */
80240 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
80241 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
80242 +#endif
80243 +#if defined(CONFIG_GRKERNSEC_PROC) && !defined(CONFIG_GRKERNSEC_PROC_USER) && !defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
80244 +#error "CONFIG_GRKERNSEC_PROC enabled, but neither CONFIG_GRKERNSEC_PROC_USER nor CONFIG_GRKERNSEC_PROC_USERGROUP enabled"
80245 +#endif
80246 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
80247 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
80248 +#endif
80249 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
80250 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
80251 +#endif
80252 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
80253 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
80254 +#endif
80255 +
80256 +int gr_handle_new_usb(void);
80257 +
80258 +void gr_handle_brute_attach(int dumpable);
80259 +void gr_handle_brute_check(void);
80260 +void gr_handle_kernel_exploit(void);
80261 +
80262 +char gr_roletype_to_char(void);
80263 +
80264 +int gr_proc_is_restricted(void);
80265 +
80266 +int gr_acl_enable_at_secure(void);
80267 +
80268 +int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
80269 +int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
80270 +
80271 +void gr_del_task_from_ip_table(struct task_struct *p);
80272 +
80273 +int gr_pid_is_chrooted(struct task_struct *p);
80274 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
80275 +int gr_handle_chroot_nice(void);
80276 +int gr_handle_chroot_sysctl(const int op);
80277 +int gr_handle_chroot_setpriority(struct task_struct *p,
80278 + const int niceval);
80279 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
80280 +int gr_chroot_fhandle(void);
80281 +int gr_handle_chroot_chroot(const struct dentry *dentry,
80282 + const struct vfsmount *mnt);
80283 +void gr_handle_chroot_chdir(const struct path *path);
80284 +int gr_handle_chroot_chmod(const struct dentry *dentry,
80285 + const struct vfsmount *mnt, const int mode);
80286 +int gr_handle_chroot_mknod(const struct dentry *dentry,
80287 + const struct vfsmount *mnt, const int mode);
80288 +int gr_handle_chroot_mount(const struct dentry *dentry,
80289 + const struct vfsmount *mnt,
80290 + const char *dev_name);
80291 +int gr_handle_chroot_pivot(void);
80292 +int gr_handle_chroot_unix(const pid_t pid);
80293 +
80294 +int gr_handle_rawio(const struct inode *inode);
80295 +
80296 +void gr_handle_ioperm(void);
80297 +void gr_handle_iopl(void);
80298 +void gr_handle_msr_write(void);
80299 +
80300 +umode_t gr_acl_umask(void);
80301 +
80302 +int gr_tpe_allow(const struct file *file);
80303 +
80304 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
80305 +void gr_clear_chroot_entries(struct task_struct *task);
80306 +
80307 +void gr_log_forkfail(const int retval);
80308 +void gr_log_timechange(void);
80309 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
80310 +void gr_log_chdir(const struct dentry *dentry,
80311 + const struct vfsmount *mnt);
80312 +void gr_log_chroot_exec(const struct dentry *dentry,
80313 + const struct vfsmount *mnt);
80314 +void gr_log_remount(const char *devname, const int retval);
80315 +void gr_log_unmount(const char *devname, const int retval);
80316 +void gr_log_mount(const char *from, const char *to, const int retval);
80317 +void gr_log_textrel(struct vm_area_struct *vma);
80318 +void gr_log_ptgnustack(struct file *file);
80319 +void gr_log_rwxmmap(struct file *file);
80320 +void gr_log_rwxmprotect(struct vm_area_struct *vma);
80321 +
80322 +int gr_handle_follow_link(const struct inode *parent,
80323 + const struct inode *inode,
80324 + const struct dentry *dentry,
80325 + const struct vfsmount *mnt);
80326 +int gr_handle_fifo(const struct dentry *dentry,
80327 + const struct vfsmount *mnt,
80328 + const struct dentry *dir, const int flag,
80329 + const int acc_mode);
80330 +int gr_handle_hardlink(const struct dentry *dentry,
80331 + const struct vfsmount *mnt,
80332 + struct inode *inode,
80333 + const int mode, const struct filename *to);
80334 +
80335 +int gr_is_capable(const int cap);
80336 +int gr_is_capable_nolog(const int cap);
80337 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
80338 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
80339 +
80340 +void gr_copy_label(struct task_struct *tsk);
80341 +void gr_handle_crash(struct task_struct *task, const int sig);
80342 +int gr_handle_signal(const struct task_struct *p, const int sig);
80343 +int gr_check_crash_uid(const kuid_t uid);
80344 +int gr_check_protected_task(const struct task_struct *task);
80345 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
80346 +int gr_acl_handle_mmap(const struct file *file,
80347 + const unsigned long prot);
80348 +int gr_acl_handle_mprotect(const struct file *file,
80349 + const unsigned long prot);
80350 +int gr_check_hidden_task(const struct task_struct *tsk);
80351 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
80352 + const struct vfsmount *mnt);
80353 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
80354 + const struct vfsmount *mnt);
80355 +__u32 gr_acl_handle_access(const struct dentry *dentry,
80356 + const struct vfsmount *mnt, const int fmode);
80357 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
80358 + const struct vfsmount *mnt, umode_t *mode);
80359 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
80360 + const struct vfsmount *mnt);
80361 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
80362 + const struct vfsmount *mnt);
80363 +__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
80364 + const struct vfsmount *mnt);
80365 +int gr_handle_ptrace(struct task_struct *task, const long request);
80366 +int gr_handle_proc_ptrace(struct task_struct *task);
80367 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
80368 + const struct vfsmount *mnt);
80369 +int gr_check_crash_exec(const struct file *filp);
80370 +int gr_acl_is_enabled(void);
80371 +void gr_set_role_label(struct task_struct *task, const kuid_t uid,
80372 + const kgid_t gid);
80373 +int gr_set_proc_label(const struct dentry *dentry,
80374 + const struct vfsmount *mnt,
80375 + const int unsafe_flags);
80376 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
80377 + const struct vfsmount *mnt);
80378 +__u32 gr_acl_handle_open(const struct dentry *dentry,
80379 + const struct vfsmount *mnt, int acc_mode);
80380 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
80381 + const struct dentry *p_dentry,
80382 + const struct vfsmount *p_mnt,
80383 + int open_flags, int acc_mode, const int imode);
80384 +void gr_handle_create(const struct dentry *dentry,
80385 + const struct vfsmount *mnt);
80386 +void gr_handle_proc_create(const struct dentry *dentry,
80387 + const struct inode *inode);
80388 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
80389 + const struct dentry *parent_dentry,
80390 + const struct vfsmount *parent_mnt,
80391 + const int mode);
80392 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
80393 + const struct dentry *parent_dentry,
80394 + const struct vfsmount *parent_mnt);
80395 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
80396 + const struct vfsmount *mnt);
80397 +void gr_handle_delete(const ino_t ino, const dev_t dev);
80398 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
80399 + const struct vfsmount *mnt);
80400 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
80401 + const struct dentry *parent_dentry,
80402 + const struct vfsmount *parent_mnt,
80403 + const struct filename *from);
80404 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
80405 + const struct dentry *parent_dentry,
80406 + const struct vfsmount *parent_mnt,
80407 + const struct dentry *old_dentry,
80408 + const struct vfsmount *old_mnt, const struct filename *to);
80409 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
80410 +int gr_acl_handle_rename(struct dentry *new_dentry,
80411 + struct dentry *parent_dentry,
80412 + const struct vfsmount *parent_mnt,
80413 + struct dentry *old_dentry,
80414 + struct inode *old_parent_inode,
80415 + struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags);
80416 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
80417 + struct dentry *old_dentry,
80418 + struct dentry *new_dentry,
80419 + struct vfsmount *mnt, const __u8 replace, unsigned int flags);
80420 +__u32 gr_check_link(const struct dentry *new_dentry,
80421 + const struct dentry *parent_dentry,
80422 + const struct vfsmount *parent_mnt,
80423 + const struct dentry *old_dentry,
80424 + const struct vfsmount *old_mnt);
80425 +int gr_acl_handle_filldir(const struct file *file, const char *name,
80426 + const unsigned int namelen, const ino_t ino);
80427 +
80428 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
80429 + const struct vfsmount *mnt);
80430 +void gr_acl_handle_exit(void);
80431 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
80432 +int gr_acl_handle_procpidmem(const struct task_struct *task);
80433 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
80434 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
80435 +void gr_audit_ptrace(struct task_struct *task);
80436 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
80437 +void gr_put_exec_file(struct task_struct *task);
80438 +
80439 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
80440 +
80441 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
80442 +extern void gr_learn_resource(const struct task_struct *task, const int res,
80443 + const unsigned long wanted, const int gt);
80444 +#else
80445 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
80446 + const unsigned long wanted, const int gt)
80447 +{
80448 +}
80449 +#endif
80450 +
80451 +#ifdef CONFIG_GRKERNSEC_RESLOG
80452 +extern void gr_log_resource(const struct task_struct *task, const int res,
80453 + const unsigned long wanted, const int gt);
80454 +#else
80455 +static inline void gr_log_resource(const struct task_struct *task, const int res,
80456 + const unsigned long wanted, const int gt)
80457 +{
80458 +}
80459 +#endif
80460 +
80461 +#ifdef CONFIG_GRKERNSEC
80462 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
80463 +void gr_handle_vm86(void);
80464 +void gr_handle_mem_readwrite(u64 from, u64 to);
80465 +
80466 +void gr_log_badprocpid(const char *entry);
80467 +
80468 +extern int grsec_enable_dmesg;
80469 +extern int grsec_disable_privio;
80470 +
80471 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
80472 +extern kgid_t grsec_proc_gid;
80473 +#endif
80474 +
80475 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
80476 +extern int grsec_enable_chroot_findtask;
80477 +#endif
80478 +#ifdef CONFIG_GRKERNSEC_SETXID
80479 +extern int grsec_enable_setxid;
80480 +#endif
80481 +#endif
80482 +
80483 +#endif
80484 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
80485 new file mode 100644
80486 index 0000000..e7ffaaf
80487 --- /dev/null
80488 +++ b/include/linux/grsock.h
80489 @@ -0,0 +1,19 @@
80490 +#ifndef __GRSOCK_H
80491 +#define __GRSOCK_H
80492 +
80493 +extern void gr_attach_curr_ip(const struct sock *sk);
80494 +extern int gr_handle_sock_all(const int family, const int type,
80495 + const int protocol);
80496 +extern int gr_handle_sock_server(const struct sockaddr *sck);
80497 +extern int gr_handle_sock_server_other(const struct sock *sck);
80498 +extern int gr_handle_sock_client(const struct sockaddr *sck);
80499 +extern int gr_search_connect(struct socket * sock,
80500 + struct sockaddr_in * addr);
80501 +extern int gr_search_bind(struct socket * sock,
80502 + struct sockaddr_in * addr);
80503 +extern int gr_search_listen(struct socket * sock);
80504 +extern int gr_search_accept(struct socket * sock);
80505 +extern int gr_search_socket(const int domain, const int type,
80506 + const int protocol);
80507 +
80508 +#endif
80509 diff --git a/include/linux/hash.h b/include/linux/hash.h
80510 index bd1754c..8240892 100644
80511 --- a/include/linux/hash.h
80512 +++ b/include/linux/hash.h
80513 @@ -83,7 +83,7 @@ static inline u32 hash32_ptr(const void *ptr)
80514 struct fast_hash_ops {
80515 u32 (*hash)(const void *data, u32 len, u32 seed);
80516 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
80517 -};
80518 +} __no_const;
80519
80520 /**
80521 * arch_fast_hash - Caclulates a hash over a given buffer that can have
80522 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
80523 index 7fb31da..08b5114 100644
80524 --- a/include/linux/highmem.h
80525 +++ b/include/linux/highmem.h
80526 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
80527 kunmap_atomic(kaddr);
80528 }
80529
80530 +static inline void sanitize_highpage(struct page *page)
80531 +{
80532 + void *kaddr;
80533 + unsigned long flags;
80534 +
80535 + local_irq_save(flags);
80536 + kaddr = kmap_atomic(page);
80537 + clear_page(kaddr);
80538 + kunmap_atomic(kaddr);
80539 + local_irq_restore(flags);
80540 +}
80541 +
80542 static inline void zero_user_segments(struct page *page,
80543 unsigned start1, unsigned end1,
80544 unsigned start2, unsigned end2)
80545 diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
80546 index 1c7b89a..7dda400 100644
80547 --- a/include/linux/hwmon-sysfs.h
80548 +++ b/include/linux/hwmon-sysfs.h
80549 @@ -25,7 +25,8 @@
80550 struct sensor_device_attribute{
80551 struct device_attribute dev_attr;
80552 int index;
80553 -};
80554 +} __do_const;
80555 +typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
80556 #define to_sensor_dev_attr(_dev_attr) \
80557 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
80558
80559 @@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
80560 struct device_attribute dev_attr;
80561 u8 index;
80562 u8 nr;
80563 -};
80564 +} __do_const;
80565 +typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
80566 #define to_sensor_dev_attr_2(_dev_attr) \
80567 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
80568
80569 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
80570 index b556e0a..c10a515 100644
80571 --- a/include/linux/i2c.h
80572 +++ b/include/linux/i2c.h
80573 @@ -378,6 +378,7 @@ struct i2c_algorithm {
80574 /* To determine what the adapter supports */
80575 u32 (*functionality) (struct i2c_adapter *);
80576 };
80577 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
80578
80579 /**
80580 * struct i2c_bus_recovery_info - I2C bus recovery information
80581 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
80582 index d23c3c2..eb63c81 100644
80583 --- a/include/linux/i2o.h
80584 +++ b/include/linux/i2o.h
80585 @@ -565,7 +565,7 @@ struct i2o_controller {
80586 struct i2o_device *exec; /* Executive */
80587 #if BITS_PER_LONG == 64
80588 spinlock_t context_list_lock; /* lock for context_list */
80589 - atomic_t context_list_counter; /* needed for unique contexts */
80590 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
80591 struct list_head context_list; /* list of context id's
80592 and pointers */
80593 #endif
80594 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
80595 index aff7ad8..3942bbd 100644
80596 --- a/include/linux/if_pppox.h
80597 +++ b/include/linux/if_pppox.h
80598 @@ -76,7 +76,7 @@ struct pppox_proto {
80599 int (*ioctl)(struct socket *sock, unsigned int cmd,
80600 unsigned long arg);
80601 struct module *owner;
80602 -};
80603 +} __do_const;
80604
80605 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
80606 extern void unregister_pppox_proto(int proto_num);
80607 diff --git a/include/linux/init.h b/include/linux/init.h
80608 index a3ba270..a1b6604 100644
80609 --- a/include/linux/init.h
80610 +++ b/include/linux/init.h
80611 @@ -37,9 +37,17 @@
80612 * section.
80613 */
80614
80615 +#define add_init_latent_entropy __latent_entropy
80616 +
80617 +#ifdef CONFIG_MEMORY_HOTPLUG
80618 +#define add_meminit_latent_entropy
80619 +#else
80620 +#define add_meminit_latent_entropy __latent_entropy
80621 +#endif
80622 +
80623 /* These are for everybody (although not all archs will actually
80624 discard it in modules) */
80625 -#define __init __section(.init.text) __cold notrace
80626 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
80627 #define __initdata __section(.init.data)
80628 #define __initconst __constsection(.init.rodata)
80629 #define __exitdata __section(.exit.data)
80630 @@ -100,7 +108,7 @@
80631 #define __cpuexitconst
80632
80633 /* Used for MEMORY_HOTPLUG */
80634 -#define __meminit __section(.meminit.text) __cold notrace
80635 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
80636 #define __meminitdata __section(.meminit.data)
80637 #define __meminitconst __constsection(.meminit.rodata)
80638 #define __memexit __section(.memexit.text) __exitused __cold notrace
80639 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
80640 index 6df7f9f..d0bf699 100644
80641 --- a/include/linux/init_task.h
80642 +++ b/include/linux/init_task.h
80643 @@ -156,6 +156,12 @@ extern struct task_group root_task_group;
80644
80645 #define INIT_TASK_COMM "swapper"
80646
80647 +#ifdef CONFIG_X86
80648 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
80649 +#else
80650 +#define INIT_TASK_THREAD_INFO
80651 +#endif
80652 +
80653 #ifdef CONFIG_RT_MUTEXES
80654 # define INIT_RT_MUTEXES(tsk) \
80655 .pi_waiters = RB_ROOT, \
80656 @@ -203,6 +209,7 @@ extern struct task_group root_task_group;
80657 RCU_POINTER_INITIALIZER(cred, &init_cred), \
80658 .comm = INIT_TASK_COMM, \
80659 .thread = INIT_THREAD, \
80660 + INIT_TASK_THREAD_INFO \
80661 .fs = &init_fs, \
80662 .files = &init_files, \
80663 .signal = &init_signals, \
80664 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
80665 index 051c850..431f83a 100644
80666 --- a/include/linux/interrupt.h
80667 +++ b/include/linux/interrupt.h
80668 @@ -412,8 +412,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
80669
80670 struct softirq_action
80671 {
80672 - void (*action)(struct softirq_action *);
80673 -};
80674 + void (*action)(void);
80675 +} __no_const;
80676
80677 asmlinkage void do_softirq(void);
80678 asmlinkage void __do_softirq(void);
80679 @@ -427,7 +427,7 @@ static inline void do_softirq_own_stack(void)
80680 }
80681 #endif
80682
80683 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
80684 +extern void open_softirq(int nr, void (*action)(void));
80685 extern void softirq_init(void);
80686 extern void __raise_softirq_irqoff(unsigned int nr);
80687
80688 diff --git a/include/linux/iommu.h b/include/linux/iommu.h
80689 index b96a5b2..2732d1c 100644
80690 --- a/include/linux/iommu.h
80691 +++ b/include/linux/iommu.h
80692 @@ -131,7 +131,7 @@ struct iommu_ops {
80693 u32 (*domain_get_windows)(struct iommu_domain *domain);
80694
80695 unsigned long pgsize_bitmap;
80696 -};
80697 +} __do_const;
80698
80699 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
80700 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
80701 diff --git a/include/linux/ioport.h b/include/linux/ioport.h
80702 index 5e3a906..3131d0f 100644
80703 --- a/include/linux/ioport.h
80704 +++ b/include/linux/ioport.h
80705 @@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
80706 int adjust_resource(struct resource *res, resource_size_t start,
80707 resource_size_t size);
80708 resource_size_t resource_alignment(struct resource *res);
80709 -static inline resource_size_t resource_size(const struct resource *res)
80710 +static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
80711 {
80712 return res->end - res->start + 1;
80713 }
80714 diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
80715 index 35e7eca..6afb7ad 100644
80716 --- a/include/linux/ipc_namespace.h
80717 +++ b/include/linux/ipc_namespace.h
80718 @@ -69,7 +69,7 @@ struct ipc_namespace {
80719 struct user_namespace *user_ns;
80720
80721 unsigned int proc_inum;
80722 -};
80723 +} __randomize_layout;
80724
80725 extern struct ipc_namespace init_ipc_ns;
80726 extern atomic_t nr_ipc_ns;
80727 diff --git a/include/linux/irq.h b/include/linux/irq.h
80728 index 5c57efb..965a62b 100644
80729 --- a/include/linux/irq.h
80730 +++ b/include/linux/irq.h
80731 @@ -344,7 +344,8 @@ struct irq_chip {
80732 void (*irq_release_resources)(struct irq_data *data);
80733
80734 unsigned long flags;
80735 -};
80736 +} __do_const;
80737 +typedef struct irq_chip __no_const irq_chip_no_const;
80738
80739 /*
80740 * irq_chip specific flags
80741 diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
80742 index 7ed92d0..589abf5 100644
80743 --- a/include/linux/irqchip/arm-gic.h
80744 +++ b/include/linux/irqchip/arm-gic.h
80745 @@ -73,9 +73,11 @@
80746
80747 #ifndef __ASSEMBLY__
80748
80749 +#include <linux/irq.h>
80750 +
80751 struct device_node;
80752
80753 -extern struct irq_chip gic_arch_extn;
80754 +extern irq_chip_no_const gic_arch_extn;
80755
80756 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
80757 u32 offset, struct device_node *);
80758 diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
80759 index 1f44466..b481806 100644
80760 --- a/include/linux/jiffies.h
80761 +++ b/include/linux/jiffies.h
80762 @@ -292,20 +292,20 @@ extern unsigned long preset_lpj;
80763 /*
80764 * Convert various time units to each other:
80765 */
80766 -extern unsigned int jiffies_to_msecs(const unsigned long j);
80767 -extern unsigned int jiffies_to_usecs(const unsigned long j);
80768 +extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
80769 +extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
80770
80771 -static inline u64 jiffies_to_nsecs(const unsigned long j)
80772 +static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
80773 {
80774 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
80775 }
80776
80777 -extern unsigned long msecs_to_jiffies(const unsigned int m);
80778 -extern unsigned long usecs_to_jiffies(const unsigned int u);
80779 +extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
80780 +extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
80781 extern unsigned long timespec_to_jiffies(const struct timespec *value);
80782 extern void jiffies_to_timespec(const unsigned long jiffies,
80783 - struct timespec *value);
80784 -extern unsigned long timeval_to_jiffies(const struct timeval *value);
80785 + struct timespec *value) __intentional_overflow(-1);
80786 +extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
80787 extern void jiffies_to_timeval(const unsigned long jiffies,
80788 struct timeval *value);
80789
80790 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
80791 index 6883e19..e854fcb 100644
80792 --- a/include/linux/kallsyms.h
80793 +++ b/include/linux/kallsyms.h
80794 @@ -15,7 +15,8 @@
80795
80796 struct module;
80797
80798 -#ifdef CONFIG_KALLSYMS
80799 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
80800 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
80801 /* Lookup the address for a symbol. Returns 0 if not found. */
80802 unsigned long kallsyms_lookup_name(const char *name);
80803
80804 @@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
80805 /* Stupid that this does nothing, but I didn't create this mess. */
80806 #define __print_symbol(fmt, addr)
80807 #endif /*CONFIG_KALLSYMS*/
80808 +#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
80809 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
80810 +extern unsigned long kallsyms_lookup_name(const char *name);
80811 +extern void __print_symbol(const char *fmt, unsigned long address);
80812 +extern int sprint_backtrace(char *buffer, unsigned long address);
80813 +extern int sprint_symbol(char *buffer, unsigned long address);
80814 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
80815 +const char *kallsyms_lookup(unsigned long addr,
80816 + unsigned long *symbolsize,
80817 + unsigned long *offset,
80818 + char **modname, char *namebuf);
80819 +extern int kallsyms_lookup_size_offset(unsigned long addr,
80820 + unsigned long *symbolsize,
80821 + unsigned long *offset);
80822 +#endif
80823
80824 /* This macro allows us to keep printk typechecking */
80825 static __printf(1, 2)
80826 diff --git a/include/linux/key-type.h b/include/linux/key-type.h
80827 index a74c3a8..28d3f21 100644
80828 --- a/include/linux/key-type.h
80829 +++ b/include/linux/key-type.h
80830 @@ -131,7 +131,7 @@ struct key_type {
80831 /* internal fields */
80832 struct list_head link; /* link in types list */
80833 struct lock_class_key lock_class; /* key->sem lock class */
80834 -};
80835 +} __do_const;
80836
80837 extern struct key_type key_type_keyring;
80838
80839 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
80840 index 6b06d37..c134867 100644
80841 --- a/include/linux/kgdb.h
80842 +++ b/include/linux/kgdb.h
80843 @@ -52,7 +52,7 @@ extern int kgdb_connected;
80844 extern int kgdb_io_module_registered;
80845
80846 extern atomic_t kgdb_setting_breakpoint;
80847 -extern atomic_t kgdb_cpu_doing_single_step;
80848 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
80849
80850 extern struct task_struct *kgdb_usethread;
80851 extern struct task_struct *kgdb_contthread;
80852 @@ -254,7 +254,7 @@ struct kgdb_arch {
80853 void (*correct_hw_break)(void);
80854
80855 void (*enable_nmi)(bool on);
80856 -};
80857 +} __do_const;
80858
80859 /**
80860 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
80861 @@ -279,7 +279,7 @@ struct kgdb_io {
80862 void (*pre_exception) (void);
80863 void (*post_exception) (void);
80864 int is_console;
80865 -};
80866 +} __do_const;
80867
80868 extern struct kgdb_arch arch_kgdb_ops;
80869
80870 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
80871 index 0555cc6..40116ce 100644
80872 --- a/include/linux/kmod.h
80873 +++ b/include/linux/kmod.h
80874 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
80875 * usually useless though. */
80876 extern __printf(2, 3)
80877 int __request_module(bool wait, const char *name, ...);
80878 +extern __printf(3, 4)
80879 +int ___request_module(bool wait, char *param_name, const char *name, ...);
80880 #define request_module(mod...) __request_module(true, mod)
80881 #define request_module_nowait(mod...) __request_module(false, mod)
80882 #define try_then_request_module(x, mod...) \
80883 @@ -57,6 +59,9 @@ struct subprocess_info {
80884 struct work_struct work;
80885 struct completion *complete;
80886 char *path;
80887 +#ifdef CONFIG_GRKERNSEC
80888 + char *origpath;
80889 +#endif
80890 char **argv;
80891 char **envp;
80892 int wait;
80893 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
80894 index f896a33..f2eb10f 100644
80895 --- a/include/linux/kobject.h
80896 +++ b/include/linux/kobject.h
80897 @@ -116,7 +116,7 @@ struct kobj_type {
80898 struct attribute **default_attrs;
80899 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
80900 const void *(*namespace)(struct kobject *kobj);
80901 -};
80902 +} __do_const;
80903
80904 struct kobj_uevent_env {
80905 char *argv[3];
80906 @@ -140,6 +140,7 @@ struct kobj_attribute {
80907 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
80908 const char *buf, size_t count);
80909 };
80910 +typedef struct kobj_attribute __no_const kobj_attribute_no_const;
80911
80912 extern const struct sysfs_ops kobj_sysfs_ops;
80913
80914 @@ -167,7 +168,7 @@ struct kset {
80915 spinlock_t list_lock;
80916 struct kobject kobj;
80917 const struct kset_uevent_ops *uevent_ops;
80918 -};
80919 +} __randomize_layout;
80920
80921 extern void kset_init(struct kset *kset);
80922 extern int __must_check kset_register(struct kset *kset);
80923 diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
80924 index df32d25..fb52e27 100644
80925 --- a/include/linux/kobject_ns.h
80926 +++ b/include/linux/kobject_ns.h
80927 @@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
80928 const void *(*netlink_ns)(struct sock *sk);
80929 const void *(*initial_ns)(void);
80930 void (*drop_ns)(void *);
80931 -};
80932 +} __do_const;
80933
80934 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
80935 int kobj_ns_type_registered(enum kobj_ns_type type);
80936 diff --git a/include/linux/kref.h b/include/linux/kref.h
80937 index 484604d..0f6c5b6 100644
80938 --- a/include/linux/kref.h
80939 +++ b/include/linux/kref.h
80940 @@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
80941 static inline int kref_sub(struct kref *kref, unsigned int count,
80942 void (*release)(struct kref *kref))
80943 {
80944 - WARN_ON(release == NULL);
80945 + BUG_ON(release == NULL);
80946
80947 if (atomic_sub_and_test((int) count, &kref->refcount)) {
80948 release(kref);
80949 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
80950 index 7d21cf9..bc0c81f 100644
80951 --- a/include/linux/kvm_host.h
80952 +++ b/include/linux/kvm_host.h
80953 @@ -466,7 +466,7 @@ static inline void kvm_irqfd_exit(void)
80954 {
80955 }
80956 #endif
80957 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80958 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80959 struct module *module);
80960 void kvm_exit(void);
80961
80962 @@ -632,7 +632,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
80963 struct kvm_guest_debug *dbg);
80964 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
80965
80966 -int kvm_arch_init(void *opaque);
80967 +int kvm_arch_init(const void *opaque);
80968 void kvm_arch_exit(void);
80969
80970 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
80971 diff --git a/include/linux/libata.h b/include/linux/libata.h
80972 index 92abb49..e7fff2a 100644
80973 --- a/include/linux/libata.h
80974 +++ b/include/linux/libata.h
80975 @@ -976,7 +976,7 @@ struct ata_port_operations {
80976 * fields must be pointers.
80977 */
80978 const struct ata_port_operations *inherits;
80979 -};
80980 +} __do_const;
80981
80982 struct ata_port_info {
80983 unsigned long flags;
80984 diff --git a/include/linux/linkage.h b/include/linux/linkage.h
80985 index a6a42dd..6c5ebce 100644
80986 --- a/include/linux/linkage.h
80987 +++ b/include/linux/linkage.h
80988 @@ -36,6 +36,7 @@
80989 #endif
80990
80991 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
80992 +#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
80993 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
80994
80995 /*
80996 diff --git a/include/linux/list.h b/include/linux/list.h
80997 index ef95941..82db65a 100644
80998 --- a/include/linux/list.h
80999 +++ b/include/linux/list.h
81000 @@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
81001 extern void list_del(struct list_head *entry);
81002 #endif
81003
81004 +extern void __pax_list_add(struct list_head *new,
81005 + struct list_head *prev,
81006 + struct list_head *next);
81007 +static inline void pax_list_add(struct list_head *new, struct list_head *head)
81008 +{
81009 + __pax_list_add(new, head, head->next);
81010 +}
81011 +static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
81012 +{
81013 + __pax_list_add(new, head->prev, head);
81014 +}
81015 +extern void pax_list_del(struct list_head *entry);
81016 +
81017 /**
81018 * list_replace - replace old entry by new one
81019 * @old : the element to be replaced
81020 @@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
81021 INIT_LIST_HEAD(entry);
81022 }
81023
81024 +extern void pax_list_del_init(struct list_head *entry);
81025 +
81026 /**
81027 * list_move - delete from one list and add as another's head
81028 * @list: the entry to move
81029 diff --git a/include/linux/math64.h b/include/linux/math64.h
81030 index c45c089..298841c 100644
81031 --- a/include/linux/math64.h
81032 +++ b/include/linux/math64.h
81033 @@ -15,7 +15,7 @@
81034 * This is commonly provided by 32bit archs to provide an optimized 64bit
81035 * divide.
81036 */
81037 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
81038 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
81039 {
81040 *remainder = dividend % divisor;
81041 return dividend / divisor;
81042 @@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
81043 /**
81044 * div64_u64 - unsigned 64bit divide with 64bit divisor
81045 */
81046 -static inline u64 div64_u64(u64 dividend, u64 divisor)
81047 +static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
81048 {
81049 return dividend / divisor;
81050 }
81051 @@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
81052 #define div64_ul(x, y) div_u64((x), (y))
81053
81054 #ifndef div_u64_rem
81055 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
81056 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
81057 {
81058 *remainder = do_div(dividend, divisor);
81059 return dividend;
81060 @@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
81061 #endif
81062
81063 #ifndef div64_u64
81064 -extern u64 div64_u64(u64 dividend, u64 divisor);
81065 +extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
81066 #endif
81067
81068 #ifndef div64_s64
81069 @@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
81070 * divide.
81071 */
81072 #ifndef div_u64
81073 -static inline u64 div_u64(u64 dividend, u32 divisor)
81074 +static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
81075 {
81076 u32 remainder;
81077 return div_u64_rem(dividend, divisor, &remainder);
81078 diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
81079 index f230a97..714c006 100644
81080 --- a/include/linux/mempolicy.h
81081 +++ b/include/linux/mempolicy.h
81082 @@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
81083 }
81084
81085 #define vma_policy(vma) ((vma)->vm_policy)
81086 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
81087 +{
81088 + vma->vm_policy = pol;
81089 +}
81090
81091 static inline void mpol_get(struct mempolicy *pol)
81092 {
81093 @@ -228,6 +232,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
81094 }
81095
81096 #define vma_policy(vma) NULL
81097 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
81098 +{
81099 +}
81100
81101 static inline int
81102 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
81103 diff --git a/include/linux/mm.h b/include/linux/mm.h
81104 index d677706..673408c 100644
81105 --- a/include/linux/mm.h
81106 +++ b/include/linux/mm.h
81107 @@ -127,6 +127,11 @@ extern unsigned int kobjsize(const void *objp);
81108 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
81109 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
81110 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
81111 +
81112 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
81113 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
81114 +#endif
81115 +
81116 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
81117
81118 #ifdef CONFIG_MEM_SOFT_DIRTY
81119 @@ -237,8 +242,8 @@ struct vm_operations_struct {
81120 /* called by access_process_vm when get_user_pages() fails, typically
81121 * for use by special VMAs that can switch between memory and hardware
81122 */
81123 - int (*access)(struct vm_area_struct *vma, unsigned long addr,
81124 - void *buf, int len, int write);
81125 + ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
81126 + void *buf, size_t len, int write);
81127 #ifdef CONFIG_NUMA
81128 /*
81129 * set_policy() op must add a reference to any non-NULL @new mempolicy
81130 @@ -268,6 +273,7 @@ struct vm_operations_struct {
81131 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
81132 unsigned long size, pgoff_t pgoff);
81133 };
81134 +typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
81135
81136 struct mmu_gather;
81137 struct inode;
81138 @@ -1133,8 +1139,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
81139 unsigned long *pfn);
81140 int follow_phys(struct vm_area_struct *vma, unsigned long address,
81141 unsigned int flags, unsigned long *prot, resource_size_t *phys);
81142 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
81143 - void *buf, int len, int write);
81144 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
81145 + void *buf, size_t len, int write);
81146
81147 static inline void unmap_shared_mapping_range(struct address_space *mapping,
81148 loff_t const holebegin, loff_t const holelen)
81149 @@ -1173,9 +1179,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
81150 }
81151 #endif
81152
81153 -extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
81154 -extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
81155 - void *buf, int len, int write);
81156 +extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
81157 +extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
81158 + void *buf, size_t len, int write);
81159
81160 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
81161 unsigned long start, unsigned long nr_pages,
81162 @@ -1208,34 +1214,6 @@ int set_page_dirty_lock(struct page *page);
81163 int clear_page_dirty_for_io(struct page *page);
81164 int get_cmdline(struct task_struct *task, char *buffer, int buflen);
81165
81166 -/* Is the vma a continuation of the stack vma above it? */
81167 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
81168 -{
81169 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
81170 -}
81171 -
81172 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
81173 - unsigned long addr)
81174 -{
81175 - return (vma->vm_flags & VM_GROWSDOWN) &&
81176 - (vma->vm_start == addr) &&
81177 - !vma_growsdown(vma->vm_prev, addr);
81178 -}
81179 -
81180 -/* Is the vma a continuation of the stack vma below it? */
81181 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
81182 -{
81183 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
81184 -}
81185 -
81186 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
81187 - unsigned long addr)
81188 -{
81189 - return (vma->vm_flags & VM_GROWSUP) &&
81190 - (vma->vm_end == addr) &&
81191 - !vma_growsup(vma->vm_next, addr);
81192 -}
81193 -
81194 extern pid_t
81195 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
81196
81197 @@ -1335,6 +1313,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
81198 }
81199 #endif
81200
81201 +#ifdef CONFIG_MMU
81202 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
81203 +#else
81204 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
81205 +{
81206 + return __pgprot(0);
81207 +}
81208 +#endif
81209 +
81210 int vma_wants_writenotify(struct vm_area_struct *vma);
81211
81212 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
81213 @@ -1353,8 +1340,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
81214 {
81215 return 0;
81216 }
81217 +
81218 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
81219 + unsigned long address)
81220 +{
81221 + return 0;
81222 +}
81223 #else
81224 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
81225 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
81226 #endif
81227
81228 #ifdef __PAGETABLE_PMD_FOLDED
81229 @@ -1363,8 +1357,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
81230 {
81231 return 0;
81232 }
81233 +
81234 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
81235 + unsigned long address)
81236 +{
81237 + return 0;
81238 +}
81239 #else
81240 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
81241 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
81242 #endif
81243
81244 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
81245 @@ -1382,11 +1383,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
81246 NULL: pud_offset(pgd, address);
81247 }
81248
81249 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
81250 +{
81251 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
81252 + NULL: pud_offset(pgd, address);
81253 +}
81254 +
81255 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
81256 {
81257 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
81258 NULL: pmd_offset(pud, address);
81259 }
81260 +
81261 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
81262 +{
81263 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
81264 + NULL: pmd_offset(pud, address);
81265 +}
81266 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
81267
81268 #if USE_SPLIT_PTE_PTLOCKS
81269 @@ -1783,7 +1796,7 @@ extern int install_special_mapping(struct mm_struct *mm,
81270 unsigned long addr, unsigned long len,
81271 unsigned long flags, struct page **pages);
81272
81273 -extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
81274 +extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
81275
81276 extern unsigned long mmap_region(struct file *file, unsigned long addr,
81277 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
81278 @@ -1791,6 +1804,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
81279 unsigned long len, unsigned long prot, unsigned long flags,
81280 unsigned long pgoff, unsigned long *populate);
81281 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
81282 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
81283
81284 #ifdef CONFIG_MMU
81285 extern int __mm_populate(unsigned long addr, unsigned long len,
81286 @@ -1819,10 +1833,11 @@ struct vm_unmapped_area_info {
81287 unsigned long high_limit;
81288 unsigned long align_mask;
81289 unsigned long align_offset;
81290 + unsigned long threadstack_offset;
81291 };
81292
81293 -extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
81294 -extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
81295 +extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
81296 +extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
81297
81298 /*
81299 * Search for an unmapped address range.
81300 @@ -1834,7 +1849,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
81301 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
81302 */
81303 static inline unsigned long
81304 -vm_unmapped_area(struct vm_unmapped_area_info *info)
81305 +vm_unmapped_area(const struct vm_unmapped_area_info *info)
81306 {
81307 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
81308 return unmapped_area(info);
81309 @@ -1896,6 +1911,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
81310 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
81311 struct vm_area_struct **pprev);
81312
81313 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
81314 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
81315 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
81316 +
81317 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
81318 NULL if none. Assume start_addr < end_addr. */
81319 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
81320 @@ -1924,15 +1943,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
81321 return vma;
81322 }
81323
81324 -#ifdef CONFIG_MMU
81325 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
81326 -#else
81327 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
81328 -{
81329 - return __pgprot(0);
81330 -}
81331 -#endif
81332 -
81333 #ifdef CONFIG_NUMA_BALANCING
81334 unsigned long change_prot_numa(struct vm_area_struct *vma,
81335 unsigned long start, unsigned long end);
81336 @@ -1984,6 +1994,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
81337 static inline void vm_stat_account(struct mm_struct *mm,
81338 unsigned long flags, struct file *file, long pages)
81339 {
81340 +
81341 +#ifdef CONFIG_PAX_RANDMMAP
81342 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
81343 +#endif
81344 +
81345 mm->total_vm += pages;
81346 }
81347 #endif /* CONFIG_PROC_FS */
81348 @@ -2065,7 +2080,7 @@ extern int unpoison_memory(unsigned long pfn);
81349 extern int sysctl_memory_failure_early_kill;
81350 extern int sysctl_memory_failure_recovery;
81351 extern void shake_page(struct page *p, int access);
81352 -extern atomic_long_t num_poisoned_pages;
81353 +extern atomic_long_unchecked_t num_poisoned_pages;
81354 extern int soft_offline_page(struct page *page, int flags);
81355
81356 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
81357 @@ -2100,5 +2115,11 @@ void __init setup_nr_node_ids(void);
81358 static inline void setup_nr_node_ids(void) {}
81359 #endif
81360
81361 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
81362 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
81363 +#else
81364 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
81365 +#endif
81366 +
81367 #endif /* __KERNEL__ */
81368 #endif /* _LINUX_MM_H */
81369 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
81370 index 8967e20..61f7900 100644
81371 --- a/include/linux/mm_types.h
81372 +++ b/include/linux/mm_types.h
81373 @@ -308,7 +308,9 @@ struct vm_area_struct {
81374 #ifdef CONFIG_NUMA
81375 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
81376 #endif
81377 -};
81378 +
81379 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
81380 +} __randomize_layout;
81381
81382 struct core_thread {
81383 struct task_struct *task;
81384 @@ -454,7 +456,25 @@ struct mm_struct {
81385 bool tlb_flush_pending;
81386 #endif
81387 struct uprobes_state uprobes_state;
81388 -};
81389 +
81390 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
81391 + unsigned long pax_flags;
81392 +#endif
81393 +
81394 +#ifdef CONFIG_PAX_DLRESOLVE
81395 + unsigned long call_dl_resolve;
81396 +#endif
81397 +
81398 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
81399 + unsigned long call_syscall;
81400 +#endif
81401 +
81402 +#ifdef CONFIG_PAX_ASLR
81403 + unsigned long delta_mmap; /* randomized offset */
81404 + unsigned long delta_stack; /* randomized offset */
81405 +#endif
81406 +
81407 +} __randomize_layout;
81408
81409 static inline void mm_init_cpumask(struct mm_struct *mm)
81410 {
81411 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
81412 index c5d5278..f0b68c8 100644
81413 --- a/include/linux/mmiotrace.h
81414 +++ b/include/linux/mmiotrace.h
81415 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
81416 /* Called from ioremap.c */
81417 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
81418 void __iomem *addr);
81419 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
81420 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
81421
81422 /* For anyone to insert markers. Remember trailing newline. */
81423 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
81424 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
81425 {
81426 }
81427
81428 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
81429 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
81430 {
81431 }
81432
81433 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
81434 index 835aa3d..676b387 100644
81435 --- a/include/linux/mmzone.h
81436 +++ b/include/linux/mmzone.h
81437 @@ -406,7 +406,7 @@ struct zone {
81438 unsigned long flags; /* zone flags, see below */
81439
81440 /* Zone statistics */
81441 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
81442 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
81443
81444 /*
81445 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
81446 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
81447 index 44eeef0..a92d3f9 100644
81448 --- a/include/linux/mod_devicetable.h
81449 +++ b/include/linux/mod_devicetable.h
81450 @@ -139,7 +139,7 @@ struct usb_device_id {
81451 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
81452 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
81453
81454 -#define HID_ANY_ID (~0)
81455 +#define HID_ANY_ID (~0U)
81456 #define HID_BUS_ANY 0xffff
81457 #define HID_GROUP_ANY 0x0000
81458
81459 @@ -475,7 +475,7 @@ struct dmi_system_id {
81460 const char *ident;
81461 struct dmi_strmatch matches[4];
81462 void *driver_data;
81463 -};
81464 +} __do_const;
81465 /*
81466 * struct dmi_device_id appears during expansion of
81467 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
81468 diff --git a/include/linux/module.h b/include/linux/module.h
81469 index f520a76..5f898ef 100644
81470 --- a/include/linux/module.h
81471 +++ b/include/linux/module.h
81472 @@ -17,9 +17,11 @@
81473 #include <linux/moduleparam.h>
81474 #include <linux/jump_label.h>
81475 #include <linux/export.h>
81476 +#include <linux/fs.h>
81477
81478 #include <linux/percpu.h>
81479 #include <asm/module.h>
81480 +#include <asm/pgtable.h>
81481
81482 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
81483 #define MODULE_SIG_STRING "~Module signature appended~\n"
81484 @@ -42,7 +44,7 @@ struct module_kobject {
81485 struct kobject *drivers_dir;
81486 struct module_param_attrs *mp;
81487 struct completion *kobj_completion;
81488 -};
81489 +} __randomize_layout;
81490
81491 struct module_attribute {
81492 struct attribute attr;
81493 @@ -54,12 +56,13 @@ struct module_attribute {
81494 int (*test)(struct module *);
81495 void (*free)(struct module *);
81496 };
81497 +typedef struct module_attribute __no_const module_attribute_no_const;
81498
81499 struct module_version_attribute {
81500 struct module_attribute mattr;
81501 const char *module_name;
81502 const char *version;
81503 -} __attribute__ ((__aligned__(sizeof(void *))));
81504 +} __do_const __attribute__ ((__aligned__(sizeof(void *))));
81505
81506 extern ssize_t __modver_version_show(struct module_attribute *,
81507 struct module_kobject *, char *);
81508 @@ -235,7 +238,7 @@ struct module {
81509
81510 /* Sysfs stuff. */
81511 struct module_kobject mkobj;
81512 - struct module_attribute *modinfo_attrs;
81513 + module_attribute_no_const *modinfo_attrs;
81514 const char *version;
81515 const char *srcversion;
81516 struct kobject *holders_dir;
81517 @@ -284,19 +287,16 @@ struct module {
81518 int (*init)(void);
81519
81520 /* If this is non-NULL, vfree after init() returns */
81521 - void *module_init;
81522 + void *module_init_rx, *module_init_rw;
81523
81524 /* Here is the actual code + data, vfree'd on unload. */
81525 - void *module_core;
81526 + void *module_core_rx, *module_core_rw;
81527
81528 /* Here are the sizes of the init and core sections */
81529 - unsigned int init_size, core_size;
81530 + unsigned int init_size_rw, core_size_rw;
81531
81532 /* The size of the executable code in each section. */
81533 - unsigned int init_text_size, core_text_size;
81534 -
81535 - /* Size of RO sections of the module (text+rodata) */
81536 - unsigned int init_ro_size, core_ro_size;
81537 + unsigned int init_size_rx, core_size_rx;
81538
81539 /* Arch-specific module values */
81540 struct mod_arch_specific arch;
81541 @@ -352,6 +352,10 @@ struct module {
81542 #ifdef CONFIG_EVENT_TRACING
81543 struct ftrace_event_call **trace_events;
81544 unsigned int num_trace_events;
81545 + struct file_operations trace_id;
81546 + struct file_operations trace_enable;
81547 + struct file_operations trace_format;
81548 + struct file_operations trace_filter;
81549 #endif
81550 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
81551 unsigned int num_ftrace_callsites;
81552 @@ -375,7 +379,7 @@ struct module {
81553 ctor_fn_t *ctors;
81554 unsigned int num_ctors;
81555 #endif
81556 -};
81557 +} __randomize_layout;
81558 #ifndef MODULE_ARCH_INIT
81559 #define MODULE_ARCH_INIT {}
81560 #endif
81561 @@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
81562 bool is_module_percpu_address(unsigned long addr);
81563 bool is_module_text_address(unsigned long addr);
81564
81565 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
81566 +{
81567 +
81568 +#ifdef CONFIG_PAX_KERNEXEC
81569 + if (ktla_ktva(addr) >= (unsigned long)start &&
81570 + ktla_ktva(addr) < (unsigned long)start + size)
81571 + return 1;
81572 +#endif
81573 +
81574 + return ((void *)addr >= start && (void *)addr < start + size);
81575 +}
81576 +
81577 +static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
81578 +{
81579 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
81580 +}
81581 +
81582 +static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
81583 +{
81584 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
81585 +}
81586 +
81587 +static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
81588 +{
81589 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
81590 +}
81591 +
81592 +static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
81593 +{
81594 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
81595 +}
81596 +
81597 static inline int within_module_core(unsigned long addr, const struct module *mod)
81598 {
81599 - return (unsigned long)mod->module_core <= addr &&
81600 - addr < (unsigned long)mod->module_core + mod->core_size;
81601 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
81602 }
81603
81604 static inline int within_module_init(unsigned long addr, const struct module *mod)
81605 {
81606 - return (unsigned long)mod->module_init <= addr &&
81607 - addr < (unsigned long)mod->module_init + mod->init_size;
81608 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
81609 }
81610
81611 /* Search for module by name: must hold module_mutex. */
81612 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
81613 index 560ca53..ef621ef 100644
81614 --- a/include/linux/moduleloader.h
81615 +++ b/include/linux/moduleloader.h
81616 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
81617 sections. Returns NULL on failure. */
81618 void *module_alloc(unsigned long size);
81619
81620 +#ifdef CONFIG_PAX_KERNEXEC
81621 +void *module_alloc_exec(unsigned long size);
81622 +#else
81623 +#define module_alloc_exec(x) module_alloc(x)
81624 +#endif
81625 +
81626 /* Free memory returned from module_alloc. */
81627 void module_free(struct module *mod, void *module_region);
81628
81629 +#ifdef CONFIG_PAX_KERNEXEC
81630 +void module_free_exec(struct module *mod, void *module_region);
81631 +#else
81632 +#define module_free_exec(x, y) module_free((x), (y))
81633 +#endif
81634 +
81635 /*
81636 * Apply the given relocation to the (simplified) ELF. Return -error
81637 * or 0.
81638 @@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
81639 unsigned int relsec,
81640 struct module *me)
81641 {
81642 +#ifdef CONFIG_MODULES
81643 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
81644 +#endif
81645 return -ENOEXEC;
81646 }
81647 #endif
81648 @@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
81649 unsigned int relsec,
81650 struct module *me)
81651 {
81652 +#ifdef CONFIG_MODULES
81653 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
81654 +#endif
81655 return -ENOEXEC;
81656 }
81657 #endif
81658 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
81659 index 204a677..e9b486a 100644
81660 --- a/include/linux/moduleparam.h
81661 +++ b/include/linux/moduleparam.h
81662 @@ -293,7 +293,7 @@ static inline void __kernel_param_unlock(void)
81663 * @len is usually just sizeof(string).
81664 */
81665 #define module_param_string(name, string, len, perm) \
81666 - static const struct kparam_string __param_string_##name \
81667 + static const struct kparam_string __param_string_##name __used \
81668 = { len, string }; \
81669 __module_param_call(MODULE_PARAM_PREFIX, name, \
81670 &param_ops_string, \
81671 @@ -432,7 +432,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
81672 */
81673 #define module_param_array_named(name, array, type, nump, perm) \
81674 param_check_##type(name, &(array)[0]); \
81675 - static const struct kparam_array __param_arr_##name \
81676 + static const struct kparam_array __param_arr_##name __used \
81677 = { .max = ARRAY_SIZE(array), .num = nump, \
81678 .ops = &param_ops_##type, \
81679 .elemsize = sizeof(array[0]), .elem = array }; \
81680 diff --git a/include/linux/mount.h b/include/linux/mount.h
81681 index 839bac2..a96b37c 100644
81682 --- a/include/linux/mount.h
81683 +++ b/include/linux/mount.h
81684 @@ -59,7 +59,7 @@ struct vfsmount {
81685 struct dentry *mnt_root; /* root of the mounted tree */
81686 struct super_block *mnt_sb; /* pointer to superblock */
81687 int mnt_flags;
81688 -};
81689 +} __randomize_layout;
81690
81691 struct file; /* forward dec */
81692
81693 diff --git a/include/linux/namei.h b/include/linux/namei.h
81694 index 492de72..1bddcd4 100644
81695 --- a/include/linux/namei.h
81696 +++ b/include/linux/namei.h
81697 @@ -19,7 +19,7 @@ struct nameidata {
81698 unsigned seq, m_seq;
81699 int last_type;
81700 unsigned depth;
81701 - char *saved_names[MAX_NESTED_LINKS + 1];
81702 + const char *saved_names[MAX_NESTED_LINKS + 1];
81703 };
81704
81705 /*
81706 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
81707
81708 extern void nd_jump_link(struct nameidata *nd, struct path *path);
81709
81710 -static inline void nd_set_link(struct nameidata *nd, char *path)
81711 +static inline void nd_set_link(struct nameidata *nd, const char *path)
81712 {
81713 nd->saved_names[nd->depth] = path;
81714 }
81715
81716 -static inline char *nd_get_link(struct nameidata *nd)
81717 +static inline const char *nd_get_link(const struct nameidata *nd)
81718 {
81719 return nd->saved_names[nd->depth];
81720 }
81721 diff --git a/include/linux/net.h b/include/linux/net.h
81722 index 17d8339..81656c0 100644
81723 --- a/include/linux/net.h
81724 +++ b/include/linux/net.h
81725 @@ -192,7 +192,7 @@ struct net_proto_family {
81726 int (*create)(struct net *net, struct socket *sock,
81727 int protocol, int kern);
81728 struct module *owner;
81729 -};
81730 +} __do_const;
81731
81732 struct iovec;
81733 struct kvec;
81734 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
81735 index b42d07b..7f45ae2 100644
81736 --- a/include/linux/netdevice.h
81737 +++ b/include/linux/netdevice.h
81738 @@ -1146,6 +1146,7 @@ struct net_device_ops {
81739 void *priv);
81740 int (*ndo_get_lock_subclass)(struct net_device *dev);
81741 };
81742 +typedef struct net_device_ops __no_const net_device_ops_no_const;
81743
81744 /**
81745 * enum net_device_priv_flags - &struct net_device priv_flags
81746 @@ -1313,11 +1314,11 @@ struct net_device {
81747 struct net_device_stats stats;
81748
81749 /* dropped packets by core network, Do not use this in drivers */
81750 - atomic_long_t rx_dropped;
81751 - atomic_long_t tx_dropped;
81752 + atomic_long_unchecked_t rx_dropped;
81753 + atomic_long_unchecked_t tx_dropped;
81754
81755 /* Stats to monitor carrier on<->off transitions */
81756 - atomic_t carrier_changes;
81757 + atomic_unchecked_t carrier_changes;
81758
81759 #ifdef CONFIG_WIRELESS_EXT
81760 /* List of functions to handle Wireless Extensions (instead of ioctl).
81761 diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
81762 index 2077489..a15e561 100644
81763 --- a/include/linux/netfilter.h
81764 +++ b/include/linux/netfilter.h
81765 @@ -84,7 +84,7 @@ struct nf_sockopt_ops {
81766 #endif
81767 /* Use the module struct to lock set/get code in place */
81768 struct module *owner;
81769 -};
81770 +} __do_const;
81771
81772 /* Function to register/unregister hook points. */
81773 int nf_register_hook(struct nf_hook_ops *reg);
81774 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
81775 index e955d47..04a5338 100644
81776 --- a/include/linux/netfilter/nfnetlink.h
81777 +++ b/include/linux/netfilter/nfnetlink.h
81778 @@ -19,7 +19,7 @@ struct nfnl_callback {
81779 const struct nlattr * const cda[]);
81780 const struct nla_policy *policy; /* netlink attribute policy */
81781 const u_int16_t attr_count; /* number of nlattr's */
81782 -};
81783 +} __do_const;
81784
81785 struct nfnetlink_subsystem {
81786 const char *name;
81787 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
81788 new file mode 100644
81789 index 0000000..33f4af8
81790 --- /dev/null
81791 +++ b/include/linux/netfilter/xt_gradm.h
81792 @@ -0,0 +1,9 @@
81793 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
81794 +#define _LINUX_NETFILTER_XT_GRADM_H 1
81795 +
81796 +struct xt_gradm_mtinfo {
81797 + __u16 flags;
81798 + __u16 invflags;
81799 +};
81800 +
81801 +#endif
81802 diff --git a/include/linux/nls.h b/include/linux/nls.h
81803 index 520681b..1d67ed2 100644
81804 --- a/include/linux/nls.h
81805 +++ b/include/linux/nls.h
81806 @@ -31,7 +31,7 @@ struct nls_table {
81807 const unsigned char *charset2upper;
81808 struct module *owner;
81809 struct nls_table *next;
81810 -};
81811 +} __do_const;
81812
81813 /* this value hold the maximum octet of charset */
81814 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
81815 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
81816 index d14a4c3..a078786 100644
81817 --- a/include/linux/notifier.h
81818 +++ b/include/linux/notifier.h
81819 @@ -54,7 +54,8 @@ struct notifier_block {
81820 notifier_fn_t notifier_call;
81821 struct notifier_block __rcu *next;
81822 int priority;
81823 -};
81824 +} __do_const;
81825 +typedef struct notifier_block __no_const notifier_block_no_const;
81826
81827 struct atomic_notifier_head {
81828 spinlock_t lock;
81829 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
81830 index b2a0f15..4d7da32 100644
81831 --- a/include/linux/oprofile.h
81832 +++ b/include/linux/oprofile.h
81833 @@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
81834 int oprofilefs_create_ro_ulong(struct dentry * root,
81835 char const * name, ulong * val);
81836
81837 -/** Create a file for read-only access to an atomic_t. */
81838 +/** Create a file for read-only access to an atomic_unchecked_t. */
81839 int oprofilefs_create_ro_atomic(struct dentry * root,
81840 - char const * name, atomic_t * val);
81841 + char const * name, atomic_unchecked_t * val);
81842
81843 /** create a directory */
81844 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
81845 diff --git a/include/linux/padata.h b/include/linux/padata.h
81846 index 4386946..f50c615 100644
81847 --- a/include/linux/padata.h
81848 +++ b/include/linux/padata.h
81849 @@ -129,7 +129,7 @@ struct parallel_data {
81850 struct padata_serial_queue __percpu *squeue;
81851 atomic_t reorder_objects;
81852 atomic_t refcnt;
81853 - atomic_t seq_nr;
81854 + atomic_unchecked_t seq_nr;
81855 struct padata_cpumask cpumask;
81856 spinlock_t lock ____cacheline_aligned;
81857 unsigned int processed;
81858 diff --git a/include/linux/path.h b/include/linux/path.h
81859 index d137218..be0c176 100644
81860 --- a/include/linux/path.h
81861 +++ b/include/linux/path.h
81862 @@ -1,13 +1,15 @@
81863 #ifndef _LINUX_PATH_H
81864 #define _LINUX_PATH_H
81865
81866 +#include <linux/compiler.h>
81867 +
81868 struct dentry;
81869 struct vfsmount;
81870
81871 struct path {
81872 struct vfsmount *mnt;
81873 struct dentry *dentry;
81874 -};
81875 +} __randomize_layout;
81876
81877 extern void path_get(const struct path *);
81878 extern void path_put(const struct path *);
81879 diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
81880 index 5f2e559..7d59314 100644
81881 --- a/include/linux/pci_hotplug.h
81882 +++ b/include/linux/pci_hotplug.h
81883 @@ -71,7 +71,8 @@ struct hotplug_slot_ops {
81884 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
81885 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
81886 int (*reset_slot) (struct hotplug_slot *slot, int probe);
81887 -};
81888 +} __do_const;
81889 +typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
81890
81891 /**
81892 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
81893 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
81894 index 3ef6ea1..ed1a248 100644
81895 --- a/include/linux/perf_event.h
81896 +++ b/include/linux/perf_event.h
81897 @@ -328,8 +328,8 @@ struct perf_event {
81898
81899 enum perf_event_active_state state;
81900 unsigned int attach_state;
81901 - local64_t count;
81902 - atomic64_t child_count;
81903 + local64_t count; /* PaX: fix it one day */
81904 + atomic64_unchecked_t child_count;
81905
81906 /*
81907 * These are the total time in nanoseconds that the event
81908 @@ -380,8 +380,8 @@ struct perf_event {
81909 * These accumulate total time (in nanoseconds) that children
81910 * events have been enabled and running, respectively.
81911 */
81912 - atomic64_t child_total_time_enabled;
81913 - atomic64_t child_total_time_running;
81914 + atomic64_unchecked_t child_total_time_enabled;
81915 + atomic64_unchecked_t child_total_time_running;
81916
81917 /*
81918 * Protect attach/detach and child_list:
81919 @@ -710,7 +710,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
81920 entry->ip[entry->nr++] = ip;
81921 }
81922
81923 -extern int sysctl_perf_event_paranoid;
81924 +extern int sysctl_perf_event_legitimately_concerned;
81925 extern int sysctl_perf_event_mlock;
81926 extern int sysctl_perf_event_sample_rate;
81927 extern int sysctl_perf_cpu_time_max_percent;
81928 @@ -725,19 +725,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
81929 loff_t *ppos);
81930
81931
81932 +static inline bool perf_paranoid_any(void)
81933 +{
81934 + return sysctl_perf_event_legitimately_concerned > 2;
81935 +}
81936 +
81937 static inline bool perf_paranoid_tracepoint_raw(void)
81938 {
81939 - return sysctl_perf_event_paranoid > -1;
81940 + return sysctl_perf_event_legitimately_concerned > -1;
81941 }
81942
81943 static inline bool perf_paranoid_cpu(void)
81944 {
81945 - return sysctl_perf_event_paranoid > 0;
81946 + return sysctl_perf_event_legitimately_concerned > 0;
81947 }
81948
81949 static inline bool perf_paranoid_kernel(void)
81950 {
81951 - return sysctl_perf_event_paranoid > 1;
81952 + return sysctl_perf_event_legitimately_concerned > 1;
81953 }
81954
81955 extern void perf_event_init(void);
81956 @@ -867,7 +872,7 @@ struct perf_pmu_events_attr {
81957 struct device_attribute attr;
81958 u64 id;
81959 const char *event_str;
81960 -};
81961 +} __do_const;
81962
81963 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
81964 static struct perf_pmu_events_attr _var = { \
81965 diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
81966 index 7246ef3..1539ea4 100644
81967 --- a/include/linux/pid_namespace.h
81968 +++ b/include/linux/pid_namespace.h
81969 @@ -43,7 +43,7 @@ struct pid_namespace {
81970 int hide_pid;
81971 int reboot; /* group exit code if this pidns was rebooted */
81972 unsigned int proc_inum;
81973 -};
81974 +} __randomize_layout;
81975
81976 extern struct pid_namespace init_pid_ns;
81977
81978 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
81979 index eb8b8ac..62649e1 100644
81980 --- a/include/linux/pipe_fs_i.h
81981 +++ b/include/linux/pipe_fs_i.h
81982 @@ -47,10 +47,10 @@ struct pipe_inode_info {
81983 struct mutex mutex;
81984 wait_queue_head_t wait;
81985 unsigned int nrbufs, curbuf, buffers;
81986 - unsigned int readers;
81987 - unsigned int writers;
81988 - unsigned int files;
81989 - unsigned int waiting_writers;
81990 + atomic_t readers;
81991 + atomic_t writers;
81992 + atomic_t files;
81993 + atomic_t waiting_writers;
81994 unsigned int r_counter;
81995 unsigned int w_counter;
81996 struct page *tmp_page;
81997 diff --git a/include/linux/pm.h b/include/linux/pm.h
81998 index d915d03..0531037 100644
81999 --- a/include/linux/pm.h
82000 +++ b/include/linux/pm.h
82001 @@ -600,6 +600,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
82002 struct dev_pm_domain {
82003 struct dev_pm_ops ops;
82004 };
82005 +typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
82006
82007 /*
82008 * The PM_EVENT_ messages are also used by drivers implementing the legacy
82009 diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
82010 index 7c1d252..0e7061d 100644
82011 --- a/include/linux/pm_domain.h
82012 +++ b/include/linux/pm_domain.h
82013 @@ -44,11 +44,11 @@ struct gpd_dev_ops {
82014 int (*thaw_early)(struct device *dev);
82015 int (*thaw)(struct device *dev);
82016 bool (*active_wakeup)(struct device *dev);
82017 -};
82018 +} __no_const;
82019
82020 struct gpd_cpu_data {
82021 unsigned int saved_exit_latency;
82022 - struct cpuidle_state *idle_state;
82023 + cpuidle_state_no_const *idle_state;
82024 };
82025
82026 struct generic_pm_domain {
82027 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
82028 index 2a5897a..4f9af63 100644
82029 --- a/include/linux/pm_runtime.h
82030 +++ b/include/linux/pm_runtime.h
82031 @@ -113,7 +113,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
82032
82033 static inline void pm_runtime_mark_last_busy(struct device *dev)
82034 {
82035 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
82036 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
82037 }
82038
82039 #else /* !CONFIG_PM_RUNTIME */
82040 diff --git a/include/linux/pnp.h b/include/linux/pnp.h
82041 index 195aafc..49a7bc2 100644
82042 --- a/include/linux/pnp.h
82043 +++ b/include/linux/pnp.h
82044 @@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
82045 struct pnp_fixup {
82046 char id[7];
82047 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
82048 -};
82049 +} __do_const;
82050
82051 /* config parameters */
82052 #define PNP_CONFIG_NORMAL 0x0001
82053 diff --git a/include/linux/poison.h b/include/linux/poison.h
82054 index 2110a81..13a11bb 100644
82055 --- a/include/linux/poison.h
82056 +++ b/include/linux/poison.h
82057 @@ -19,8 +19,8 @@
82058 * under normal circumstances, used to verify that nobody uses
82059 * non-initialized list entries.
82060 */
82061 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
82062 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
82063 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
82064 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
82065
82066 /********** include/linux/timer.h **********/
82067 /*
82068 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
82069 index d8b187c3..9a9257a 100644
82070 --- a/include/linux/power/smartreflex.h
82071 +++ b/include/linux/power/smartreflex.h
82072 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
82073 int (*notify)(struct omap_sr *sr, u32 status);
82074 u8 notify_flags;
82075 u8 class_type;
82076 -};
82077 +} __do_const;
82078
82079 /**
82080 * struct omap_sr_nvalue_table - Smartreflex n-target value info
82081 diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
82082 index 4ea1d37..80f4b33 100644
82083 --- a/include/linux/ppp-comp.h
82084 +++ b/include/linux/ppp-comp.h
82085 @@ -84,7 +84,7 @@ struct compressor {
82086 struct module *owner;
82087 /* Extra skb space needed by the compressor algorithm */
82088 unsigned int comp_extra;
82089 -};
82090 +} __do_const;
82091
82092 /*
82093 * The return value from decompress routine is the length of the
82094 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
82095 index de83b4e..c4b997d 100644
82096 --- a/include/linux/preempt.h
82097 +++ b/include/linux/preempt.h
82098 @@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
82099 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
82100 #endif
82101
82102 +#define raw_preempt_count_add(val) __preempt_count_add(val)
82103 +#define raw_preempt_count_sub(val) __preempt_count_sub(val)
82104 +
82105 #define __preempt_count_inc() __preempt_count_add(1)
82106 #define __preempt_count_dec() __preempt_count_sub(1)
82107
82108 #define preempt_count_inc() preempt_count_add(1)
82109 +#define raw_preempt_count_inc() raw_preempt_count_add(1)
82110 #define preempt_count_dec() preempt_count_sub(1)
82111 +#define raw_preempt_count_dec() raw_preempt_count_sub(1)
82112
82113 #ifdef CONFIG_PREEMPT_COUNT
82114
82115 @@ -41,6 +46,12 @@ do { \
82116 barrier(); \
82117 } while (0)
82118
82119 +#define raw_preempt_disable() \
82120 +do { \
82121 + raw_preempt_count_inc(); \
82122 + barrier(); \
82123 +} while (0)
82124 +
82125 #define sched_preempt_enable_no_resched() \
82126 do { \
82127 barrier(); \
82128 @@ -49,6 +60,12 @@ do { \
82129
82130 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
82131
82132 +#define raw_preempt_enable_no_resched() \
82133 +do { \
82134 + barrier(); \
82135 + raw_preempt_count_dec(); \
82136 +} while (0)
82137 +
82138 #ifdef CONFIG_PREEMPT
82139 #define preempt_enable() \
82140 do { \
82141 @@ -113,8 +130,10 @@ do { \
82142 * region.
82143 */
82144 #define preempt_disable() barrier()
82145 +#define raw_preempt_disable() barrier()
82146 #define sched_preempt_enable_no_resched() barrier()
82147 #define preempt_enable_no_resched() barrier()
82148 +#define raw_preempt_enable_no_resched() barrier()
82149 #define preempt_enable() barrier()
82150 #define preempt_check_resched() do { } while (0)
82151
82152 @@ -128,11 +147,13 @@ do { \
82153 /*
82154 * Modules have no business playing preemption tricks.
82155 */
82156 +#ifndef CONFIG_PAX_KERNEXEC
82157 #undef sched_preempt_enable_no_resched
82158 #undef preempt_enable_no_resched
82159 #undef preempt_enable_no_resched_notrace
82160 #undef preempt_check_resched
82161 #endif
82162 +#endif
82163
82164 #define preempt_set_need_resched() \
82165 do { \
82166 diff --git a/include/linux/printk.h b/include/linux/printk.h
82167 index 7847301..29cd406 100644
82168 --- a/include/linux/printk.h
82169 +++ b/include/linux/printk.h
82170 @@ -110,6 +110,8 @@ static inline __printf(1, 2) __cold
82171 void early_printk(const char *s, ...) { }
82172 #endif
82173
82174 +extern int kptr_restrict;
82175 +
82176 #ifdef CONFIG_PRINTK
82177 asmlinkage __printf(5, 0)
82178 int vprintk_emit(int facility, int level,
82179 @@ -144,7 +146,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
82180
82181 extern int printk_delay_msec;
82182 extern int dmesg_restrict;
82183 -extern int kptr_restrict;
82184
82185 extern void wake_up_klogd(void);
82186
82187 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
82188 index 608e60a..79cfb18 100644
82189 --- a/include/linux/proc_fs.h
82190 +++ b/include/linux/proc_fs.h
82191 @@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
82192 extern struct proc_dir_entry *proc_symlink(const char *,
82193 struct proc_dir_entry *, const char *);
82194 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
82195 +extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
82196 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
82197 struct proc_dir_entry *, void *);
82198 +extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
82199 + struct proc_dir_entry *, void *);
82200 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
82201 struct proc_dir_entry *);
82202
82203 @@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
82204 return proc_create_data(name, mode, parent, proc_fops, NULL);
82205 }
82206
82207 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
82208 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
82209 +{
82210 +#ifdef CONFIG_GRKERNSEC_PROC_USER
82211 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
82212 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
82213 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
82214 +#else
82215 + return proc_create_data(name, mode, parent, proc_fops, NULL);
82216 +#endif
82217 +}
82218 +
82219 +
82220 extern void proc_set_size(struct proc_dir_entry *, loff_t);
82221 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
82222 extern void *PDE_DATA(const struct inode *);
82223 @@ -52,8 +68,12 @@ static inline struct proc_dir_entry *proc_symlink(const char *name,
82224 struct proc_dir_entry *parent,const char *dest) { return NULL;}
82225 static inline struct proc_dir_entry *proc_mkdir(const char *name,
82226 struct proc_dir_entry *parent) {return NULL;}
82227 +static inline struct proc_dir_entry *proc_mkdir_restrict(const char *name,
82228 + struct proc_dir_entry *parent) { return NULL; }
82229 static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
82230 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
82231 +static inline struct proc_dir_entry *proc_mkdir_data_restrict(const char *name,
82232 + umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
82233 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
82234 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
82235 #define proc_create(name, mode, parent, proc_fops) ({NULL;})
82236 @@ -73,7 +93,7 @@ static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *p
82237 static inline struct proc_dir_entry *proc_net_mkdir(
82238 struct net *net, const char *name, struct proc_dir_entry *parent)
82239 {
82240 - return proc_mkdir_data(name, 0, parent, net);
82241 + return proc_mkdir_data_restrict(name, 0, parent, net);
82242 }
82243
82244 #endif /* _LINUX_PROC_FS_H */
82245 diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
82246 index 34a1e10..70f6bde 100644
82247 --- a/include/linux/proc_ns.h
82248 +++ b/include/linux/proc_ns.h
82249 @@ -14,7 +14,7 @@ struct proc_ns_operations {
82250 void (*put)(void *ns);
82251 int (*install)(struct nsproxy *nsproxy, void *ns);
82252 unsigned int (*inum)(void *ns);
82253 -};
82254 +} __do_const __randomize_layout;
82255
82256 struct proc_ns {
82257 void *ns;
82258 diff --git a/include/linux/quota.h b/include/linux/quota.h
82259 index cc7494a..1e27036 100644
82260 --- a/include/linux/quota.h
82261 +++ b/include/linux/quota.h
82262 @@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
82263
82264 extern bool qid_eq(struct kqid left, struct kqid right);
82265 extern bool qid_lt(struct kqid left, struct kqid right);
82266 -extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
82267 +extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
82268 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
82269 extern bool qid_valid(struct kqid qid);
82270
82271 diff --git a/include/linux/random.h b/include/linux/random.h
82272 index 57fbbff..2170304 100644
82273 --- a/include/linux/random.h
82274 +++ b/include/linux/random.h
82275 @@ -9,9 +9,19 @@
82276 #include <uapi/linux/random.h>
82277
82278 extern void add_device_randomness(const void *, unsigned int);
82279 +
82280 +static inline void add_latent_entropy(void)
82281 +{
82282 +
82283 +#ifdef LATENT_ENTROPY_PLUGIN
82284 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
82285 +#endif
82286 +
82287 +}
82288 +
82289 extern void add_input_randomness(unsigned int type, unsigned int code,
82290 - unsigned int value);
82291 -extern void add_interrupt_randomness(int irq, int irq_flags);
82292 + unsigned int value) __latent_entropy;
82293 +extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
82294
82295 extern void get_random_bytes(void *buf, int nbytes);
82296 extern void get_random_bytes_arch(void *buf, int nbytes);
82297 @@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
82298 extern const struct file_operations random_fops, urandom_fops;
82299 #endif
82300
82301 -unsigned int get_random_int(void);
82302 +unsigned int __intentional_overflow(-1) get_random_int(void);
82303 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
82304
82305 -u32 prandom_u32(void);
82306 +u32 prandom_u32(void) __intentional_overflow(-1);
82307 void prandom_bytes(void *buf, int nbytes);
82308 void prandom_seed(u32 seed);
82309 void prandom_reseed_late(void);
82310 @@ -37,6 +47,11 @@ struct rnd_state {
82311 u32 prandom_u32_state(struct rnd_state *state);
82312 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
82313
82314 +static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
82315 +{
82316 + return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
82317 +}
82318 +
82319 /**
82320 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
82321 * @ep_ro: right open interval endpoint
82322 @@ -49,7 +64,7 @@ void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
82323 *
82324 * Returns: pseudo-random number in interval [0, ep_ro)
82325 */
82326 -static inline u32 prandom_u32_max(u32 ep_ro)
82327 +static inline u32 __intentional_overflow(-1) prandom_u32_max(u32 ep_ro)
82328 {
82329 return (u32)(((u64) prandom_u32() * ep_ro) >> 32);
82330 }
82331 diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
82332 index fea49b5..2ac22bb 100644
82333 --- a/include/linux/rbtree_augmented.h
82334 +++ b/include/linux/rbtree_augmented.h
82335 @@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
82336 old->rbaugmented = rbcompute(old); \
82337 } \
82338 rbstatic const struct rb_augment_callbacks rbname = { \
82339 - rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
82340 + .propagate = rbname ## _propagate, \
82341 + .copy = rbname ## _copy, \
82342 + .rotate = rbname ## _rotate \
82343 };
82344
82345
82346 diff --git a/include/linux/rculist.h b/include/linux/rculist.h
82347 index 8183b46..a388711 100644
82348 --- a/include/linux/rculist.h
82349 +++ b/include/linux/rculist.h
82350 @@ -29,8 +29,8 @@
82351 */
82352 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
82353 {
82354 - ACCESS_ONCE(list->next) = list;
82355 - ACCESS_ONCE(list->prev) = list;
82356 + ACCESS_ONCE_RW(list->next) = list;
82357 + ACCESS_ONCE_RW(list->prev) = list;
82358 }
82359
82360 /*
82361 @@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
82362 struct list_head *prev, struct list_head *next);
82363 #endif
82364
82365 +void __pax_list_add_rcu(struct list_head *new,
82366 + struct list_head *prev, struct list_head *next);
82367 +
82368 /**
82369 * list_add_rcu - add a new entry to rcu-protected list
82370 * @new: new entry to be added
82371 @@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
82372 __list_add_rcu(new, head, head->next);
82373 }
82374
82375 +static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
82376 +{
82377 + __pax_list_add_rcu(new, head, head->next);
82378 +}
82379 +
82380 /**
82381 * list_add_tail_rcu - add a new entry to rcu-protected list
82382 * @new: new entry to be added
82383 @@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
82384 __list_add_rcu(new, head->prev, head);
82385 }
82386
82387 +static inline void pax_list_add_tail_rcu(struct list_head *new,
82388 + struct list_head *head)
82389 +{
82390 + __pax_list_add_rcu(new, head->prev, head);
82391 +}
82392 +
82393 /**
82394 * list_del_rcu - deletes entry from list without re-initialization
82395 * @entry: the element to delete from the list.
82396 @@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
82397 entry->prev = LIST_POISON2;
82398 }
82399
82400 +extern void pax_list_del_rcu(struct list_head *entry);
82401 +
82402 /**
82403 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
82404 * @n: the element to delete from the hash list.
82405 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
82406 index 48bf152..d38b785 100644
82407 --- a/include/linux/reboot.h
82408 +++ b/include/linux/reboot.h
82409 @@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
82410 */
82411
82412 extern void migrate_to_reboot_cpu(void);
82413 -extern void machine_restart(char *cmd);
82414 -extern void machine_halt(void);
82415 -extern void machine_power_off(void);
82416 +extern void machine_restart(char *cmd) __noreturn;
82417 +extern void machine_halt(void) __noreturn;
82418 +extern void machine_power_off(void) __noreturn;
82419
82420 extern void machine_shutdown(void);
82421 struct pt_regs;
82422 @@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
82423 */
82424
82425 extern void kernel_restart_prepare(char *cmd);
82426 -extern void kernel_restart(char *cmd);
82427 -extern void kernel_halt(void);
82428 -extern void kernel_power_off(void);
82429 +extern void kernel_restart(char *cmd) __noreturn;
82430 +extern void kernel_halt(void) __noreturn;
82431 +extern void kernel_power_off(void) __noreturn;
82432
82433 extern int C_A_D; /* for sysctl */
82434 void ctrl_alt_del(void);
82435 @@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
82436 * Emergency restart, callable from an interrupt handler.
82437 */
82438
82439 -extern void emergency_restart(void);
82440 +extern void emergency_restart(void) __noreturn;
82441 #include <asm/emergency-restart.h>
82442
82443 #endif /* _LINUX_REBOOT_H */
82444 diff --git a/include/linux/regset.h b/include/linux/regset.h
82445 index 8e0c9fe..ac4d221 100644
82446 --- a/include/linux/regset.h
82447 +++ b/include/linux/regset.h
82448 @@ -161,7 +161,8 @@ struct user_regset {
82449 unsigned int align;
82450 unsigned int bias;
82451 unsigned int core_note_type;
82452 -};
82453 +} __do_const;
82454 +typedef struct user_regset __no_const user_regset_no_const;
82455
82456 /**
82457 * struct user_regset_view - available regsets
82458 diff --git a/include/linux/relay.h b/include/linux/relay.h
82459 index d7c8359..818daf5 100644
82460 --- a/include/linux/relay.h
82461 +++ b/include/linux/relay.h
82462 @@ -157,7 +157,7 @@ struct rchan_callbacks
82463 * The callback should return 0 if successful, negative if not.
82464 */
82465 int (*remove_buf_file)(struct dentry *dentry);
82466 -};
82467 +} __no_const;
82468
82469 /*
82470 * CONFIG_RELAY kernel API, kernel/relay.c
82471 diff --git a/include/linux/rio.h b/include/linux/rio.h
82472 index 6bda06f..bf39a9b 100644
82473 --- a/include/linux/rio.h
82474 +++ b/include/linux/rio.h
82475 @@ -358,7 +358,7 @@ struct rio_ops {
82476 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
82477 u64 rstart, u32 size, u32 flags);
82478 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
82479 -};
82480 +} __no_const;
82481
82482 #define RIO_RESOURCE_MEM 0x00000100
82483 #define RIO_RESOURCE_DOORBELL 0x00000200
82484 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
82485 index b66c211..13d2915 100644
82486 --- a/include/linux/rmap.h
82487 +++ b/include/linux/rmap.h
82488 @@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
82489 void anon_vma_init(void); /* create anon_vma_cachep */
82490 int anon_vma_prepare(struct vm_area_struct *);
82491 void unlink_anon_vmas(struct vm_area_struct *);
82492 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
82493 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
82494 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
82495 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
82496
82497 static inline void anon_vma_merge(struct vm_area_struct *vma,
82498 struct vm_area_struct *next)
82499 diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
82500 index a964f72..b475afb 100644
82501 --- a/include/linux/scatterlist.h
82502 +++ b/include/linux/scatterlist.h
82503 @@ -1,6 +1,7 @@
82504 #ifndef _LINUX_SCATTERLIST_H
82505 #define _LINUX_SCATTERLIST_H
82506
82507 +#include <linux/sched.h>
82508 #include <linux/string.h>
82509 #include <linux/bug.h>
82510 #include <linux/mm.h>
82511 @@ -114,6 +115,12 @@ static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
82512 #ifdef CONFIG_DEBUG_SG
82513 BUG_ON(!virt_addr_valid(buf));
82514 #endif
82515 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
82516 + if (object_starts_on_stack(buf)) {
82517 + void *adjbuf = buf - current->stack + current->lowmem_stack;
82518 + sg_set_page(sg, virt_to_page(adjbuf), buflen, offset_in_page(adjbuf));
82519 + } else
82520 +#endif
82521 sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
82522 }
82523
82524 diff --git a/include/linux/sched.h b/include/linux/sched.h
82525 index 221b2bd..e2e5f82 100644
82526 --- a/include/linux/sched.h
82527 +++ b/include/linux/sched.h
82528 @@ -131,6 +131,7 @@ struct fs_struct;
82529 struct perf_event_context;
82530 struct blk_plug;
82531 struct filename;
82532 +struct linux_binprm;
82533
82534 #define VMACACHE_BITS 2
82535 #define VMACACHE_SIZE (1U << VMACACHE_BITS)
82536 @@ -380,7 +381,7 @@ extern char __sched_text_start[], __sched_text_end[];
82537 extern int in_sched_functions(unsigned long addr);
82538
82539 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
82540 -extern signed long schedule_timeout(signed long timeout);
82541 +extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
82542 extern signed long schedule_timeout_interruptible(signed long timeout);
82543 extern signed long schedule_timeout_killable(signed long timeout);
82544 extern signed long schedule_timeout_uninterruptible(signed long timeout);
82545 @@ -391,6 +392,19 @@ struct nsproxy;
82546 struct user_namespace;
82547
82548 #ifdef CONFIG_MMU
82549 +
82550 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
82551 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
82552 +#else
82553 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
82554 +{
82555 + return 0;
82556 +}
82557 +#endif
82558 +
82559 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
82560 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
82561 +
82562 extern void arch_pick_mmap_layout(struct mm_struct *mm);
82563 extern unsigned long
82564 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
82565 @@ -688,6 +702,17 @@ struct signal_struct {
82566 #ifdef CONFIG_TASKSTATS
82567 struct taskstats *stats;
82568 #endif
82569 +
82570 +#ifdef CONFIG_GRKERNSEC
82571 + u32 curr_ip;
82572 + u32 saved_ip;
82573 + u32 gr_saddr;
82574 + u32 gr_daddr;
82575 + u16 gr_sport;
82576 + u16 gr_dport;
82577 + u8 used_accept:1;
82578 +#endif
82579 +
82580 #ifdef CONFIG_AUDIT
82581 unsigned audit_tty;
82582 unsigned audit_tty_log_passwd;
82583 @@ -714,7 +739,7 @@ struct signal_struct {
82584 struct mutex cred_guard_mutex; /* guard against foreign influences on
82585 * credential calculations
82586 * (notably. ptrace) */
82587 -};
82588 +} __randomize_layout;
82589
82590 /*
82591 * Bits in flags field of signal_struct.
82592 @@ -768,6 +793,14 @@ struct user_struct {
82593 struct key *session_keyring; /* UID's default session keyring */
82594 #endif
82595
82596 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
82597 + unsigned char kernel_banned;
82598 +#endif
82599 +#ifdef CONFIG_GRKERNSEC_BRUTE
82600 + unsigned char suid_banned;
82601 + unsigned long suid_ban_expires;
82602 +#endif
82603 +
82604 /* Hash table maintenance information */
82605 struct hlist_node uidhash_node;
82606 kuid_t uid;
82607 @@ -775,7 +808,7 @@ struct user_struct {
82608 #ifdef CONFIG_PERF_EVENTS
82609 atomic_long_t locked_vm;
82610 #endif
82611 -};
82612 +} __randomize_layout;
82613
82614 extern int uids_sysfs_init(void);
82615
82616 @@ -1179,6 +1212,9 @@ enum perf_event_task_context {
82617 struct task_struct {
82618 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
82619 void *stack;
82620 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
82621 + void *lowmem_stack;
82622 +#endif
82623 atomic_t usage;
82624 unsigned int flags; /* per process flags, defined below */
82625 unsigned int ptrace;
82626 @@ -1304,8 +1340,8 @@ struct task_struct {
82627 struct list_head thread_node;
82628
82629 struct completion *vfork_done; /* for vfork() */
82630 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
82631 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
82632 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
82633 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
82634
82635 cputime_t utime, stime, utimescaled, stimescaled;
82636 cputime_t gtime;
82637 @@ -1330,11 +1366,6 @@ struct task_struct {
82638 struct task_cputime cputime_expires;
82639 struct list_head cpu_timers[3];
82640
82641 -/* process credentials */
82642 - const struct cred __rcu *real_cred; /* objective and real subjective task
82643 - * credentials (COW) */
82644 - const struct cred __rcu *cred; /* effective (overridable) subjective task
82645 - * credentials (COW) */
82646 char comm[TASK_COMM_LEN]; /* executable name excluding path
82647 - access with [gs]et_task_comm (which lock
82648 it with task_lock())
82649 @@ -1351,6 +1382,10 @@ struct task_struct {
82650 #endif
82651 /* CPU-specific state of this task */
82652 struct thread_struct thread;
82653 +/* thread_info moved to task_struct */
82654 +#ifdef CONFIG_X86
82655 + struct thread_info tinfo;
82656 +#endif
82657 /* filesystem information */
82658 struct fs_struct *fs;
82659 /* open file information */
82660 @@ -1427,6 +1462,10 @@ struct task_struct {
82661 gfp_t lockdep_reclaim_gfp;
82662 #endif
82663
82664 +/* process credentials */
82665 + const struct cred __rcu *real_cred; /* objective and real subjective task
82666 + * credentials (COW) */
82667 +
82668 /* journalling filesystem info */
82669 void *journal_info;
82670
82671 @@ -1465,6 +1504,10 @@ struct task_struct {
82672 /* cg_list protected by css_set_lock and tsk->alloc_lock */
82673 struct list_head cg_list;
82674 #endif
82675 +
82676 + const struct cred __rcu *cred; /* effective (overridable) subjective task
82677 + * credentials (COW) */
82678 +
82679 #ifdef CONFIG_FUTEX
82680 struct robust_list_head __user *robust_list;
82681 #ifdef CONFIG_COMPAT
82682 @@ -1610,7 +1653,78 @@ struct task_struct {
82683 unsigned int sequential_io;
82684 unsigned int sequential_io_avg;
82685 #endif
82686 -};
82687 +
82688 +#ifdef CONFIG_GRKERNSEC
82689 + /* grsecurity */
82690 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
82691 + u64 exec_id;
82692 +#endif
82693 +#ifdef CONFIG_GRKERNSEC_SETXID
82694 + const struct cred *delayed_cred;
82695 +#endif
82696 + struct dentry *gr_chroot_dentry;
82697 + struct acl_subject_label *acl;
82698 + struct acl_subject_label *tmpacl;
82699 + struct acl_role_label *role;
82700 + struct file *exec_file;
82701 + unsigned long brute_expires;
82702 + u16 acl_role_id;
82703 + u8 inherited;
82704 + /* is this the task that authenticated to the special role */
82705 + u8 acl_sp_role;
82706 + u8 is_writable;
82707 + u8 brute;
82708 + u8 gr_is_chrooted;
82709 +#endif
82710 +
82711 +} __randomize_layout;
82712 +
82713 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
82714 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
82715 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
82716 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
82717 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
82718 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
82719 +
82720 +#ifdef CONFIG_PAX_SOFTMODE
82721 +extern int pax_softmode;
82722 +#endif
82723 +
82724 +extern int pax_check_flags(unsigned long *);
82725 +#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
82726 +
82727 +/* if tsk != current then task_lock must be held on it */
82728 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
82729 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
82730 +{
82731 + if (likely(tsk->mm))
82732 + return tsk->mm->pax_flags;
82733 + else
82734 + return 0UL;
82735 +}
82736 +
82737 +/* if tsk != current then task_lock must be held on it */
82738 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
82739 +{
82740 + if (likely(tsk->mm)) {
82741 + tsk->mm->pax_flags = flags;
82742 + return 0;
82743 + }
82744 + return -EINVAL;
82745 +}
82746 +#endif
82747 +
82748 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
82749 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
82750 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
82751 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
82752 +#endif
82753 +
82754 +struct path;
82755 +extern char *pax_get_path(const struct path *path, char *buf, int buflen);
82756 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
82757 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
82758 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
82759
82760 /* Future-safe accessor for struct task_struct's cpus_allowed. */
82761 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
82762 @@ -1692,7 +1806,7 @@ struct pid_namespace;
82763 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
82764 struct pid_namespace *ns);
82765
82766 -static inline pid_t task_pid_nr(struct task_struct *tsk)
82767 +static inline pid_t task_pid_nr(const struct task_struct *tsk)
82768 {
82769 return tsk->pid;
82770 }
82771 @@ -2039,6 +2153,25 @@ extern u64 sched_clock_cpu(int cpu);
82772
82773 extern void sched_clock_init(void);
82774
82775 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
82776 +static inline void populate_stack(void)
82777 +{
82778 + struct task_struct *curtask = current;
82779 + int c;
82780 + int *ptr = curtask->stack;
82781 + int *end = curtask->stack + THREAD_SIZE;
82782 +
82783 + while (ptr < end) {
82784 + c = *(volatile int *)ptr;
82785 + ptr += PAGE_SIZE/sizeof(int);
82786 + }
82787 +}
82788 +#else
82789 +static inline void populate_stack(void)
82790 +{
82791 +}
82792 +#endif
82793 +
82794 #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
82795 static inline void sched_clock_tick(void)
82796 {
82797 @@ -2172,7 +2305,9 @@ void yield(void);
82798 extern struct exec_domain default_exec_domain;
82799
82800 union thread_union {
82801 +#ifndef CONFIG_X86
82802 struct thread_info thread_info;
82803 +#endif
82804 unsigned long stack[THREAD_SIZE/sizeof(long)];
82805 };
82806
82807 @@ -2205,6 +2340,7 @@ extern struct pid_namespace init_pid_ns;
82808 */
82809
82810 extern struct task_struct *find_task_by_vpid(pid_t nr);
82811 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
82812 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
82813 struct pid_namespace *ns);
82814
82815 @@ -2367,7 +2503,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
82816 extern void exit_itimers(struct signal_struct *);
82817 extern void flush_itimer_signals(void);
82818
82819 -extern void do_group_exit(int);
82820 +extern __noreturn void do_group_exit(int);
82821
82822 extern int allow_signal(int);
82823 extern int disallow_signal(int);
82824 @@ -2568,9 +2704,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
82825
82826 #endif
82827
82828 -static inline int object_is_on_stack(void *obj)
82829 +static inline int object_starts_on_stack(const void *obj)
82830 {
82831 - void *stack = task_stack_page(current);
82832 + const void *stack = task_stack_page(current);
82833
82834 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
82835 }
82836 diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
82837 index 8045a55..c959cd5 100644
82838 --- a/include/linux/sched/sysctl.h
82839 +++ b/include/linux/sched/sysctl.h
82840 @@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
82841 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
82842
82843 extern int sysctl_max_map_count;
82844 +extern unsigned long sysctl_heap_stack_gap;
82845
82846 extern unsigned int sysctl_sched_latency;
82847 extern unsigned int sysctl_sched_min_granularity;
82848 diff --git a/include/linux/security.h b/include/linux/security.h
82849 index 6478ce3..5e6ad6e 100644
82850 --- a/include/linux/security.h
82851 +++ b/include/linux/security.h
82852 @@ -27,6 +27,7 @@
82853 #include <linux/slab.h>
82854 #include <linux/err.h>
82855 #include <linux/string.h>
82856 +#include <linux/grsecurity.h>
82857
82858 struct linux_binprm;
82859 struct cred;
82860 @@ -116,8 +117,6 @@ struct seq_file;
82861
82862 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
82863
82864 -void reset_security_ops(void);
82865 -
82866 #ifdef CONFIG_MMU
82867 extern unsigned long mmap_min_addr;
82868 extern unsigned long dac_mmap_min_addr;
82869 @@ -1719,7 +1718,7 @@ struct security_operations {
82870 struct audit_context *actx);
82871 void (*audit_rule_free) (void *lsmrule);
82872 #endif /* CONFIG_AUDIT */
82873 -};
82874 +} __randomize_layout;
82875
82876 /* prototypes */
82877 extern int security_init(void);
82878 diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
82879 index dc368b8..e895209 100644
82880 --- a/include/linux/semaphore.h
82881 +++ b/include/linux/semaphore.h
82882 @@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
82883 }
82884
82885 extern void down(struct semaphore *sem);
82886 -extern int __must_check down_interruptible(struct semaphore *sem);
82887 +extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
82888 extern int __must_check down_killable(struct semaphore *sem);
82889 extern int __must_check down_trylock(struct semaphore *sem);
82890 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
82891 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
82892 index 52e0097..383f21d 100644
82893 --- a/include/linux/seq_file.h
82894 +++ b/include/linux/seq_file.h
82895 @@ -27,6 +27,9 @@ struct seq_file {
82896 struct mutex lock;
82897 const struct seq_operations *op;
82898 int poll_event;
82899 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
82900 + u64 exec_id;
82901 +#endif
82902 #ifdef CONFIG_USER_NS
82903 struct user_namespace *user_ns;
82904 #endif
82905 @@ -39,6 +42,7 @@ struct seq_operations {
82906 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
82907 int (*show) (struct seq_file *m, void *v);
82908 };
82909 +typedef struct seq_operations __no_const seq_operations_no_const;
82910
82911 #define SEQ_SKIP 1
82912
82913 @@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
82914
82915 char *mangle_path(char *s, const char *p, const char *esc);
82916 int seq_open(struct file *, const struct seq_operations *);
82917 +int seq_open_restrict(struct file *, const struct seq_operations *);
82918 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
82919 loff_t seq_lseek(struct file *, loff_t, int);
82920 int seq_release(struct inode *, struct file *);
82921 @@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
82922 }
82923
82924 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
82925 +int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
82926 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
82927 int single_release(struct inode *, struct file *);
82928 void *__seq_open_private(struct file *, const struct seq_operations *, int);
82929 diff --git a/include/linux/shm.h b/include/linux/shm.h
82930 index 1e2cd2e..0288750 100644
82931 --- a/include/linux/shm.h
82932 +++ b/include/linux/shm.h
82933 @@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
82934
82935 /* The task created the shm object. NULL if the task is dead. */
82936 struct task_struct *shm_creator;
82937 +#ifdef CONFIG_GRKERNSEC
82938 + time_t shm_createtime;
82939 + pid_t shm_lapid;
82940 +#endif
82941 };
82942
82943 /* shm_mode upper byte flags */
82944 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
82945 index 08074a8..e2ae280 100644
82946 --- a/include/linux/skbuff.h
82947 +++ b/include/linux/skbuff.h
82948 @@ -717,7 +717,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
82949 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
82950 int node);
82951 struct sk_buff *build_skb(void *data, unsigned int frag_size);
82952 -static inline struct sk_buff *alloc_skb(unsigned int size,
82953 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
82954 gfp_t priority)
82955 {
82956 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
82957 @@ -1825,7 +1825,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
82958 return skb->inner_transport_header - skb->inner_network_header;
82959 }
82960
82961 -static inline int skb_network_offset(const struct sk_buff *skb)
82962 +static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
82963 {
82964 return skb_network_header(skb) - skb->data;
82965 }
82966 @@ -1885,7 +1885,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
82967 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
82968 */
82969 #ifndef NET_SKB_PAD
82970 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
82971 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
82972 #endif
82973
82974 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
82975 @@ -2484,7 +2484,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
82976 int *err);
82977 unsigned int datagram_poll(struct file *file, struct socket *sock,
82978 struct poll_table_struct *wait);
82979 -int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
82980 +int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
82981 struct iovec *to, int size);
82982 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
82983 struct iovec *iov);
82984 @@ -2776,6 +2776,9 @@ static inline void nf_reset(struct sk_buff *skb)
82985 nf_bridge_put(skb->nf_bridge);
82986 skb->nf_bridge = NULL;
82987 #endif
82988 +#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
82989 + skb->nf_trace = 0;
82990 +#endif
82991 }
82992
82993 static inline void nf_reset_trace(struct sk_buff *skb)
82994 diff --git a/include/linux/slab.h b/include/linux/slab.h
82995 index 307bfbe..a999cf3 100644
82996 --- a/include/linux/slab.h
82997 +++ b/include/linux/slab.h
82998 @@ -14,15 +14,29 @@
82999 #include <linux/gfp.h>
83000 #include <linux/types.h>
83001 #include <linux/workqueue.h>
83002 -
83003 +#include <linux/err.h>
83004
83005 /*
83006 * Flags to pass to kmem_cache_create().
83007 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
83008 */
83009 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
83010 +
83011 +#ifdef CONFIG_PAX_USERCOPY_SLABS
83012 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
83013 +#else
83014 +#define SLAB_USERCOPY 0x00000000UL
83015 +#endif
83016 +
83017 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
83018 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
83019 +
83020 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
83021 +#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
83022 +#else
83023 +#define SLAB_NO_SANITIZE 0x00000000UL
83024 +#endif
83025 +
83026 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
83027 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
83028 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
83029 @@ -98,10 +112,13 @@
83030 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
83031 * Both make kfree a no-op.
83032 */
83033 -#define ZERO_SIZE_PTR ((void *)16)
83034 +#define ZERO_SIZE_PTR \
83035 +({ \
83036 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
83037 + (void *)(-MAX_ERRNO-1L); \
83038 +})
83039
83040 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
83041 - (unsigned long)ZERO_SIZE_PTR)
83042 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
83043
83044 #include <linux/kmemleak.h>
83045
83046 @@ -142,6 +159,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
83047 void kfree(const void *);
83048 void kzfree(const void *);
83049 size_t ksize(const void *);
83050 +const char *check_heap_object(const void *ptr, unsigned long n);
83051 +bool is_usercopy_object(const void *ptr);
83052
83053 /*
83054 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
83055 @@ -174,7 +193,7 @@ struct kmem_cache {
83056 unsigned int align; /* Alignment as calculated */
83057 unsigned long flags; /* Active flags on the slab */
83058 const char *name; /* Slab name for sysfs */
83059 - int refcount; /* Use counter */
83060 + atomic_t refcount; /* Use counter */
83061 void (*ctor)(void *); /* Called on object slot creation */
83062 struct list_head list; /* List of all slab caches on the system */
83063 };
83064 @@ -259,6 +278,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
83065 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
83066 #endif
83067
83068 +#ifdef CONFIG_PAX_USERCOPY_SLABS
83069 +extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
83070 +#endif
83071 +
83072 /*
83073 * Figure out which kmalloc slab an allocation of a certain size
83074 * belongs to.
83075 @@ -267,7 +290,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
83076 * 2 = 120 .. 192 bytes
83077 * n = 2^(n-1) .. 2^n -1
83078 */
83079 -static __always_inline int kmalloc_index(size_t size)
83080 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
83081 {
83082 if (!size)
83083 return 0;
83084 @@ -310,11 +333,11 @@ static __always_inline int kmalloc_index(size_t size)
83085 }
83086 #endif /* !CONFIG_SLOB */
83087
83088 -void *__kmalloc(size_t size, gfp_t flags);
83089 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
83090 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
83091
83092 #ifdef CONFIG_NUMA
83093 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
83094 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
83095 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
83096 #else
83097 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
83098 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
83099 index 8235dfb..47ce586 100644
83100 --- a/include/linux/slab_def.h
83101 +++ b/include/linux/slab_def.h
83102 @@ -38,7 +38,7 @@ struct kmem_cache {
83103 /* 4) cache creation/removal */
83104 const char *name;
83105 struct list_head list;
83106 - int refcount;
83107 + atomic_t refcount;
83108 int object_size;
83109 int align;
83110
83111 @@ -54,10 +54,14 @@ struct kmem_cache {
83112 unsigned long node_allocs;
83113 unsigned long node_frees;
83114 unsigned long node_overflow;
83115 - atomic_t allochit;
83116 - atomic_t allocmiss;
83117 - atomic_t freehit;
83118 - atomic_t freemiss;
83119 + atomic_unchecked_t allochit;
83120 + atomic_unchecked_t allocmiss;
83121 + atomic_unchecked_t freehit;
83122 + atomic_unchecked_t freemiss;
83123 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
83124 + atomic_unchecked_t sanitized;
83125 + atomic_unchecked_t not_sanitized;
83126 +#endif
83127
83128 /*
83129 * If debugging is enabled, then the allocator can add additional
83130 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
83131 index d82abd4..408c3a0 100644
83132 --- a/include/linux/slub_def.h
83133 +++ b/include/linux/slub_def.h
83134 @@ -74,7 +74,7 @@ struct kmem_cache {
83135 struct kmem_cache_order_objects max;
83136 struct kmem_cache_order_objects min;
83137 gfp_t allocflags; /* gfp flags to use on each alloc */
83138 - int refcount; /* Refcount for slab cache destroy */
83139 + atomic_t refcount; /* Refcount for slab cache destroy */
83140 void (*ctor)(void *);
83141 int inuse; /* Offset to metadata */
83142 int align; /* Alignment */
83143 diff --git a/include/linux/smp.h b/include/linux/smp.h
83144 index 633f5ed..6c3dc3f 100644
83145 --- a/include/linux/smp.h
83146 +++ b/include/linux/smp.h
83147 @@ -176,7 +176,9 @@ static inline void kick_all_cpus_sync(void) { }
83148 #endif
83149
83150 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
83151 +#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
83152 #define put_cpu() preempt_enable()
83153 +#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
83154
83155 /*
83156 * Callback to arch code if there's nosmp or maxcpus=0 on the
83157 diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
83158 index 46cca4c..3323536 100644
83159 --- a/include/linux/sock_diag.h
83160 +++ b/include/linux/sock_diag.h
83161 @@ -11,7 +11,7 @@ struct sock;
83162 struct sock_diag_handler {
83163 __u8 family;
83164 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
83165 -};
83166 +} __do_const;
83167
83168 int sock_diag_register(const struct sock_diag_handler *h);
83169 void sock_diag_unregister(const struct sock_diag_handler *h);
83170 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
83171 index 680f9a3..f13aeb0 100644
83172 --- a/include/linux/sonet.h
83173 +++ b/include/linux/sonet.h
83174 @@ -7,7 +7,7 @@
83175 #include <uapi/linux/sonet.h>
83176
83177 struct k_sonet_stats {
83178 -#define __HANDLE_ITEM(i) atomic_t i
83179 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
83180 __SONET_ITEMS
83181 #undef __HANDLE_ITEM
83182 };
83183 diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
83184 index 07d8e53..dc934c9 100644
83185 --- a/include/linux/sunrpc/addr.h
83186 +++ b/include/linux/sunrpc/addr.h
83187 @@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
83188 {
83189 switch (sap->sa_family) {
83190 case AF_INET:
83191 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
83192 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
83193 case AF_INET6:
83194 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
83195 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
83196 }
83197 return 0;
83198 }
83199 @@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
83200 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
83201 const struct sockaddr *src)
83202 {
83203 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
83204 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
83205 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
83206
83207 dsin->sin_family = ssin->sin_family;
83208 @@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
83209 if (sa->sa_family != AF_INET6)
83210 return 0;
83211
83212 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
83213 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
83214 }
83215
83216 #endif /* _LINUX_SUNRPC_ADDR_H */
83217 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
83218 index 70736b9..37f33db 100644
83219 --- a/include/linux/sunrpc/clnt.h
83220 +++ b/include/linux/sunrpc/clnt.h
83221 @@ -97,7 +97,7 @@ struct rpc_procinfo {
83222 unsigned int p_timer; /* Which RTT timer to use */
83223 u32 p_statidx; /* Which procedure to account */
83224 const char * p_name; /* name of procedure */
83225 -};
83226 +} __do_const;
83227
83228 #ifdef __KERNEL__
83229
83230 diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
83231 index 04e7632..2e2a8a3 100644
83232 --- a/include/linux/sunrpc/svc.h
83233 +++ b/include/linux/sunrpc/svc.h
83234 @@ -412,7 +412,7 @@ struct svc_procedure {
83235 unsigned int pc_count; /* call count */
83236 unsigned int pc_cachetype; /* cache info (NFS) */
83237 unsigned int pc_xdrressize; /* maximum size of XDR reply */
83238 -};
83239 +} __do_const;
83240
83241 /*
83242 * Function prototypes.
83243 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
83244 index 0b8e3e6..33e0a01 100644
83245 --- a/include/linux/sunrpc/svc_rdma.h
83246 +++ b/include/linux/sunrpc/svc_rdma.h
83247 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
83248 extern unsigned int svcrdma_max_requests;
83249 extern unsigned int svcrdma_max_req_size;
83250
83251 -extern atomic_t rdma_stat_recv;
83252 -extern atomic_t rdma_stat_read;
83253 -extern atomic_t rdma_stat_write;
83254 -extern atomic_t rdma_stat_sq_starve;
83255 -extern atomic_t rdma_stat_rq_starve;
83256 -extern atomic_t rdma_stat_rq_poll;
83257 -extern atomic_t rdma_stat_rq_prod;
83258 -extern atomic_t rdma_stat_sq_poll;
83259 -extern atomic_t rdma_stat_sq_prod;
83260 +extern atomic_unchecked_t rdma_stat_recv;
83261 +extern atomic_unchecked_t rdma_stat_read;
83262 +extern atomic_unchecked_t rdma_stat_write;
83263 +extern atomic_unchecked_t rdma_stat_sq_starve;
83264 +extern atomic_unchecked_t rdma_stat_rq_starve;
83265 +extern atomic_unchecked_t rdma_stat_rq_poll;
83266 +extern atomic_unchecked_t rdma_stat_rq_prod;
83267 +extern atomic_unchecked_t rdma_stat_sq_poll;
83268 +extern atomic_unchecked_t rdma_stat_sq_prod;
83269
83270 #define RPCRDMA_VERSION 1
83271
83272 diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
83273 index 8d71d65..f79586e 100644
83274 --- a/include/linux/sunrpc/svcauth.h
83275 +++ b/include/linux/sunrpc/svcauth.h
83276 @@ -120,7 +120,7 @@ struct auth_ops {
83277 int (*release)(struct svc_rqst *rq);
83278 void (*domain_release)(struct auth_domain *);
83279 int (*set_client)(struct svc_rqst *rq);
83280 -};
83281 +} __do_const;
83282
83283 #define SVC_GARBAGE 1
83284 #define SVC_SYSERR 2
83285 diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
83286 index a5ffd32..0935dea 100644
83287 --- a/include/linux/swiotlb.h
83288 +++ b/include/linux/swiotlb.h
83289 @@ -60,7 +60,8 @@ extern void
83290
83291 extern void
83292 swiotlb_free_coherent(struct device *hwdev, size_t size,
83293 - void *vaddr, dma_addr_t dma_handle);
83294 + void *vaddr, dma_addr_t dma_handle,
83295 + struct dma_attrs *attrs);
83296
83297 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
83298 unsigned long offset, size_t size,
83299 diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
83300 index a4a0588..752870e 100644
83301 --- a/include/linux/syscalls.h
83302 +++ b/include/linux/syscalls.h
83303 @@ -98,10 +98,16 @@ struct sigaltstack;
83304 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
83305
83306 #define __SC_DECL(t, a) t a
83307 +#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))
83308 #define __TYPE_IS_L(t) (__same_type((t)0, 0L))
83309 #define __TYPE_IS_UL(t) (__same_type((t)0, 0UL))
83310 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
83311 -#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
83312 +#define __SC_LONG(t, a) __typeof( \
83313 + __builtin_choose_expr( \
83314 + sizeof(t) > sizeof(int), \
83315 + (t) 0, \
83316 + __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
83317 + )) a
83318 #define __SC_CAST(t, a) (t) a
83319 #define __SC_ARGS(t, a) a
83320 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
83321 @@ -379,11 +385,11 @@ asmlinkage long sys_sync(void);
83322 asmlinkage long sys_fsync(unsigned int fd);
83323 asmlinkage long sys_fdatasync(unsigned int fd);
83324 asmlinkage long sys_bdflush(int func, long data);
83325 -asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
83326 - char __user *type, unsigned long flags,
83327 +asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
83328 + const char __user *type, unsigned long flags,
83329 void __user *data);
83330 -asmlinkage long sys_umount(char __user *name, int flags);
83331 -asmlinkage long sys_oldumount(char __user *name);
83332 +asmlinkage long sys_umount(const char __user *name, int flags);
83333 +asmlinkage long sys_oldumount(const char __user *name);
83334 asmlinkage long sys_truncate(const char __user *path, long length);
83335 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
83336 asmlinkage long sys_stat(const char __user *filename,
83337 @@ -595,7 +601,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
83338 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
83339 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
83340 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
83341 - struct sockaddr __user *, int);
83342 + struct sockaddr __user *, int) __intentional_overflow(0);
83343 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
83344 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
83345 unsigned int vlen, unsigned flags);
83346 diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
83347 index 27b3b0b..e093dd9 100644
83348 --- a/include/linux/syscore_ops.h
83349 +++ b/include/linux/syscore_ops.h
83350 @@ -16,7 +16,7 @@ struct syscore_ops {
83351 int (*suspend)(void);
83352 void (*resume)(void);
83353 void (*shutdown)(void);
83354 -};
83355 +} __do_const;
83356
83357 extern void register_syscore_ops(struct syscore_ops *ops);
83358 extern void unregister_syscore_ops(struct syscore_ops *ops);
83359 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
83360 index 14a8ff2..fa95f3a 100644
83361 --- a/include/linux/sysctl.h
83362 +++ b/include/linux/sysctl.h
83363 @@ -34,13 +34,13 @@ struct ctl_table_root;
83364 struct ctl_table_header;
83365 struct ctl_dir;
83366
83367 -typedef struct ctl_table ctl_table;
83368 -
83369 typedef int proc_handler (struct ctl_table *ctl, int write,
83370 void __user *buffer, size_t *lenp, loff_t *ppos);
83371
83372 extern int proc_dostring(struct ctl_table *, int,
83373 void __user *, size_t *, loff_t *);
83374 +extern int proc_dostring_modpriv(struct ctl_table *, int,
83375 + void __user *, size_t *, loff_t *);
83376 extern int proc_dointvec(struct ctl_table *, int,
83377 void __user *, size_t *, loff_t *);
83378 extern int proc_dointvec_minmax(struct ctl_table *, int,
83379 @@ -115,7 +115,9 @@ struct ctl_table
83380 struct ctl_table_poll *poll;
83381 void *extra1;
83382 void *extra2;
83383 -};
83384 +} __do_const __randomize_layout;
83385 +typedef struct ctl_table __no_const ctl_table_no_const;
83386 +typedef struct ctl_table ctl_table;
83387
83388 struct ctl_node {
83389 struct rb_node node;
83390 diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
83391 index 5ffaa34..fe3e31c 100644
83392 --- a/include/linux/sysfs.h
83393 +++ b/include/linux/sysfs.h
83394 @@ -34,7 +34,8 @@ struct attribute {
83395 struct lock_class_key *key;
83396 struct lock_class_key skey;
83397 #endif
83398 -};
83399 +} __do_const;
83400 +typedef struct attribute __no_const attribute_no_const;
83401
83402 /**
83403 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
83404 @@ -63,7 +64,8 @@ struct attribute_group {
83405 struct attribute *, int);
83406 struct attribute **attrs;
83407 struct bin_attribute **bin_attrs;
83408 -};
83409 +} __do_const;
83410 +typedef struct attribute_group __no_const attribute_group_no_const;
83411
83412 /**
83413 * Use these macros to make defining attributes easier. See include/linux/device.h
83414 @@ -128,7 +130,8 @@ struct bin_attribute {
83415 char *, loff_t, size_t);
83416 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
83417 struct vm_area_struct *vma);
83418 -};
83419 +} __do_const;
83420 +typedef struct bin_attribute __no_const bin_attribute_no_const;
83421
83422 /**
83423 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
83424 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
83425 index 387fa7d..3fcde6b 100644
83426 --- a/include/linux/sysrq.h
83427 +++ b/include/linux/sysrq.h
83428 @@ -16,6 +16,7 @@
83429
83430 #include <linux/errno.h>
83431 #include <linux/types.h>
83432 +#include <linux/compiler.h>
83433
83434 /* Possible values of bitmask for enabling sysrq functions */
83435 /* 0x0001 is reserved for enable everything */
83436 @@ -33,7 +34,7 @@ struct sysrq_key_op {
83437 char *help_msg;
83438 char *action_msg;
83439 int enable_mask;
83440 -};
83441 +} __do_const;
83442
83443 #ifdef CONFIG_MAGIC_SYSRQ
83444
83445 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
83446 index fddbe20..a0e76ab 100644
83447 --- a/include/linux/thread_info.h
83448 +++ b/include/linux/thread_info.h
83449 @@ -161,6 +161,13 @@ static inline bool test_and_clear_restore_sigmask(void)
83450 #error "no set_restore_sigmask() provided and default one won't work"
83451 #endif
83452
83453 +extern void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size);
83454 +
83455 +static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
83456 +{
83457 + __check_object_size(ptr, n, to_user, __builtin_constant_p(n));
83458 +}
83459 +
83460 #endif /* __KERNEL__ */
83461
83462 #endif /* _LINUX_THREAD_INFO_H */
83463 diff --git a/include/linux/tty.h b/include/linux/tty.h
83464 index 1c3316a..ae83b9f 100644
83465 --- a/include/linux/tty.h
83466 +++ b/include/linux/tty.h
83467 @@ -202,7 +202,7 @@ struct tty_port {
83468 const struct tty_port_operations *ops; /* Port operations */
83469 spinlock_t lock; /* Lock protecting tty field */
83470 int blocked_open; /* Waiting to open */
83471 - int count; /* Usage count */
83472 + atomic_t count; /* Usage count */
83473 wait_queue_head_t open_wait; /* Open waiters */
83474 wait_queue_head_t close_wait; /* Close waiters */
83475 wait_queue_head_t delta_msr_wait; /* Modem status change */
83476 @@ -284,7 +284,7 @@ struct tty_struct {
83477 /* If the tty has a pending do_SAK, queue it here - akpm */
83478 struct work_struct SAK_work;
83479 struct tty_port *port;
83480 -};
83481 +} __randomize_layout;
83482
83483 /* Each of a tty's open files has private_data pointing to tty_file_private */
83484 struct tty_file_private {
83485 @@ -550,7 +550,7 @@ extern int tty_port_open(struct tty_port *port,
83486 struct tty_struct *tty, struct file *filp);
83487 static inline int tty_port_users(struct tty_port *port)
83488 {
83489 - return port->count + port->blocked_open;
83490 + return atomic_read(&port->count) + port->blocked_open;
83491 }
83492
83493 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
83494 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
83495 index 756a609..89db85e 100644
83496 --- a/include/linux/tty_driver.h
83497 +++ b/include/linux/tty_driver.h
83498 @@ -285,7 +285,7 @@ struct tty_operations {
83499 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
83500 #endif
83501 const struct file_operations *proc_fops;
83502 -};
83503 +} __do_const __randomize_layout;
83504
83505 struct tty_driver {
83506 int magic; /* magic number for this structure */
83507 @@ -319,7 +319,7 @@ struct tty_driver {
83508
83509 const struct tty_operations *ops;
83510 struct list_head tty_drivers;
83511 -};
83512 +} __randomize_layout;
83513
83514 extern struct list_head tty_drivers;
83515
83516 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
83517 index add26da..22c00bef 100644
83518 --- a/include/linux/tty_ldisc.h
83519 +++ b/include/linux/tty_ldisc.h
83520 @@ -212,7 +212,7 @@ struct tty_ldisc_ops {
83521
83522 struct module *owner;
83523
83524 - int refcount;
83525 + atomic_t refcount;
83526 };
83527
83528 struct tty_ldisc {
83529 diff --git a/include/linux/types.h b/include/linux/types.h
83530 index 4d118ba..c3ee9bf 100644
83531 --- a/include/linux/types.h
83532 +++ b/include/linux/types.h
83533 @@ -176,10 +176,26 @@ typedef struct {
83534 int counter;
83535 } atomic_t;
83536
83537 +#ifdef CONFIG_PAX_REFCOUNT
83538 +typedef struct {
83539 + int counter;
83540 +} atomic_unchecked_t;
83541 +#else
83542 +typedef atomic_t atomic_unchecked_t;
83543 +#endif
83544 +
83545 #ifdef CONFIG_64BIT
83546 typedef struct {
83547 long counter;
83548 } atomic64_t;
83549 +
83550 +#ifdef CONFIG_PAX_REFCOUNT
83551 +typedef struct {
83552 + long counter;
83553 +} atomic64_unchecked_t;
83554 +#else
83555 +typedef atomic64_t atomic64_unchecked_t;
83556 +#endif
83557 #endif
83558
83559 struct list_head {
83560 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
83561 index ecd3319..8a36ded 100644
83562 --- a/include/linux/uaccess.h
83563 +++ b/include/linux/uaccess.h
83564 @@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
83565 long ret; \
83566 mm_segment_t old_fs = get_fs(); \
83567 \
83568 - set_fs(KERNEL_DS); \
83569 pagefault_disable(); \
83570 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
83571 - pagefault_enable(); \
83572 + set_fs(KERNEL_DS); \
83573 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
83574 set_fs(old_fs); \
83575 + pagefault_enable(); \
83576 ret; \
83577 })
83578
83579 diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
83580 index 2d1f9b6..d7a9fce 100644
83581 --- a/include/linux/uidgid.h
83582 +++ b/include/linux/uidgid.h
83583 @@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
83584
83585 #endif /* CONFIG_USER_NS */
83586
83587 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
83588 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
83589 +#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
83590 +#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
83591 +
83592 #endif /* _LINUX_UIDGID_H */
83593 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
83594 index 99c1b4d..562e6f3 100644
83595 --- a/include/linux/unaligned/access_ok.h
83596 +++ b/include/linux/unaligned/access_ok.h
83597 @@ -4,34 +4,34 @@
83598 #include <linux/kernel.h>
83599 #include <asm/byteorder.h>
83600
83601 -static inline u16 get_unaligned_le16(const void *p)
83602 +static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
83603 {
83604 - return le16_to_cpup((__le16 *)p);
83605 + return le16_to_cpup((const __le16 *)p);
83606 }
83607
83608 -static inline u32 get_unaligned_le32(const void *p)
83609 +static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
83610 {
83611 - return le32_to_cpup((__le32 *)p);
83612 + return le32_to_cpup((const __le32 *)p);
83613 }
83614
83615 -static inline u64 get_unaligned_le64(const void *p)
83616 +static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
83617 {
83618 - return le64_to_cpup((__le64 *)p);
83619 + return le64_to_cpup((const __le64 *)p);
83620 }
83621
83622 -static inline u16 get_unaligned_be16(const void *p)
83623 +static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
83624 {
83625 - return be16_to_cpup((__be16 *)p);
83626 + return be16_to_cpup((const __be16 *)p);
83627 }
83628
83629 -static inline u32 get_unaligned_be32(const void *p)
83630 +static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
83631 {
83632 - return be32_to_cpup((__be32 *)p);
83633 + return be32_to_cpup((const __be32 *)p);
83634 }
83635
83636 -static inline u64 get_unaligned_be64(const void *p)
83637 +static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
83638 {
83639 - return be64_to_cpup((__be64 *)p);
83640 + return be64_to_cpup((const __be64 *)p);
83641 }
83642
83643 static inline void put_unaligned_le16(u16 val, void *p)
83644 diff --git a/include/linux/usb.h b/include/linux/usb.h
83645 index 6b7ec37..4428419 100644
83646 --- a/include/linux/usb.h
83647 +++ b/include/linux/usb.h
83648 @@ -569,7 +569,7 @@ struct usb_device {
83649 int maxchild;
83650
83651 u32 quirks;
83652 - atomic_t urbnum;
83653 + atomic_unchecked_t urbnum;
83654
83655 unsigned long active_duration;
83656
83657 @@ -1653,7 +1653,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
83658
83659 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
83660 __u8 request, __u8 requesttype, __u16 value, __u16 index,
83661 - void *data, __u16 size, int timeout);
83662 + void *data, __u16 size, int timeout) __intentional_overflow(-1);
83663 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
83664 void *data, int len, int *actual_length, int timeout);
83665 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
83666 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
83667 index e452ba6..78f8e80 100644
83668 --- a/include/linux/usb/renesas_usbhs.h
83669 +++ b/include/linux/usb/renesas_usbhs.h
83670 @@ -39,7 +39,7 @@ enum {
83671 */
83672 struct renesas_usbhs_driver_callback {
83673 int (*notify_hotplug)(struct platform_device *pdev);
83674 -};
83675 +} __no_const;
83676
83677 /*
83678 * callback functions for platform
83679 diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
83680 index 4836ba3..603f6ee 100644
83681 --- a/include/linux/user_namespace.h
83682 +++ b/include/linux/user_namespace.h
83683 @@ -33,7 +33,7 @@ struct user_namespace {
83684 struct key *persistent_keyring_register;
83685 struct rw_semaphore persistent_keyring_register_sem;
83686 #endif
83687 -};
83688 +} __randomize_layout;
83689
83690 extern struct user_namespace init_user_ns;
83691
83692 diff --git a/include/linux/utsname.h b/include/linux/utsname.h
83693 index 239e277..22a5cf5 100644
83694 --- a/include/linux/utsname.h
83695 +++ b/include/linux/utsname.h
83696 @@ -24,7 +24,7 @@ struct uts_namespace {
83697 struct new_utsname name;
83698 struct user_namespace *user_ns;
83699 unsigned int proc_inum;
83700 -};
83701 +} __randomize_layout;
83702 extern struct uts_namespace init_uts_ns;
83703
83704 #ifdef CONFIG_UTS_NS
83705 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
83706 index 6f8fbcf..4efc177 100644
83707 --- a/include/linux/vermagic.h
83708 +++ b/include/linux/vermagic.h
83709 @@ -25,9 +25,42 @@
83710 #define MODULE_ARCH_VERMAGIC ""
83711 #endif
83712
83713 +#ifdef CONFIG_PAX_REFCOUNT
83714 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
83715 +#else
83716 +#define MODULE_PAX_REFCOUNT ""
83717 +#endif
83718 +
83719 +#ifdef CONSTIFY_PLUGIN
83720 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
83721 +#else
83722 +#define MODULE_CONSTIFY_PLUGIN ""
83723 +#endif
83724 +
83725 +#ifdef STACKLEAK_PLUGIN
83726 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
83727 +#else
83728 +#define MODULE_STACKLEAK_PLUGIN ""
83729 +#endif
83730 +
83731 +#ifdef RANDSTRUCT_PLUGIN
83732 +#include <generated/randomize_layout_hash.h>
83733 +#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
83734 +#else
83735 +#define MODULE_RANDSTRUCT_PLUGIN
83736 +#endif
83737 +
83738 +#ifdef CONFIG_GRKERNSEC
83739 +#define MODULE_GRSEC "GRSEC "
83740 +#else
83741 +#define MODULE_GRSEC ""
83742 +#endif
83743 +
83744 #define VERMAGIC_STRING \
83745 UTS_RELEASE " " \
83746 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
83747 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
83748 - MODULE_ARCH_VERMAGIC
83749 + MODULE_ARCH_VERMAGIC \
83750 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
83751 + MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
83752
83753 diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
83754 index 502073a..a7de024 100644
83755 --- a/include/linux/vga_switcheroo.h
83756 +++ b/include/linux/vga_switcheroo.h
83757 @@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
83758
83759 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
83760
83761 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
83762 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
83763 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
83764 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
83765 #else
83766
83767 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
83768 @@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
83769
83770 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
83771
83772 -static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
83773 -static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
83774 +static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
83775 +static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
83776
83777 #endif
83778 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
83779 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
83780 index 4b8a891..e9a2863 100644
83781 --- a/include/linux/vmalloc.h
83782 +++ b/include/linux/vmalloc.h
83783 @@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
83784 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
83785 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
83786 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
83787 +
83788 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
83789 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
83790 +#endif
83791 +
83792 /* bits [20..32] reserved for arch specific ioremap internals */
83793
83794 /*
83795 @@ -82,6 +87,10 @@ extern void *vmap(struct page **pages, unsigned int count,
83796 unsigned long flags, pgprot_t prot);
83797 extern void vunmap(const void *addr);
83798
83799 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
83800 +extern void unmap_process_stacks(struct task_struct *task);
83801 +#endif
83802 +
83803 extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,
83804 unsigned long uaddr, void *kaddr,
83805 unsigned long size);
83806 @@ -142,7 +151,7 @@ extern void free_vm_area(struct vm_struct *area);
83807
83808 /* for /dev/kmem */
83809 extern long vread(char *buf, char *addr, unsigned long count);
83810 -extern long vwrite(char *buf, char *addr, unsigned long count);
83811 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
83812
83813 /*
83814 * Internals. Dont't use..
83815 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
83816 index 45c9cd1..20bd0bf 100644
83817 --- a/include/linux/vmstat.h
83818 +++ b/include/linux/vmstat.h
83819 @@ -102,18 +102,18 @@ static inline void vm_events_fold_cpu(int cpu)
83820 /*
83821 * Zone based page accounting with per cpu differentials.
83822 */
83823 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83824 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83825
83826 static inline void zone_page_state_add(long x, struct zone *zone,
83827 enum zone_stat_item item)
83828 {
83829 - atomic_long_add(x, &zone->vm_stat[item]);
83830 - atomic_long_add(x, &vm_stat[item]);
83831 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
83832 + atomic_long_add_unchecked(x, &vm_stat[item]);
83833 }
83834
83835 -static inline unsigned long global_page_state(enum zone_stat_item item)
83836 +static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
83837 {
83838 - long x = atomic_long_read(&vm_stat[item]);
83839 + long x = atomic_long_read_unchecked(&vm_stat[item]);
83840 #ifdef CONFIG_SMP
83841 if (x < 0)
83842 x = 0;
83843 @@ -121,10 +121,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
83844 return x;
83845 }
83846
83847 -static inline unsigned long zone_page_state(struct zone *zone,
83848 +static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
83849 enum zone_stat_item item)
83850 {
83851 - long x = atomic_long_read(&zone->vm_stat[item]);
83852 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
83853 #ifdef CONFIG_SMP
83854 if (x < 0)
83855 x = 0;
83856 @@ -141,7 +141,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
83857 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
83858 enum zone_stat_item item)
83859 {
83860 - long x = atomic_long_read(&zone->vm_stat[item]);
83861 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
83862
83863 #ifdef CONFIG_SMP
83864 int cpu;
83865 @@ -228,14 +228,14 @@ static inline void __mod_zone_page_state(struct zone *zone,
83866
83867 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
83868 {
83869 - atomic_long_inc(&zone->vm_stat[item]);
83870 - atomic_long_inc(&vm_stat[item]);
83871 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
83872 + atomic_long_inc_unchecked(&vm_stat[item]);
83873 }
83874
83875 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
83876 {
83877 - atomic_long_dec(&zone->vm_stat[item]);
83878 - atomic_long_dec(&vm_stat[item]);
83879 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
83880 + atomic_long_dec_unchecked(&vm_stat[item]);
83881 }
83882
83883 static inline void __inc_zone_page_state(struct page *page,
83884 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
83885 index 91b0a68..0e9adf6 100644
83886 --- a/include/linux/xattr.h
83887 +++ b/include/linux/xattr.h
83888 @@ -28,7 +28,7 @@ struct xattr_handler {
83889 size_t size, int handler_flags);
83890 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
83891 size_t size, int flags, int handler_flags);
83892 -};
83893 +} __do_const;
83894
83895 struct xattr {
83896 const char *name;
83897 @@ -37,6 +37,9 @@ struct xattr {
83898 };
83899
83900 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
83901 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
83902 +ssize_t pax_getxattr(struct dentry *, void *, size_t);
83903 +#endif
83904 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
83905 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
83906 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
83907 diff --git a/include/linux/zlib.h b/include/linux/zlib.h
83908 index 9c5a6b4..09c9438 100644
83909 --- a/include/linux/zlib.h
83910 +++ b/include/linux/zlib.h
83911 @@ -31,6 +31,7 @@
83912 #define _ZLIB_H
83913
83914 #include <linux/zconf.h>
83915 +#include <linux/compiler.h>
83916
83917 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
83918 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
83919 @@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
83920
83921 /* basic functions */
83922
83923 -extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
83924 +extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
83925 /*
83926 Returns the number of bytes that needs to be allocated for a per-
83927 stream workspace with the specified parameters. A pointer to this
83928 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
83929 index eec6e46..82d5641 100644
83930 --- a/include/media/v4l2-dev.h
83931 +++ b/include/media/v4l2-dev.h
83932 @@ -77,7 +77,7 @@ struct v4l2_file_operations {
83933 int (*mmap) (struct file *, struct vm_area_struct *);
83934 int (*open) (struct file *);
83935 int (*release) (struct file *);
83936 -};
83937 +} __do_const;
83938
83939 /*
83940 * Newer version of video_device, handled by videodev2.c
83941 diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
83942 index c9b1593..a572459 100644
83943 --- a/include/media/v4l2-device.h
83944 +++ b/include/media/v4l2-device.h
83945 @@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
83946 this function returns 0. If the name ends with a digit (e.g. cx18),
83947 then the name will be set to cx18-0 since cx180 looks really odd. */
83948 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
83949 - atomic_t *instance);
83950 + atomic_unchecked_t *instance);
83951
83952 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
83953 Since the parent disappears this ensures that v4l2_dev doesn't have an
83954 diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
83955 index d9fa68f..45c88d1 100644
83956 --- a/include/net/9p/transport.h
83957 +++ b/include/net/9p/transport.h
83958 @@ -63,7 +63,7 @@ struct p9_trans_module {
83959 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
83960 int (*zc_request)(struct p9_client *, struct p9_req_t *,
83961 char *, char *, int , int, int, int);
83962 -};
83963 +} __do_const;
83964
83965 void v9fs_register_trans(struct p9_trans_module *m);
83966 void v9fs_unregister_trans(struct p9_trans_module *m);
83967 diff --git a/include/net/af_unix.h b/include/net/af_unix.h
83968 index a175ba4..196eb82 100644
83969 --- a/include/net/af_unix.h
83970 +++ b/include/net/af_unix.h
83971 @@ -36,7 +36,7 @@ struct unix_skb_parms {
83972 u32 secid; /* Security ID */
83973 #endif
83974 u32 consumed;
83975 -};
83976 +} __randomize_layout;
83977
83978 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
83979 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
83980 diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
83981 index 4abdcb2..945c5cc 100644
83982 --- a/include/net/bluetooth/l2cap.h
83983 +++ b/include/net/bluetooth/l2cap.h
83984 @@ -601,7 +601,7 @@ struct l2cap_ops {
83985 long (*get_sndtimeo) (struct l2cap_chan *chan);
83986 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
83987 unsigned long len, int nb);
83988 -};
83989 +} __do_const;
83990
83991 struct l2cap_conn {
83992 struct hci_conn *hcon;
83993 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
83994 index f2ae33d..c457cf0 100644
83995 --- a/include/net/caif/cfctrl.h
83996 +++ b/include/net/caif/cfctrl.h
83997 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
83998 void (*radioset_rsp)(void);
83999 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
84000 struct cflayer *client_layer);
84001 -};
84002 +} __no_const;
84003
84004 /* Link Setup Parameters for CAIF-Links. */
84005 struct cfctrl_link_param {
84006 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
84007 struct cfctrl {
84008 struct cfsrvl serv;
84009 struct cfctrl_rsp res;
84010 - atomic_t req_seq_no;
84011 - atomic_t rsp_seq_no;
84012 + atomic_unchecked_t req_seq_no;
84013 + atomic_unchecked_t rsp_seq_no;
84014 struct list_head list;
84015 /* Protects from simultaneous access to first_req list */
84016 spinlock_t info_list_lock;
84017 diff --git a/include/net/flow.h b/include/net/flow.h
84018 index 8109a15..504466d 100644
84019 --- a/include/net/flow.h
84020 +++ b/include/net/flow.h
84021 @@ -231,6 +231,6 @@ void flow_cache_fini(struct net *net);
84022
84023 void flow_cache_flush(struct net *net);
84024 void flow_cache_flush_deferred(struct net *net);
84025 -extern atomic_t flow_cache_genid;
84026 +extern atomic_unchecked_t flow_cache_genid;
84027
84028 #endif
84029 diff --git a/include/net/genetlink.h b/include/net/genetlink.h
84030 index 93695f0..766d71c 100644
84031 --- a/include/net/genetlink.h
84032 +++ b/include/net/genetlink.h
84033 @@ -120,7 +120,7 @@ struct genl_ops {
84034 u8 cmd;
84035 u8 internal_flags;
84036 u8 flags;
84037 -};
84038 +} __do_const;
84039
84040 int __genl_register_family(struct genl_family *family);
84041
84042 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
84043 index 734d9b5..48a9a4b 100644
84044 --- a/include/net/gro_cells.h
84045 +++ b/include/net/gro_cells.h
84046 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
84047 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
84048
84049 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
84050 - atomic_long_inc(&dev->rx_dropped);
84051 + atomic_long_inc_unchecked(&dev->rx_dropped);
84052 kfree_skb(skb);
84053 return;
84054 }
84055 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
84056 index 7a43138..bc76865 100644
84057 --- a/include/net/inet_connection_sock.h
84058 +++ b/include/net/inet_connection_sock.h
84059 @@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
84060 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
84061 int (*bind_conflict)(const struct sock *sk,
84062 const struct inet_bind_bucket *tb, bool relax);
84063 -};
84064 +} __do_const;
84065
84066 /** inet_connection_sock - INET connection oriented sock
84067 *
84068 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
84069 index 823ec7b..1af4453 100644
84070 --- a/include/net/inetpeer.h
84071 +++ b/include/net/inetpeer.h
84072 @@ -47,7 +47,7 @@ struct inet_peer {
84073 */
84074 union {
84075 struct {
84076 - atomic_t rid; /* Frag reception counter */
84077 + atomic_unchecked_t rid; /* Frag reception counter */
84078 };
84079 struct rcu_head rcu;
84080 struct inet_peer *gc_next;
84081 diff --git a/include/net/ip.h b/include/net/ip.h
84082 index 54de029..6a28064 100644
84083 --- a/include/net/ip.h
84084 +++ b/include/net/ip.h
84085 @@ -220,7 +220,7 @@ static inline void snmp_mib_free(void __percpu *ptr[SNMP_ARRAY_SZ])
84086
84087 void inet_get_local_port_range(struct net *net, int *low, int *high);
84088
84089 -extern unsigned long *sysctl_local_reserved_ports;
84090 +extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
84091 static inline int inet_is_reserved_local_port(int port)
84092 {
84093 return test_bit(port, sysctl_local_reserved_ports);
84094 @@ -310,7 +310,7 @@ static inline unsigned int ip_skb_dst_mtu(const struct sk_buff *skb)
84095 }
84096 }
84097
84098 -u32 ip_idents_reserve(u32 hash, int segs);
84099 +u32 ip_idents_reserve(u32 hash, int segs) __intentional_overflow(-1);
84100 void __ip_select_ident(struct iphdr *iph, int segs);
84101
84102 static inline void ip_select_ident_segs(struct sk_buff *skb, struct sock *sk, int segs)
84103 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
84104 index 9922093..a1755d6 100644
84105 --- a/include/net/ip_fib.h
84106 +++ b/include/net/ip_fib.h
84107 @@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
84108
84109 #define FIB_RES_SADDR(net, res) \
84110 ((FIB_RES_NH(res).nh_saddr_genid == \
84111 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
84112 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
84113 FIB_RES_NH(res).nh_saddr : \
84114 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
84115 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
84116 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
84117 index 5679d92..2e7a690 100644
84118 --- a/include/net/ip_vs.h
84119 +++ b/include/net/ip_vs.h
84120 @@ -558,7 +558,7 @@ struct ip_vs_conn {
84121 struct ip_vs_conn *control; /* Master control connection */
84122 atomic_t n_control; /* Number of controlled ones */
84123 struct ip_vs_dest *dest; /* real server */
84124 - atomic_t in_pkts; /* incoming packet counter */
84125 + atomic_unchecked_t in_pkts; /* incoming packet counter */
84126
84127 /* packet transmitter for different forwarding methods. If it
84128 mangles the packet, it must return NF_DROP or better NF_STOLEN,
84129 @@ -705,7 +705,7 @@ struct ip_vs_dest {
84130 __be16 port; /* port number of the server */
84131 union nf_inet_addr addr; /* IP address of the server */
84132 volatile unsigned int flags; /* dest status flags */
84133 - atomic_t conn_flags; /* flags to copy to conn */
84134 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
84135 atomic_t weight; /* server weight */
84136
84137 atomic_t refcnt; /* reference counter */
84138 @@ -960,11 +960,11 @@ struct netns_ipvs {
84139 /* ip_vs_lblc */
84140 int sysctl_lblc_expiration;
84141 struct ctl_table_header *lblc_ctl_header;
84142 - struct ctl_table *lblc_ctl_table;
84143 + ctl_table_no_const *lblc_ctl_table;
84144 /* ip_vs_lblcr */
84145 int sysctl_lblcr_expiration;
84146 struct ctl_table_header *lblcr_ctl_header;
84147 - struct ctl_table *lblcr_ctl_table;
84148 + ctl_table_no_const *lblcr_ctl_table;
84149 /* ip_vs_est */
84150 struct list_head est_list; /* estimator list */
84151 spinlock_t est_lock;
84152 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
84153 index 8d4f588..2e37ad2 100644
84154 --- a/include/net/irda/ircomm_tty.h
84155 +++ b/include/net/irda/ircomm_tty.h
84156 @@ -33,6 +33,7 @@
84157 #include <linux/termios.h>
84158 #include <linux/timer.h>
84159 #include <linux/tty.h> /* struct tty_struct */
84160 +#include <asm/local.h>
84161
84162 #include <net/irda/irias_object.h>
84163 #include <net/irda/ircomm_core.h>
84164 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
84165 index 714cc9a..ea05f3e 100644
84166 --- a/include/net/iucv/af_iucv.h
84167 +++ b/include/net/iucv/af_iucv.h
84168 @@ -149,7 +149,7 @@ struct iucv_skb_cb {
84169 struct iucv_sock_list {
84170 struct hlist_head head;
84171 rwlock_t lock;
84172 - atomic_t autobind_name;
84173 + atomic_unchecked_t autobind_name;
84174 };
84175
84176 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
84177 diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
84178 index f3be818..bf46196 100644
84179 --- a/include/net/llc_c_ac.h
84180 +++ b/include/net/llc_c_ac.h
84181 @@ -87,7 +87,7 @@
84182 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
84183 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
84184
84185 -typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
84186 +typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
84187
84188 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
84189 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
84190 diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
84191 index 3948cf1..83b28c4 100644
84192 --- a/include/net/llc_c_ev.h
84193 +++ b/include/net/llc_c_ev.h
84194 @@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
84195 return (struct llc_conn_state_ev *)skb->cb;
84196 }
84197
84198 -typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
84199 -typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
84200 +typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
84201 +typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
84202
84203 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
84204 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
84205 diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
84206 index 0e79cfb..f46db31 100644
84207 --- a/include/net/llc_c_st.h
84208 +++ b/include/net/llc_c_st.h
84209 @@ -37,7 +37,7 @@ struct llc_conn_state_trans {
84210 u8 next_state;
84211 llc_conn_ev_qfyr_t *ev_qualifiers;
84212 llc_conn_action_t *ev_actions;
84213 -};
84214 +} __do_const;
84215
84216 struct llc_conn_state {
84217 u8 current_state;
84218 diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
84219 index a61b98c..aade1eb 100644
84220 --- a/include/net/llc_s_ac.h
84221 +++ b/include/net/llc_s_ac.h
84222 @@ -23,7 +23,7 @@
84223 #define SAP_ACT_TEST_IND 9
84224
84225 /* All action functions must look like this */
84226 -typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
84227 +typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
84228
84229 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
84230 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
84231 diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
84232 index 567c681..cd73ac02 100644
84233 --- a/include/net/llc_s_st.h
84234 +++ b/include/net/llc_s_st.h
84235 @@ -20,7 +20,7 @@ struct llc_sap_state_trans {
84236 llc_sap_ev_t ev;
84237 u8 next_state;
84238 llc_sap_action_t *ev_actions;
84239 -};
84240 +} __do_const;
84241
84242 struct llc_sap_state {
84243 u8 curr_state;
84244 diff --git a/include/net/mac80211.h b/include/net/mac80211.h
84245 index 8248e39..7610eec 100644
84246 --- a/include/net/mac80211.h
84247 +++ b/include/net/mac80211.h
84248 @@ -4467,7 +4467,7 @@ struct rate_control_ops {
84249 void (*add_sta_debugfs)(void *priv, void *priv_sta,
84250 struct dentry *dir);
84251 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
84252 -};
84253 +} __do_const;
84254
84255 static inline int rate_supported(struct ieee80211_sta *sta,
84256 enum ieee80211_band band,
84257 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
84258 index 7277caf..fd095bc 100644
84259 --- a/include/net/neighbour.h
84260 +++ b/include/net/neighbour.h
84261 @@ -163,7 +163,7 @@ struct neigh_ops {
84262 void (*error_report)(struct neighbour *, struct sk_buff *);
84263 int (*output)(struct neighbour *, struct sk_buff *);
84264 int (*connected_output)(struct neighbour *, struct sk_buff *);
84265 -};
84266 +} __do_const;
84267
84268 struct pneigh_entry {
84269 struct pneigh_entry *next;
84270 @@ -203,7 +203,6 @@ struct neigh_table {
84271 void (*proxy_redo)(struct sk_buff *skb);
84272 char *id;
84273 struct neigh_parms parms;
84274 - /* HACK. gc_* should follow parms without a gap! */
84275 int gc_interval;
84276 int gc_thresh1;
84277 int gc_thresh2;
84278 @@ -218,7 +217,7 @@ struct neigh_table {
84279 struct neigh_statistics __percpu *stats;
84280 struct neigh_hash_table __rcu *nht;
84281 struct pneigh_entry **phash_buckets;
84282 -};
84283 +} __randomize_layout;
84284
84285 static inline int neigh_parms_family(struct neigh_parms *p)
84286 {
84287 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
84288 index 5f9eb26..85699c4 100644
84289 --- a/include/net/net_namespace.h
84290 +++ b/include/net/net_namespace.h
84291 @@ -129,8 +129,8 @@ struct net {
84292 struct netns_ipvs *ipvs;
84293 #endif
84294 struct sock *diag_nlsk;
84295 - atomic_t fnhe_genid;
84296 -};
84297 + atomic_unchecked_t fnhe_genid;
84298 +} __randomize_layout;
84299
84300 #include <linux/seq_file_net.h>
84301
84302 @@ -286,7 +286,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
84303 #define __net_init __init
84304 #define __net_exit __exit_refok
84305 #define __net_initdata __initdata
84306 +#ifdef CONSTIFY_PLUGIN
84307 #define __net_initconst __initconst
84308 +#else
84309 +#define __net_initconst __initdata
84310 +#endif
84311 #endif
84312
84313 struct pernet_operations {
84314 @@ -296,7 +300,7 @@ struct pernet_operations {
84315 void (*exit_batch)(struct list_head *net_exit_list);
84316 int *id;
84317 size_t size;
84318 -};
84319 +} __do_const;
84320
84321 /*
84322 * Use these carefully. If you implement a network device and it
84323 @@ -344,23 +348,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
84324
84325 static inline int rt_genid_ipv4(struct net *net)
84326 {
84327 - return atomic_read(&net->ipv4.rt_genid);
84328 + return atomic_read_unchecked(&net->ipv4.rt_genid);
84329 }
84330
84331 static inline void rt_genid_bump_ipv4(struct net *net)
84332 {
84333 - atomic_inc(&net->ipv4.rt_genid);
84334 + atomic_inc_unchecked(&net->ipv4.rt_genid);
84335 }
84336
84337 #if IS_ENABLED(CONFIG_IPV6)
84338 static inline int rt_genid_ipv6(struct net *net)
84339 {
84340 - return atomic_read(&net->ipv6.rt_genid);
84341 + return atomic_read_unchecked(&net->ipv6.rt_genid);
84342 }
84343
84344 static inline void rt_genid_bump_ipv6(struct net *net)
84345 {
84346 - atomic_inc(&net->ipv6.rt_genid);
84347 + atomic_inc_unchecked(&net->ipv6.rt_genid);
84348 }
84349 #else
84350 static inline int rt_genid_ipv6(struct net *net)
84351 @@ -382,12 +386,12 @@ static inline void rt_genid_bump_all(struct net *net)
84352
84353 static inline int fnhe_genid(struct net *net)
84354 {
84355 - return atomic_read(&net->fnhe_genid);
84356 + return atomic_read_unchecked(&net->fnhe_genid);
84357 }
84358
84359 static inline void fnhe_genid_bump(struct net *net)
84360 {
84361 - atomic_inc(&net->fnhe_genid);
84362 + atomic_inc_unchecked(&net->fnhe_genid);
84363 }
84364
84365 #endif /* __NET_NET_NAMESPACE_H */
84366 diff --git a/include/net/netdma.h b/include/net/netdma.h
84367 index 8ba8ce2..99b7fff 100644
84368 --- a/include/net/netdma.h
84369 +++ b/include/net/netdma.h
84370 @@ -24,7 +24,7 @@
84371 #include <linux/dmaengine.h>
84372 #include <linux/skbuff.h>
84373
84374 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
84375 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
84376 struct sk_buff *skb, int offset, struct iovec *to,
84377 size_t len, struct dma_pinned_list *pinned_list);
84378
84379 diff --git a/include/net/netlink.h b/include/net/netlink.h
84380 index 2b47eaa..6d5bcc2 100644
84381 --- a/include/net/netlink.h
84382 +++ b/include/net/netlink.h
84383 @@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
84384 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
84385 {
84386 if (mark)
84387 - skb_trim(skb, (unsigned char *) mark - skb->data);
84388 + skb_trim(skb, (const unsigned char *) mark - skb->data);
84389 }
84390
84391 /**
84392 diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
84393 index 773cce3..6a11852 100644
84394 --- a/include/net/netns/conntrack.h
84395 +++ b/include/net/netns/conntrack.h
84396 @@ -13,10 +13,10 @@ struct nf_conntrack_ecache;
84397 struct nf_proto_net {
84398 #ifdef CONFIG_SYSCTL
84399 struct ctl_table_header *ctl_table_header;
84400 - struct ctl_table *ctl_table;
84401 + ctl_table_no_const *ctl_table;
84402 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
84403 struct ctl_table_header *ctl_compat_header;
84404 - struct ctl_table *ctl_compat_table;
84405 + ctl_table_no_const *ctl_compat_table;
84406 #endif
84407 #endif
84408 unsigned int users;
84409 @@ -59,7 +59,7 @@ struct nf_ip_net {
84410 struct nf_icmp_net icmpv6;
84411 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
84412 struct ctl_table_header *ctl_table_header;
84413 - struct ctl_table *ctl_table;
84414 + ctl_table_no_const *ctl_table;
84415 #endif
84416 };
84417
84418 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
84419 index b2704fd0..421d717 100644
84420 --- a/include/net/netns/ipv4.h
84421 +++ b/include/net/netns/ipv4.h
84422 @@ -79,7 +79,7 @@ struct netns_ipv4 {
84423
84424 struct ping_group_range ping_group_range;
84425
84426 - atomic_t dev_addr_genid;
84427 + atomic_unchecked_t dev_addr_genid;
84428
84429 #ifdef CONFIG_IP_MROUTE
84430 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
84431 @@ -89,6 +89,6 @@ struct netns_ipv4 {
84432 struct fib_rules_ops *mr_rules_ops;
84433 #endif
84434 #endif
84435 - atomic_t rt_genid;
84436 + atomic_unchecked_t rt_genid;
84437 };
84438 #endif
84439 diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
84440 index 21edaf1..4c5faae 100644
84441 --- a/include/net/netns/ipv6.h
84442 +++ b/include/net/netns/ipv6.h
84443 @@ -73,8 +73,8 @@ struct netns_ipv6 {
84444 struct fib_rules_ops *mr6_rules_ops;
84445 #endif
84446 #endif
84447 - atomic_t dev_addr_genid;
84448 - atomic_t rt_genid;
84449 + atomic_unchecked_t dev_addr_genid;
84450 + atomic_unchecked_t rt_genid;
84451 };
84452
84453 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
84454 diff --git a/include/net/netns/xfrm.h b/include/net/netns/xfrm.h
84455 index 3492434..209f58c 100644
84456 --- a/include/net/netns/xfrm.h
84457 +++ b/include/net/netns/xfrm.h
84458 @@ -64,7 +64,7 @@ struct netns_xfrm {
84459
84460 /* flow cache part */
84461 struct flow_cache flow_cache_global;
84462 - atomic_t flow_cache_genid;
84463 + atomic_unchecked_t flow_cache_genid;
84464 struct list_head flow_cache_gc_list;
84465 spinlock_t flow_cache_gc_lock;
84466 struct work_struct flow_cache_gc_work;
84467 diff --git a/include/net/ping.h b/include/net/ping.h
84468 index 026479b..d9b2829 100644
84469 --- a/include/net/ping.h
84470 +++ b/include/net/ping.h
84471 @@ -54,7 +54,7 @@ struct ping_iter_state {
84472
84473 extern struct proto ping_prot;
84474 #if IS_ENABLED(CONFIG_IPV6)
84475 -extern struct pingv6_ops pingv6_ops;
84476 +extern struct pingv6_ops *pingv6_ops;
84477 #endif
84478
84479 struct pingfakehdr {
84480 diff --git a/include/net/protocol.h b/include/net/protocol.h
84481 index a7e986b..dc67bce 100644
84482 --- a/include/net/protocol.h
84483 +++ b/include/net/protocol.h
84484 @@ -49,7 +49,7 @@ struct net_protocol {
84485 * socket lookup?
84486 */
84487 icmp_strict_tag_validation:1;
84488 -};
84489 +} __do_const;
84490
84491 #if IS_ENABLED(CONFIG_IPV6)
84492 struct inet6_protocol {
84493 @@ -62,7 +62,7 @@ struct inet6_protocol {
84494 u8 type, u8 code, int offset,
84495 __be32 info);
84496 unsigned int flags; /* INET6_PROTO_xxx */
84497 -};
84498 +} __do_const;
84499
84500 #define INET6_PROTO_NOPOLICY 0x1
84501 #define INET6_PROTO_FINAL 0x2
84502 diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
84503 index 72240e5..8c14bef 100644
84504 --- a/include/net/rtnetlink.h
84505 +++ b/include/net/rtnetlink.h
84506 @@ -93,7 +93,7 @@ struct rtnl_link_ops {
84507 int (*fill_slave_info)(struct sk_buff *skb,
84508 const struct net_device *dev,
84509 const struct net_device *slave_dev);
84510 -};
84511 +} __do_const;
84512
84513 int __rtnl_link_register(struct rtnl_link_ops *ops);
84514 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
84515 diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
84516 index 4a5b9a3..ca27d73 100644
84517 --- a/include/net/sctp/checksum.h
84518 +++ b/include/net/sctp/checksum.h
84519 @@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
84520 unsigned int offset)
84521 {
84522 struct sctphdr *sh = sctp_hdr(skb);
84523 - __le32 ret, old = sh->checksum;
84524 - const struct skb_checksum_ops ops = {
84525 + __le32 ret, old = sh->checksum;
84526 + static const struct skb_checksum_ops ops = {
84527 .update = sctp_csum_update,
84528 .combine = sctp_csum_combine,
84529 };
84530 diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
84531 index 7f4eeb3..37e8fe1 100644
84532 --- a/include/net/sctp/sm.h
84533 +++ b/include/net/sctp/sm.h
84534 @@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
84535 typedef struct {
84536 sctp_state_fn_t *fn;
84537 const char *name;
84538 -} sctp_sm_table_entry_t;
84539 +} __do_const sctp_sm_table_entry_t;
84540
84541 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
84542 * currently in use.
84543 @@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
84544 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
84545
84546 /* Extern declarations for major data structures. */
84547 -extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
84548 +extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
84549
84550
84551 /* Get the size of a DATA chunk payload. */
84552 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
84553 index 0dfcc92..7967849 100644
84554 --- a/include/net/sctp/structs.h
84555 +++ b/include/net/sctp/structs.h
84556 @@ -507,7 +507,7 @@ struct sctp_pf {
84557 struct sctp_association *asoc);
84558 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
84559 struct sctp_af *af;
84560 -};
84561 +} __do_const;
84562
84563
84564 /* Structure to track chunk fragments that have been acked, but peer
84565 diff --git a/include/net/sock.h b/include/net/sock.h
84566 index f5a7e22..043b85f 100644
84567 --- a/include/net/sock.h
84568 +++ b/include/net/sock.h
84569 @@ -348,7 +348,7 @@ struct sock {
84570 unsigned int sk_napi_id;
84571 unsigned int sk_ll_usec;
84572 #endif
84573 - atomic_t sk_drops;
84574 + atomic_unchecked_t sk_drops;
84575 int sk_rcvbuf;
84576
84577 struct sk_filter __rcu *sk_filter;
84578 @@ -1036,7 +1036,7 @@ struct proto {
84579 void (*destroy_cgroup)(struct mem_cgroup *memcg);
84580 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
84581 #endif
84582 -};
84583 +} __randomize_layout;
84584
84585 /*
84586 * Bits in struct cg_proto.flags
84587 @@ -1223,7 +1223,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
84588 return ret >> PAGE_SHIFT;
84589 }
84590
84591 -static inline long
84592 +static inline long __intentional_overflow(-1)
84593 sk_memory_allocated(const struct sock *sk)
84594 {
84595 struct proto *prot = sk->sk_prot;
84596 @@ -1368,7 +1368,7 @@ struct sock_iocb {
84597 struct scm_cookie *scm;
84598 struct msghdr *msg, async_msg;
84599 struct kiocb *kiocb;
84600 -};
84601 +} __randomize_layout;
84602
84603 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
84604 {
84605 @@ -1803,7 +1803,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
84606 }
84607
84608 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
84609 - char __user *from, char *to,
84610 + char __user *from, unsigned char *to,
84611 int copy, int offset)
84612 {
84613 if (skb->ip_summed == CHECKSUM_NONE) {
84614 @@ -2065,7 +2065,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
84615 }
84616 }
84617
84618 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
84619 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
84620
84621 /**
84622 * sk_page_frag - return an appropriate page_frag
84623 diff --git a/include/net/tcp.h b/include/net/tcp.h
84624 index 87d8774..cf214f8 100644
84625 --- a/include/net/tcp.h
84626 +++ b/include/net/tcp.h
84627 @@ -541,7 +541,7 @@ void tcp_retransmit_timer(struct sock *sk);
84628 void tcp_xmit_retransmit_queue(struct sock *);
84629 void tcp_simple_retransmit(struct sock *);
84630 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
84631 -int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
84632 +int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
84633
84634 void tcp_send_probe0(struct sock *);
84635 void tcp_send_partial(struct sock *);
84636 @@ -715,8 +715,8 @@ struct tcp_skb_cb {
84637 struct inet6_skb_parm h6;
84638 #endif
84639 } header; /* For incoming frames */
84640 - __u32 seq; /* Starting sequence number */
84641 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
84642 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
84643 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
84644 __u32 when; /* used to compute rtt's */
84645 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
84646
84647 @@ -730,7 +730,7 @@ struct tcp_skb_cb {
84648
84649 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
84650 /* 1 byte hole */
84651 - __u32 ack_seq; /* Sequence number ACK'd */
84652 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
84653 };
84654
84655 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
84656 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
84657 index 116e9c7..3070537 100644
84658 --- a/include/net/xfrm.h
84659 +++ b/include/net/xfrm.h
84660 @@ -285,7 +285,6 @@ struct xfrm_dst;
84661 struct xfrm_policy_afinfo {
84662 unsigned short family;
84663 struct dst_ops *dst_ops;
84664 - void (*garbage_collect)(struct net *net);
84665 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
84666 const xfrm_address_t *saddr,
84667 const xfrm_address_t *daddr);
84668 @@ -303,7 +302,7 @@ struct xfrm_policy_afinfo {
84669 struct net_device *dev,
84670 const struct flowi *fl);
84671 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
84672 -};
84673 +} __do_const;
84674
84675 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
84676 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
84677 @@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
84678 int (*transport_finish)(struct sk_buff *skb,
84679 int async);
84680 void (*local_error)(struct sk_buff *skb, u32 mtu);
84681 -};
84682 +} __do_const;
84683
84684 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
84685 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
84686 @@ -437,7 +436,7 @@ struct xfrm_mode {
84687 struct module *owner;
84688 unsigned int encap;
84689 int flags;
84690 -};
84691 +} __do_const;
84692
84693 /* Flags for xfrm_mode. */
84694 enum {
84695 @@ -534,7 +533,7 @@ struct xfrm_policy {
84696 struct timer_list timer;
84697
84698 struct flow_cache_object flo;
84699 - atomic_t genid;
84700 + atomic_unchecked_t genid;
84701 u32 priority;
84702 u32 index;
84703 struct xfrm_mark mark;
84704 @@ -1180,6 +1179,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
84705 }
84706
84707 void xfrm_garbage_collect(struct net *net);
84708 +void xfrm_garbage_collect_deferred(struct net *net);
84709
84710 #else
84711
84712 @@ -1218,6 +1218,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
84713 static inline void xfrm_garbage_collect(struct net *net)
84714 {
84715 }
84716 +static inline void xfrm_garbage_collect_deferred(struct net *net)
84717 +{
84718 +}
84719 #endif
84720
84721 static __inline__
84722 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
84723 index 1017e0b..227aa4d 100644
84724 --- a/include/rdma/iw_cm.h
84725 +++ b/include/rdma/iw_cm.h
84726 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
84727 int backlog);
84728
84729 int (*destroy_listen)(struct iw_cm_id *cm_id);
84730 -};
84731 +} __no_const;
84732
84733 /**
84734 * iw_create_cm_id - Create an IW CM identifier.
84735 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
84736 index 52beadf..598734c 100644
84737 --- a/include/scsi/libfc.h
84738 +++ b/include/scsi/libfc.h
84739 @@ -771,6 +771,7 @@ struct libfc_function_template {
84740 */
84741 void (*disc_stop_final) (struct fc_lport *);
84742 };
84743 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
84744
84745 /**
84746 * struct fc_disc - Discovery context
84747 @@ -875,7 +876,7 @@ struct fc_lport {
84748 struct fc_vport *vport;
84749
84750 /* Operational Information */
84751 - struct libfc_function_template tt;
84752 + libfc_function_template_no_const tt;
84753 u8 link_up;
84754 u8 qfull;
84755 enum fc_lport_state state;
84756 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
84757 index 27ab310..60dc245 100644
84758 --- a/include/scsi/scsi_device.h
84759 +++ b/include/scsi/scsi_device.h
84760 @@ -187,9 +187,9 @@ struct scsi_device {
84761 unsigned int max_device_blocked; /* what device_blocked counts down from */
84762 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
84763
84764 - atomic_t iorequest_cnt;
84765 - atomic_t iodone_cnt;
84766 - atomic_t ioerr_cnt;
84767 + atomic_unchecked_t iorequest_cnt;
84768 + atomic_unchecked_t iodone_cnt;
84769 + atomic_unchecked_t ioerr_cnt;
84770
84771 struct device sdev_gendev,
84772 sdev_dev;
84773 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
84774 index 8c79980..723f6f9 100644
84775 --- a/include/scsi/scsi_transport_fc.h
84776 +++ b/include/scsi/scsi_transport_fc.h
84777 @@ -752,7 +752,8 @@ struct fc_function_template {
84778 unsigned long show_host_system_hostname:1;
84779
84780 unsigned long disable_target_scan:1;
84781 -};
84782 +} __do_const;
84783 +typedef struct fc_function_template __no_const fc_function_template_no_const;
84784
84785
84786 /**
84787 diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
84788 index ae6c3b8..fd748ac 100644
84789 --- a/include/sound/compress_driver.h
84790 +++ b/include/sound/compress_driver.h
84791 @@ -128,7 +128,7 @@ struct snd_compr_ops {
84792 struct snd_compr_caps *caps);
84793 int (*get_codec_caps) (struct snd_compr_stream *stream,
84794 struct snd_compr_codec_caps *codec);
84795 -};
84796 +} __no_const;
84797
84798 /**
84799 * struct snd_compr: Compressed device
84800 diff --git a/include/sound/soc.h b/include/sound/soc.h
84801 index 0b83168..d67280a 100644
84802 --- a/include/sound/soc.h
84803 +++ b/include/sound/soc.h
84804 @@ -782,7 +782,7 @@ struct snd_soc_codec_driver {
84805 /* probe ordering - for components with runtime dependencies */
84806 int probe_order;
84807 int remove_order;
84808 -};
84809 +} __do_const;
84810
84811 /* SoC platform interface */
84812 struct snd_soc_platform_driver {
84813 @@ -828,7 +828,7 @@ struct snd_soc_platform_driver {
84814 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
84815 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
84816 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
84817 -};
84818 +} __do_const;
84819
84820 struct snd_soc_platform {
84821 const char *name;
84822 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
84823 index 9ec9864..e2ee1ee 100644
84824 --- a/include/target/target_core_base.h
84825 +++ b/include/target/target_core_base.h
84826 @@ -761,7 +761,7 @@ struct se_device {
84827 atomic_long_t write_bytes;
84828 /* Active commands on this virtual SE device */
84829 atomic_t simple_cmds;
84830 - atomic_t dev_ordered_id;
84831 + atomic_unchecked_t dev_ordered_id;
84832 atomic_t dev_ordered_sync;
84833 atomic_t dev_qf_count;
84834 int export_count;
84835 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
84836 new file mode 100644
84837 index 0000000..fb634b7
84838 --- /dev/null
84839 +++ b/include/trace/events/fs.h
84840 @@ -0,0 +1,53 @@
84841 +#undef TRACE_SYSTEM
84842 +#define TRACE_SYSTEM fs
84843 +
84844 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
84845 +#define _TRACE_FS_H
84846 +
84847 +#include <linux/fs.h>
84848 +#include <linux/tracepoint.h>
84849 +
84850 +TRACE_EVENT(do_sys_open,
84851 +
84852 + TP_PROTO(const char *filename, int flags, int mode),
84853 +
84854 + TP_ARGS(filename, flags, mode),
84855 +
84856 + TP_STRUCT__entry(
84857 + __string( filename, filename )
84858 + __field( int, flags )
84859 + __field( int, mode )
84860 + ),
84861 +
84862 + TP_fast_assign(
84863 + __assign_str(filename, filename);
84864 + __entry->flags = flags;
84865 + __entry->mode = mode;
84866 + ),
84867 +
84868 + TP_printk("\"%s\" %x %o",
84869 + __get_str(filename), __entry->flags, __entry->mode)
84870 +);
84871 +
84872 +TRACE_EVENT(open_exec,
84873 +
84874 + TP_PROTO(const char *filename),
84875 +
84876 + TP_ARGS(filename),
84877 +
84878 + TP_STRUCT__entry(
84879 + __string( filename, filename )
84880 + ),
84881 +
84882 + TP_fast_assign(
84883 + __assign_str(filename, filename);
84884 + ),
84885 +
84886 + TP_printk("\"%s\"",
84887 + __get_str(filename))
84888 +);
84889 +
84890 +#endif /* _TRACE_FS_H */
84891 +
84892 +/* This part must be outside protection */
84893 +#include <trace/define_trace.h>
84894 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
84895 index 1c09820..7f5ec79 100644
84896 --- a/include/trace/events/irq.h
84897 +++ b/include/trace/events/irq.h
84898 @@ -36,7 +36,7 @@ struct softirq_action;
84899 */
84900 TRACE_EVENT(irq_handler_entry,
84901
84902 - TP_PROTO(int irq, struct irqaction *action),
84903 + TP_PROTO(int irq, const struct irqaction *action),
84904
84905 TP_ARGS(irq, action),
84906
84907 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
84908 */
84909 TRACE_EVENT(irq_handler_exit,
84910
84911 - TP_PROTO(int irq, struct irqaction *action, int ret),
84912 + TP_PROTO(int irq, const struct irqaction *action, int ret),
84913
84914 TP_ARGS(irq, action, ret),
84915
84916 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
84917 index 7caf44c..23c6f27 100644
84918 --- a/include/uapi/linux/a.out.h
84919 +++ b/include/uapi/linux/a.out.h
84920 @@ -39,6 +39,14 @@ enum machine_type {
84921 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
84922 };
84923
84924 +/* Constants for the N_FLAGS field */
84925 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
84926 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
84927 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
84928 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
84929 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
84930 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
84931 +
84932 #if !defined (N_MAGIC)
84933 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
84934 #endif
84935 diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
84936 index 22b6ad3..aeba37e 100644
84937 --- a/include/uapi/linux/bcache.h
84938 +++ b/include/uapi/linux/bcache.h
84939 @@ -5,6 +5,7 @@
84940 * Bcache on disk data structures
84941 */
84942
84943 +#include <linux/compiler.h>
84944 #include <asm/types.h>
84945
84946 #define BITMASK(name, type, field, offset, size) \
84947 @@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
84948 /* Btree keys - all units are in sectors */
84949
84950 struct bkey {
84951 - __u64 high;
84952 - __u64 low;
84953 + __u64 high __intentional_overflow(-1);
84954 + __u64 low __intentional_overflow(-1);
84955 __u64 ptr[];
84956 };
84957
84958 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
84959 index d876736..ccce5c0 100644
84960 --- a/include/uapi/linux/byteorder/little_endian.h
84961 +++ b/include/uapi/linux/byteorder/little_endian.h
84962 @@ -42,51 +42,51 @@
84963
84964 static inline __le64 __cpu_to_le64p(const __u64 *p)
84965 {
84966 - return (__force __le64)*p;
84967 + return (__force const __le64)*p;
84968 }
84969 -static inline __u64 __le64_to_cpup(const __le64 *p)
84970 +static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
84971 {
84972 - return (__force __u64)*p;
84973 + return (__force const __u64)*p;
84974 }
84975 static inline __le32 __cpu_to_le32p(const __u32 *p)
84976 {
84977 - return (__force __le32)*p;
84978 + return (__force const __le32)*p;
84979 }
84980 static inline __u32 __le32_to_cpup(const __le32 *p)
84981 {
84982 - return (__force __u32)*p;
84983 + return (__force const __u32)*p;
84984 }
84985 static inline __le16 __cpu_to_le16p(const __u16 *p)
84986 {
84987 - return (__force __le16)*p;
84988 + return (__force const __le16)*p;
84989 }
84990 static inline __u16 __le16_to_cpup(const __le16 *p)
84991 {
84992 - return (__force __u16)*p;
84993 + return (__force const __u16)*p;
84994 }
84995 static inline __be64 __cpu_to_be64p(const __u64 *p)
84996 {
84997 - return (__force __be64)__swab64p(p);
84998 + return (__force const __be64)__swab64p(p);
84999 }
85000 static inline __u64 __be64_to_cpup(const __be64 *p)
85001 {
85002 - return __swab64p((__u64 *)p);
85003 + return __swab64p((const __u64 *)p);
85004 }
85005 static inline __be32 __cpu_to_be32p(const __u32 *p)
85006 {
85007 - return (__force __be32)__swab32p(p);
85008 + return (__force const __be32)__swab32p(p);
85009 }
85010 -static inline __u32 __be32_to_cpup(const __be32 *p)
85011 +static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
85012 {
85013 - return __swab32p((__u32 *)p);
85014 + return __swab32p((const __u32 *)p);
85015 }
85016 static inline __be16 __cpu_to_be16p(const __u16 *p)
85017 {
85018 - return (__force __be16)__swab16p(p);
85019 + return (__force const __be16)__swab16p(p);
85020 }
85021 static inline __u16 __be16_to_cpup(const __be16 *p)
85022 {
85023 - return __swab16p((__u16 *)p);
85024 + return __swab16p((const __u16 *)p);
85025 }
85026 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
85027 #define __le64_to_cpus(x) do { (void)(x); } while (0)
85028 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
85029 index ef6103b..d4e65dd 100644
85030 --- a/include/uapi/linux/elf.h
85031 +++ b/include/uapi/linux/elf.h
85032 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
85033 #define PT_GNU_EH_FRAME 0x6474e550
85034
85035 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
85036 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
85037 +
85038 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
85039 +
85040 +/* Constants for the e_flags field */
85041 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
85042 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
85043 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
85044 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
85045 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
85046 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
85047
85048 /*
85049 * Extended Numbering
85050 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
85051 #define DT_DEBUG 21
85052 #define DT_TEXTREL 22
85053 #define DT_JMPREL 23
85054 +#define DT_FLAGS 30
85055 + #define DF_TEXTREL 0x00000004
85056 #define DT_ENCODING 32
85057 #define OLD_DT_LOOS 0x60000000
85058 #define DT_LOOS 0x6000000d
85059 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
85060 #define PF_W 0x2
85061 #define PF_X 0x1
85062
85063 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
85064 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
85065 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
85066 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
85067 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
85068 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
85069 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
85070 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
85071 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
85072 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
85073 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
85074 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
85075 +
85076 typedef struct elf32_phdr{
85077 Elf32_Word p_type;
85078 Elf32_Off p_offset;
85079 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
85080 #define EI_OSABI 7
85081 #define EI_PAD 8
85082
85083 +#define EI_PAX 14
85084 +
85085 #define ELFMAG0 0x7f /* EI_MAG */
85086 #define ELFMAG1 'E'
85087 #define ELFMAG2 'L'
85088 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
85089 index aa169c4..6a2771d 100644
85090 --- a/include/uapi/linux/personality.h
85091 +++ b/include/uapi/linux/personality.h
85092 @@ -30,6 +30,7 @@ enum {
85093 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
85094 ADDR_NO_RANDOMIZE | \
85095 ADDR_COMPAT_LAYOUT | \
85096 + ADDR_LIMIT_3GB | \
85097 MMAP_PAGE_ZERO)
85098
85099 /*
85100 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
85101 index 7530e74..e714828 100644
85102 --- a/include/uapi/linux/screen_info.h
85103 +++ b/include/uapi/linux/screen_info.h
85104 @@ -43,7 +43,8 @@ struct screen_info {
85105 __u16 pages; /* 0x32 */
85106 __u16 vesa_attributes; /* 0x34 */
85107 __u32 capabilities; /* 0x36 */
85108 - __u8 _reserved[6]; /* 0x3a */
85109 + __u16 vesapm_size; /* 0x3a */
85110 + __u8 _reserved[4]; /* 0x3c */
85111 } __attribute__((packed));
85112
85113 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
85114 diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
85115 index 0e011eb..82681b1 100644
85116 --- a/include/uapi/linux/swab.h
85117 +++ b/include/uapi/linux/swab.h
85118 @@ -43,7 +43,7 @@
85119 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
85120 */
85121
85122 -static inline __attribute_const__ __u16 __fswab16(__u16 val)
85123 +static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
85124 {
85125 #ifdef __HAVE_BUILTIN_BSWAP16__
85126 return __builtin_bswap16(val);
85127 @@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
85128 #endif
85129 }
85130
85131 -static inline __attribute_const__ __u32 __fswab32(__u32 val)
85132 +static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
85133 {
85134 #ifdef __HAVE_BUILTIN_BSWAP32__
85135 return __builtin_bswap32(val);
85136 @@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
85137 #endif
85138 }
85139
85140 -static inline __attribute_const__ __u64 __fswab64(__u64 val)
85141 +static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
85142 {
85143 #ifdef __HAVE_BUILTIN_BSWAP64__
85144 return __builtin_bswap64(val);
85145 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
85146 index 6d67213..552fdd9 100644
85147 --- a/include/uapi/linux/sysctl.h
85148 +++ b/include/uapi/linux/sysctl.h
85149 @@ -155,8 +155,6 @@ enum
85150 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
85151 };
85152
85153 -
85154 -
85155 /* CTL_VM names: */
85156 enum
85157 {
85158 diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
85159 index ea468ee..4d367a5 100644
85160 --- a/include/uapi/linux/videodev2.h
85161 +++ b/include/uapi/linux/videodev2.h
85162 @@ -1248,7 +1248,7 @@ struct v4l2_ext_control {
85163 union {
85164 __s32 value;
85165 __s64 value64;
85166 - char *string;
85167 + char __user *string;
85168 };
85169 } __attribute__ ((packed));
85170
85171 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
85172 index c38355c..17a57bc 100644
85173 --- a/include/uapi/linux/xattr.h
85174 +++ b/include/uapi/linux/xattr.h
85175 @@ -73,5 +73,9 @@
85176 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
85177 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
85178
85179 +/* User namespace */
85180 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
85181 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
85182 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
85183
85184 #endif /* _UAPI_LINUX_XATTR_H */
85185 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
85186 index f9466fa..f4e2b81 100644
85187 --- a/include/video/udlfb.h
85188 +++ b/include/video/udlfb.h
85189 @@ -53,10 +53,10 @@ struct dlfb_data {
85190 u32 pseudo_palette[256];
85191 int blank_mode; /*one of FB_BLANK_ */
85192 /* blit-only rendering path metrics, exposed through sysfs */
85193 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
85194 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
85195 - atomic_t bytes_sent; /* to usb, after compression including overhead */
85196 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
85197 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
85198 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
85199 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
85200 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
85201 };
85202
85203 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
85204 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
85205 index 30f5362..8ed8ac9 100644
85206 --- a/include/video/uvesafb.h
85207 +++ b/include/video/uvesafb.h
85208 @@ -122,6 +122,7 @@ struct uvesafb_par {
85209 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
85210 u8 pmi_setpal; /* PMI for palette changes */
85211 u16 *pmi_base; /* protected mode interface location */
85212 + u8 *pmi_code; /* protected mode code location */
85213 void *pmi_start;
85214 void *pmi_pal;
85215 u8 *vbe_state_orig; /*
85216 diff --git a/init/Kconfig b/init/Kconfig
85217 index 9d3585b..ad45d34 100644
85218 --- a/init/Kconfig
85219 +++ b/init/Kconfig
85220 @@ -1093,6 +1093,7 @@ endif # CGROUPS
85221
85222 config CHECKPOINT_RESTORE
85223 bool "Checkpoint/restore support" if EXPERT
85224 + depends on !GRKERNSEC
85225 default n
85226 help
85227 Enables additional kernel features in a sake of checkpoint/restore.
85228 @@ -1570,7 +1571,7 @@ config SLUB_DEBUG
85229
85230 config COMPAT_BRK
85231 bool "Disable heap randomization"
85232 - default y
85233 + default n
85234 help
85235 Randomizing heap placement makes heap exploits harder, but it
85236 also breaks ancient binaries (including anything libc5 based).
85237 @@ -1858,7 +1859,7 @@ config INIT_ALL_POSSIBLE
85238 config STOP_MACHINE
85239 bool
85240 default y
85241 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
85242 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
85243 help
85244 Need stop_machine() primitive.
85245
85246 diff --git a/init/Makefile b/init/Makefile
85247 index 7bc47ee..6da2dc7 100644
85248 --- a/init/Makefile
85249 +++ b/init/Makefile
85250 @@ -2,6 +2,9 @@
85251 # Makefile for the linux kernel.
85252 #
85253
85254 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
85255 +asflags-y := $(GCC_PLUGINS_AFLAGS)
85256 +
85257 obj-y := main.o version.o mounts.o
85258 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
85259 obj-y += noinitramfs.o
85260 diff --git a/init/do_mounts.c b/init/do_mounts.c
85261 index 82f2288..ea1430a 100644
85262 --- a/init/do_mounts.c
85263 +++ b/init/do_mounts.c
85264 @@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
85265 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
85266 {
85267 struct super_block *s;
85268 - int err = sys_mount(name, "/root", fs, flags, data);
85269 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
85270 if (err)
85271 return err;
85272
85273 - sys_chdir("/root");
85274 + sys_chdir((const char __force_user *)"/root");
85275 s = current->fs->pwd.dentry->d_sb;
85276 ROOT_DEV = s->s_dev;
85277 printk(KERN_INFO
85278 @@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
85279 va_start(args, fmt);
85280 vsprintf(buf, fmt, args);
85281 va_end(args);
85282 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
85283 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
85284 if (fd >= 0) {
85285 sys_ioctl(fd, FDEJECT, 0);
85286 sys_close(fd);
85287 }
85288 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
85289 - fd = sys_open("/dev/console", O_RDWR, 0);
85290 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
85291 if (fd >= 0) {
85292 sys_ioctl(fd, TCGETS, (long)&termios);
85293 termios.c_lflag &= ~ICANON;
85294 sys_ioctl(fd, TCSETSF, (long)&termios);
85295 - sys_read(fd, &c, 1);
85296 + sys_read(fd, (char __user *)&c, 1);
85297 termios.c_lflag |= ICANON;
85298 sys_ioctl(fd, TCSETSF, (long)&termios);
85299 sys_close(fd);
85300 @@ -589,8 +589,8 @@ void __init prepare_namespace(void)
85301 mount_root();
85302 out:
85303 devtmpfs_mount("dev");
85304 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
85305 - sys_chroot(".");
85306 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
85307 + sys_chroot((const char __force_user *)".");
85308 }
85309
85310 static bool is_tmpfs;
85311 diff --git a/init/do_mounts.h b/init/do_mounts.h
85312 index f5b978a..69dbfe8 100644
85313 --- a/init/do_mounts.h
85314 +++ b/init/do_mounts.h
85315 @@ -15,15 +15,15 @@ extern int root_mountflags;
85316
85317 static inline int create_dev(char *name, dev_t dev)
85318 {
85319 - sys_unlink(name);
85320 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
85321 + sys_unlink((char __force_user *)name);
85322 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
85323 }
85324
85325 #if BITS_PER_LONG == 32
85326 static inline u32 bstat(char *name)
85327 {
85328 struct stat64 stat;
85329 - if (sys_stat64(name, &stat) != 0)
85330 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
85331 return 0;
85332 if (!S_ISBLK(stat.st_mode))
85333 return 0;
85334 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
85335 static inline u32 bstat(char *name)
85336 {
85337 struct stat stat;
85338 - if (sys_newstat(name, &stat) != 0)
85339 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
85340 return 0;
85341 if (!S_ISBLK(stat.st_mode))
85342 return 0;
85343 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
85344 index 3e0878e..8a9d7a0 100644
85345 --- a/init/do_mounts_initrd.c
85346 +++ b/init/do_mounts_initrd.c
85347 @@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
85348 {
85349 sys_unshare(CLONE_FS | CLONE_FILES);
85350 /* stdin/stdout/stderr for /linuxrc */
85351 - sys_open("/dev/console", O_RDWR, 0);
85352 + sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
85353 sys_dup(0);
85354 sys_dup(0);
85355 /* move initrd over / and chdir/chroot in initrd root */
85356 - sys_chdir("/root");
85357 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
85358 - sys_chroot(".");
85359 + sys_chdir((const char __force_user *)"/root");
85360 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
85361 + sys_chroot((const char __force_user *)".");
85362 sys_setsid();
85363 return 0;
85364 }
85365 @@ -59,8 +59,8 @@ static void __init handle_initrd(void)
85366 create_dev("/dev/root.old", Root_RAM0);
85367 /* mount initrd on rootfs' /root */
85368 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
85369 - sys_mkdir("/old", 0700);
85370 - sys_chdir("/old");
85371 + sys_mkdir((const char __force_user *)"/old", 0700);
85372 + sys_chdir((const char __force_user *)"/old");
85373
85374 /* try loading default modules from initrd */
85375 load_default_modules();
85376 @@ -80,31 +80,31 @@ static void __init handle_initrd(void)
85377 current->flags &= ~PF_FREEZER_SKIP;
85378
85379 /* move initrd to rootfs' /old */
85380 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
85381 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
85382 /* switch root and cwd back to / of rootfs */
85383 - sys_chroot("..");
85384 + sys_chroot((const char __force_user *)"..");
85385
85386 if (new_decode_dev(real_root_dev) == Root_RAM0) {
85387 - sys_chdir("/old");
85388 + sys_chdir((const char __force_user *)"/old");
85389 return;
85390 }
85391
85392 - sys_chdir("/");
85393 + sys_chdir((const char __force_user *)"/");
85394 ROOT_DEV = new_decode_dev(real_root_dev);
85395 mount_root();
85396
85397 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
85398 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
85399 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
85400 if (!error)
85401 printk("okay\n");
85402 else {
85403 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
85404 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
85405 if (error == -ENOENT)
85406 printk("/initrd does not exist. Ignored.\n");
85407 else
85408 printk("failed\n");
85409 printk(KERN_NOTICE "Unmounting old root\n");
85410 - sys_umount("/old", MNT_DETACH);
85411 + sys_umount((char __force_user *)"/old", MNT_DETACH);
85412 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
85413 if (fd < 0) {
85414 error = fd;
85415 @@ -127,11 +127,11 @@ int __init initrd_load(void)
85416 * mounted in the normal path.
85417 */
85418 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
85419 - sys_unlink("/initrd.image");
85420 + sys_unlink((const char __force_user *)"/initrd.image");
85421 handle_initrd();
85422 return 1;
85423 }
85424 }
85425 - sys_unlink("/initrd.image");
85426 + sys_unlink((const char __force_user *)"/initrd.image");
85427 return 0;
85428 }
85429 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
85430 index 8cb6db5..d729f50 100644
85431 --- a/init/do_mounts_md.c
85432 +++ b/init/do_mounts_md.c
85433 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
85434 partitioned ? "_d" : "", minor,
85435 md_setup_args[ent].device_names);
85436
85437 - fd = sys_open(name, 0, 0);
85438 + fd = sys_open((char __force_user *)name, 0, 0);
85439 if (fd < 0) {
85440 printk(KERN_ERR "md: open failed - cannot start "
85441 "array %s\n", name);
85442 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
85443 * array without it
85444 */
85445 sys_close(fd);
85446 - fd = sys_open(name, 0, 0);
85447 + fd = sys_open((char __force_user *)name, 0, 0);
85448 sys_ioctl(fd, BLKRRPART, 0);
85449 }
85450 sys_close(fd);
85451 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
85452
85453 wait_for_device_probe();
85454
85455 - fd = sys_open("/dev/md0", 0, 0);
85456 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
85457 if (fd >= 0) {
85458 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
85459 sys_close(fd);
85460 diff --git a/init/init_task.c b/init/init_task.c
85461 index ba0a7f36..2bcf1d5 100644
85462 --- a/init/init_task.c
85463 +++ b/init/init_task.c
85464 @@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
85465 * Initial thread structure. Alignment of this is handled by a special
85466 * linker map entry.
85467 */
85468 +#ifdef CONFIG_X86
85469 +union thread_union init_thread_union __init_task_data;
85470 +#else
85471 union thread_union init_thread_union __init_task_data =
85472 { INIT_THREAD_INFO(init_task) };
85473 +#endif
85474 diff --git a/init/initramfs.c b/init/initramfs.c
85475 index a8497fa..35b3c90 100644
85476 --- a/init/initramfs.c
85477 +++ b/init/initramfs.c
85478 @@ -84,7 +84,7 @@ static void __init free_hash(void)
85479 }
85480 }
85481
85482 -static long __init do_utime(char *filename, time_t mtime)
85483 +static long __init do_utime(char __force_user *filename, time_t mtime)
85484 {
85485 struct timespec t[2];
85486
85487 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
85488 struct dir_entry *de, *tmp;
85489 list_for_each_entry_safe(de, tmp, &dir_list, list) {
85490 list_del(&de->list);
85491 - do_utime(de->name, de->mtime);
85492 + do_utime((char __force_user *)de->name, de->mtime);
85493 kfree(de->name);
85494 kfree(de);
85495 }
85496 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
85497 if (nlink >= 2) {
85498 char *old = find_link(major, minor, ino, mode, collected);
85499 if (old)
85500 - return (sys_link(old, collected) < 0) ? -1 : 1;
85501 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
85502 }
85503 return 0;
85504 }
85505 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
85506 {
85507 struct stat st;
85508
85509 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
85510 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
85511 if (S_ISDIR(st.st_mode))
85512 - sys_rmdir(path);
85513 + sys_rmdir((char __force_user *)path);
85514 else
85515 - sys_unlink(path);
85516 + sys_unlink((char __force_user *)path);
85517 }
85518 }
85519
85520 @@ -315,7 +315,7 @@ static int __init do_name(void)
85521 int openflags = O_WRONLY|O_CREAT;
85522 if (ml != 1)
85523 openflags |= O_TRUNC;
85524 - wfd = sys_open(collected, openflags, mode);
85525 + wfd = sys_open((char __force_user *)collected, openflags, mode);
85526
85527 if (wfd >= 0) {
85528 sys_fchown(wfd, uid, gid);
85529 @@ -327,17 +327,17 @@ static int __init do_name(void)
85530 }
85531 }
85532 } else if (S_ISDIR(mode)) {
85533 - sys_mkdir(collected, mode);
85534 - sys_chown(collected, uid, gid);
85535 - sys_chmod(collected, mode);
85536 + sys_mkdir((char __force_user *)collected, mode);
85537 + sys_chown((char __force_user *)collected, uid, gid);
85538 + sys_chmod((char __force_user *)collected, mode);
85539 dir_add(collected, mtime);
85540 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
85541 S_ISFIFO(mode) || S_ISSOCK(mode)) {
85542 if (maybe_link() == 0) {
85543 - sys_mknod(collected, mode, rdev);
85544 - sys_chown(collected, uid, gid);
85545 - sys_chmod(collected, mode);
85546 - do_utime(collected, mtime);
85547 + sys_mknod((char __force_user *)collected, mode, rdev);
85548 + sys_chown((char __force_user *)collected, uid, gid);
85549 + sys_chmod((char __force_user *)collected, mode);
85550 + do_utime((char __force_user *)collected, mtime);
85551 }
85552 }
85553 return 0;
85554 @@ -346,15 +346,15 @@ static int __init do_name(void)
85555 static int __init do_copy(void)
85556 {
85557 if (count >= body_len) {
85558 - sys_write(wfd, victim, body_len);
85559 + sys_write(wfd, (char __force_user *)victim, body_len);
85560 sys_close(wfd);
85561 - do_utime(vcollected, mtime);
85562 + do_utime((char __force_user *)vcollected, mtime);
85563 kfree(vcollected);
85564 eat(body_len);
85565 state = SkipIt;
85566 return 0;
85567 } else {
85568 - sys_write(wfd, victim, count);
85569 + sys_write(wfd, (char __force_user *)victim, count);
85570 body_len -= count;
85571 eat(count);
85572 return 1;
85573 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
85574 {
85575 collected[N_ALIGN(name_len) + body_len] = '\0';
85576 clean_path(collected, 0);
85577 - sys_symlink(collected + N_ALIGN(name_len), collected);
85578 - sys_lchown(collected, uid, gid);
85579 - do_utime(collected, mtime);
85580 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
85581 + sys_lchown((char __force_user *)collected, uid, gid);
85582 + do_utime((char __force_user *)collected, mtime);
85583 state = SkipIt;
85584 next_state = Reset;
85585 return 0;
85586 diff --git a/init/main.c b/init/main.c
85587 index eb0ea86..b91cd60 100644
85588 --- a/init/main.c
85589 +++ b/init/main.c
85590 @@ -97,6 +97,8 @@ extern void radix_tree_init(void);
85591 static inline void mark_rodata_ro(void) { }
85592 #endif
85593
85594 +extern void grsecurity_init(void);
85595 +
85596 /*
85597 * Debug helper: via this flag we know that we are in 'early bootup code'
85598 * where only the boot processor is running with IRQ disabled. This means
85599 @@ -158,6 +160,75 @@ static int __init set_reset_devices(char *str)
85600
85601 __setup("reset_devices", set_reset_devices);
85602
85603 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
85604 +kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
85605 +static int __init setup_grsec_proc_gid(char *str)
85606 +{
85607 + grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
85608 + return 1;
85609 +}
85610 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
85611 +#endif
85612 +
85613 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
85614 +unsigned long pax_user_shadow_base __read_only;
85615 +EXPORT_SYMBOL(pax_user_shadow_base);
85616 +extern char pax_enter_kernel_user[];
85617 +extern char pax_exit_kernel_user[];
85618 +#endif
85619 +
85620 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
85621 +static int __init setup_pax_nouderef(char *str)
85622 +{
85623 +#ifdef CONFIG_X86_32
85624 + unsigned int cpu;
85625 + struct desc_struct *gdt;
85626 +
85627 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
85628 + gdt = get_cpu_gdt_table(cpu);
85629 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
85630 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
85631 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
85632 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
85633 + }
85634 + loadsegment(ds, __KERNEL_DS);
85635 + loadsegment(es, __KERNEL_DS);
85636 + loadsegment(ss, __KERNEL_DS);
85637 +#else
85638 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
85639 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
85640 + clone_pgd_mask = ~(pgdval_t)0UL;
85641 + pax_user_shadow_base = 0UL;
85642 + setup_clear_cpu_cap(X86_FEATURE_PCID);
85643 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
85644 +#endif
85645 +
85646 + return 0;
85647 +}
85648 +early_param("pax_nouderef", setup_pax_nouderef);
85649 +
85650 +#ifdef CONFIG_X86_64
85651 +static int __init setup_pax_weakuderef(char *str)
85652 +{
85653 + if (clone_pgd_mask != ~(pgdval_t)0UL)
85654 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
85655 + return 1;
85656 +}
85657 +__setup("pax_weakuderef", setup_pax_weakuderef);
85658 +#endif
85659 +#endif
85660 +
85661 +#ifdef CONFIG_PAX_SOFTMODE
85662 +int pax_softmode;
85663 +
85664 +static int __init setup_pax_softmode(char *str)
85665 +{
85666 + get_option(&str, &pax_softmode);
85667 + return 1;
85668 +}
85669 +__setup("pax_softmode=", setup_pax_softmode);
85670 +#endif
85671 +
85672 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
85673 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
85674 static const char *panic_later, *panic_param;
85675 @@ -692,25 +763,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
85676 {
85677 int count = preempt_count();
85678 int ret;
85679 - char msgbuf[64];
85680 + const char *msg1 = "", *msg2 = "";
85681
85682 if (initcall_debug)
85683 ret = do_one_initcall_debug(fn);
85684 else
85685 ret = fn();
85686
85687 - msgbuf[0] = 0;
85688 -
85689 if (preempt_count() != count) {
85690 - sprintf(msgbuf, "preemption imbalance ");
85691 + msg1 = " preemption imbalance";
85692 preempt_count_set(count);
85693 }
85694 if (irqs_disabled()) {
85695 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
85696 + msg2 = " disabled interrupts";
85697 local_irq_enable();
85698 }
85699 - WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
85700 + WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
85701
85702 + add_latent_entropy();
85703 return ret;
85704 }
85705
85706 @@ -817,8 +887,8 @@ static int run_init_process(const char *init_filename)
85707 {
85708 argv_init[0] = init_filename;
85709 return do_execve(getname_kernel(init_filename),
85710 - (const char __user *const __user *)argv_init,
85711 - (const char __user *const __user *)envp_init);
85712 + (const char __user *const __force_user *)argv_init,
85713 + (const char __user *const __force_user *)envp_init);
85714 }
85715
85716 static int try_to_run_init_process(const char *init_filename)
85717 @@ -835,6 +905,10 @@ static int try_to_run_init_process(const char *init_filename)
85718 return ret;
85719 }
85720
85721 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
85722 +extern int gr_init_ran;
85723 +#endif
85724 +
85725 static noinline void __init kernel_init_freeable(void);
85726
85727 static int __ref kernel_init(void *unused)
85728 @@ -859,6 +933,11 @@ static int __ref kernel_init(void *unused)
85729 ramdisk_execute_command, ret);
85730 }
85731
85732 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
85733 + /* if no initrd was used, be extra sure we enforce chroot restrictions */
85734 + gr_init_ran = 1;
85735 +#endif
85736 +
85737 /*
85738 * We try each of these until one succeeds.
85739 *
85740 @@ -914,7 +993,7 @@ static noinline void __init kernel_init_freeable(void)
85741 do_basic_setup();
85742
85743 /* Open the /dev/console on the rootfs, this should never fail */
85744 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
85745 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
85746 pr_err("Warning: unable to open an initial console.\n");
85747
85748 (void) sys_dup(0);
85749 @@ -927,11 +1006,13 @@ static noinline void __init kernel_init_freeable(void)
85750 if (!ramdisk_execute_command)
85751 ramdisk_execute_command = "/init";
85752
85753 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
85754 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
85755 ramdisk_execute_command = NULL;
85756 prepare_namespace();
85757 }
85758
85759 + grsecurity_init();
85760 +
85761 /*
85762 * Ok, we have completed the initial bootup, and
85763 * we're essentially up and running. Get rid of the
85764 diff --git a/ipc/compat.c b/ipc/compat.c
85765 index 45d035d..e4a7f99 100644
85766 --- a/ipc/compat.c
85767 +++ b/ipc/compat.c
85768 @@ -396,7 +396,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
85769 COMPAT_SHMLBA);
85770 if (err < 0)
85771 return err;
85772 - return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
85773 + return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
85774 }
85775 case SHMDT:
85776 return sys_shmdt(compat_ptr(ptr));
85777 diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
85778 index 998d31b..30c24df 100644
85779 --- a/ipc/ipc_sysctl.c
85780 +++ b/ipc/ipc_sysctl.c
85781 @@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
85782 static int proc_ipc_dointvec(ctl_table *table, int write,
85783 void __user *buffer, size_t *lenp, loff_t *ppos)
85784 {
85785 - struct ctl_table ipc_table;
85786 + ctl_table_no_const ipc_table;
85787
85788 memcpy(&ipc_table, table, sizeof(ipc_table));
85789 ipc_table.data = get_ipc(table);
85790 @@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
85791 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
85792 void __user *buffer, size_t *lenp, loff_t *ppos)
85793 {
85794 - struct ctl_table ipc_table;
85795 + ctl_table_no_const ipc_table;
85796
85797 memcpy(&ipc_table, table, sizeof(ipc_table));
85798 ipc_table.data = get_ipc(table);
85799 @@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
85800 static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
85801 void __user *buffer, size_t *lenp, loff_t *ppos)
85802 {
85803 - struct ctl_table ipc_table;
85804 + ctl_table_no_const ipc_table;
85805 size_t lenp_bef = *lenp;
85806 int rc;
85807
85808 @@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
85809 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
85810 void __user *buffer, size_t *lenp, loff_t *ppos)
85811 {
85812 - struct ctl_table ipc_table;
85813 + ctl_table_no_const ipc_table;
85814 memcpy(&ipc_table, table, sizeof(ipc_table));
85815 ipc_table.data = get_ipc(table);
85816
85817 @@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
85818 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
85819 void __user *buffer, size_t *lenp, loff_t *ppos)
85820 {
85821 - struct ctl_table ipc_table;
85822 + ctl_table_no_const ipc_table;
85823 size_t lenp_bef = *lenp;
85824 int oldval;
85825 int rc;
85826 diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
85827 index 5bb8bfe..a38ec05 100644
85828 --- a/ipc/mq_sysctl.c
85829 +++ b/ipc/mq_sysctl.c
85830 @@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
85831 static int proc_mq_dointvec(ctl_table *table, int write,
85832 void __user *buffer, size_t *lenp, loff_t *ppos)
85833 {
85834 - struct ctl_table mq_table;
85835 + ctl_table_no_const mq_table;
85836 memcpy(&mq_table, table, sizeof(mq_table));
85837 mq_table.data = get_mq(table);
85838
85839 @@ -35,7 +35,7 @@ static int proc_mq_dointvec(ctl_table *table, int write,
85840 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
85841 void __user *buffer, size_t *lenp, loff_t *ppos)
85842 {
85843 - struct ctl_table mq_table;
85844 + ctl_table_no_const mq_table;
85845 memcpy(&mq_table, table, sizeof(mq_table));
85846 mq_table.data = get_mq(table);
85847
85848 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
85849 index 4fcf39a..d3cc2ec 100644
85850 --- a/ipc/mqueue.c
85851 +++ b/ipc/mqueue.c
85852 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
85853 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
85854 info->attr.mq_msgsize);
85855
85856 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
85857 spin_lock(&mq_lock);
85858 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
85859 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
85860 diff --git a/ipc/msg.c b/ipc/msg.c
85861 index 6498531..b0ff3c8 100644
85862 --- a/ipc/msg.c
85863 +++ b/ipc/msg.c
85864 @@ -303,18 +303,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
85865 return security_msg_queue_associate(msq, msgflg);
85866 }
85867
85868 +static struct ipc_ops msg_ops = {
85869 + .getnew = newque,
85870 + .associate = msg_security,
85871 + .more_checks = NULL
85872 +};
85873 +
85874 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
85875 {
85876 struct ipc_namespace *ns;
85877 - struct ipc_ops msg_ops;
85878 struct ipc_params msg_params;
85879
85880 ns = current->nsproxy->ipc_ns;
85881
85882 - msg_ops.getnew = newque;
85883 - msg_ops.associate = msg_security;
85884 - msg_ops.more_checks = NULL;
85885 -
85886 msg_params.key = key;
85887 msg_params.flg = msgflg;
85888
85889 diff --git a/ipc/sem.c b/ipc/sem.c
85890 index bee5554..e9af81dd 100644
85891 --- a/ipc/sem.c
85892 +++ b/ipc/sem.c
85893 @@ -561,10 +561,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
85894 return 0;
85895 }
85896
85897 +static struct ipc_ops sem_ops = {
85898 + .getnew = newary,
85899 + .associate = sem_security,
85900 + .more_checks = sem_more_checks
85901 +};
85902 +
85903 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
85904 {
85905 struct ipc_namespace *ns;
85906 - struct ipc_ops sem_ops;
85907 struct ipc_params sem_params;
85908
85909 ns = current->nsproxy->ipc_ns;
85910 @@ -572,10 +577,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
85911 if (nsems < 0 || nsems > ns->sc_semmsl)
85912 return -EINVAL;
85913
85914 - sem_ops.getnew = newary;
85915 - sem_ops.associate = sem_security;
85916 - sem_ops.more_checks = sem_more_checks;
85917 -
85918 sem_params.key = key;
85919 sem_params.flg = semflg;
85920 sem_params.u.nsems = nsems;
85921 diff --git a/ipc/shm.c b/ipc/shm.c
85922 index 7645961..afc7f02 100644
85923 --- a/ipc/shm.c
85924 +++ b/ipc/shm.c
85925 @@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
85926 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
85927 #endif
85928
85929 +#ifdef CONFIG_GRKERNSEC
85930 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
85931 + const time_t shm_createtime, const kuid_t cuid,
85932 + const int shmid);
85933 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
85934 + const time_t shm_createtime);
85935 +#endif
85936 +
85937 void shm_init_ns(struct ipc_namespace *ns)
85938 {
85939 ns->shm_ctlmax = SHMMAX;
85940 @@ -553,6 +561,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
85941 shp->shm_lprid = 0;
85942 shp->shm_atim = shp->shm_dtim = 0;
85943 shp->shm_ctim = get_seconds();
85944 +#ifdef CONFIG_GRKERNSEC
85945 + {
85946 + struct timespec timeval;
85947 + do_posix_clock_monotonic_gettime(&timeval);
85948 +
85949 + shp->shm_createtime = timeval.tv_sec;
85950 + }
85951 +#endif
85952 shp->shm_segsz = size;
85953 shp->shm_nattch = 0;
85954 shp->shm_file = file;
85955 @@ -606,18 +622,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
85956 return 0;
85957 }
85958
85959 +static struct ipc_ops shm_ops = {
85960 + .getnew = newseg,
85961 + .associate = shm_security,
85962 + .more_checks = shm_more_checks
85963 +};
85964 +
85965 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
85966 {
85967 struct ipc_namespace *ns;
85968 - struct ipc_ops shm_ops;
85969 struct ipc_params shm_params;
85970
85971 ns = current->nsproxy->ipc_ns;
85972
85973 - shm_ops.getnew = newseg;
85974 - shm_ops.associate = shm_security;
85975 - shm_ops.more_checks = shm_more_checks;
85976 -
85977 shm_params.key = key;
85978 shm_params.flg = shmflg;
85979 shm_params.u.size = size;
85980 @@ -1088,6 +1105,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85981 f_mode = FMODE_READ | FMODE_WRITE;
85982 }
85983 if (shmflg & SHM_EXEC) {
85984 +
85985 +#ifdef CONFIG_PAX_MPROTECT
85986 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
85987 + goto out;
85988 +#endif
85989 +
85990 prot |= PROT_EXEC;
85991 acc_mode |= S_IXUGO;
85992 }
85993 @@ -1112,6 +1135,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85994 if (err)
85995 goto out_unlock;
85996
85997 +#ifdef CONFIG_GRKERNSEC
85998 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
85999 + shp->shm_perm.cuid, shmid) ||
86000 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
86001 + err = -EACCES;
86002 + goto out_unlock;
86003 + }
86004 +#endif
86005 +
86006 ipc_lock_object(&shp->shm_perm);
86007
86008 /* check if shm_destroy() is tearing down shp */
86009 @@ -1124,6 +1156,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
86010 path = shp->shm_file->f_path;
86011 path_get(&path);
86012 shp->shm_nattch++;
86013 +#ifdef CONFIG_GRKERNSEC
86014 + shp->shm_lapid = current->pid;
86015 +#endif
86016 size = i_size_read(path.dentry->d_inode);
86017 ipc_unlock_object(&shp->shm_perm);
86018 rcu_read_unlock();
86019 diff --git a/ipc/util.c b/ipc/util.c
86020 index 2eb0d1e..0308564 100644
86021 --- a/ipc/util.c
86022 +++ b/ipc/util.c
86023 @@ -71,6 +71,8 @@ struct ipc_proc_iface {
86024 int (*show)(struct seq_file *, void *);
86025 };
86026
86027 +extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
86028 +
86029 static void ipc_memory_notifier(struct work_struct *work)
86030 {
86031 ipcns_notify(IPCNS_MEMCHANGED);
86032 @@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
86033 granted_mode >>= 6;
86034 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
86035 granted_mode >>= 3;
86036 +
86037 + if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
86038 + return -1;
86039 +
86040 /* is there some bit set in requested_mode but not in granted_mode? */
86041 if ((requested_mode & ~granted_mode & 0007) &&
86042 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
86043 diff --git a/kernel/acct.c b/kernel/acct.c
86044 index 8d6e145..33e0b1e 100644
86045 --- a/kernel/acct.c
86046 +++ b/kernel/acct.c
86047 @@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
86048 */
86049 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
86050 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
86051 - file->f_op->write(file, (char *)&ac,
86052 + file->f_op->write(file, (char __force_user *)&ac,
86053 sizeof(acct_t), &file->f_pos);
86054 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
86055 set_fs(fs);
86056 diff --git a/kernel/audit.c b/kernel/audit.c
86057 index 47845c5..bd9dd5b 100644
86058 --- a/kernel/audit.c
86059 +++ b/kernel/audit.c
86060 @@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
86061 3) suppressed due to audit_rate_limit
86062 4) suppressed due to audit_backlog_limit
86063 */
86064 -static atomic_t audit_lost = ATOMIC_INIT(0);
86065 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
86066
86067 /* The netlink socket. */
86068 static struct sock *audit_sock;
86069 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
86070 unsigned long now;
86071 int print;
86072
86073 - atomic_inc(&audit_lost);
86074 + atomic_inc_unchecked(&audit_lost);
86075
86076 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
86077
86078 @@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
86079 if (print) {
86080 if (printk_ratelimit())
86081 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
86082 - atomic_read(&audit_lost),
86083 + atomic_read_unchecked(&audit_lost),
86084 audit_rate_limit,
86085 audit_backlog_limit);
86086 audit_panic(message);
86087 @@ -808,7 +808,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
86088 s.pid = audit_pid;
86089 s.rate_limit = audit_rate_limit;
86090 s.backlog_limit = audit_backlog_limit;
86091 - s.lost = atomic_read(&audit_lost);
86092 + s.lost = atomic_read_unchecked(&audit_lost);
86093 s.backlog = skb_queue_len(&audit_skb_queue);
86094 s.version = AUDIT_VERSION_LATEST;
86095 s.backlog_wait_time = audit_backlog_wait_time;
86096 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
86097 index 21eae3c..66db239 100644
86098 --- a/kernel/auditsc.c
86099 +++ b/kernel/auditsc.c
86100 @@ -2023,7 +2023,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
86101 }
86102
86103 /* global counter which is incremented every time something logs in */
86104 -static atomic_t session_id = ATOMIC_INIT(0);
86105 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
86106
86107 static int audit_set_loginuid_perm(kuid_t loginuid)
86108 {
86109 @@ -2090,7 +2090,7 @@ int audit_set_loginuid(kuid_t loginuid)
86110
86111 /* are we setting or clearing? */
86112 if (uid_valid(loginuid))
86113 - sessionid = (unsigned int)atomic_inc_return(&session_id);
86114 + sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
86115
86116 task->sessionid = sessionid;
86117 task->loginuid = loginuid;
86118 diff --git a/kernel/capability.c b/kernel/capability.c
86119 index 24663b3..b926ae1 100644
86120 --- a/kernel/capability.c
86121 +++ b/kernel/capability.c
86122 @@ -193,6 +193,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
86123 * before modification is attempted and the application
86124 * fails.
86125 */
86126 + if (tocopy > ARRAY_SIZE(kdata))
86127 + return -EFAULT;
86128 +
86129 if (copy_to_user(dataptr, kdata, tocopy
86130 * sizeof(struct __user_cap_data_struct))) {
86131 return -EFAULT;
86132 @@ -294,10 +297,11 @@ bool has_ns_capability(struct task_struct *t,
86133 int ret;
86134
86135 rcu_read_lock();
86136 - ret = security_capable(__task_cred(t), ns, cap);
86137 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
86138 + gr_task_is_capable(t, __task_cred(t), cap);
86139 rcu_read_unlock();
86140
86141 - return (ret == 0);
86142 + return ret;
86143 }
86144
86145 /**
86146 @@ -334,10 +338,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
86147 int ret;
86148
86149 rcu_read_lock();
86150 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
86151 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
86152 rcu_read_unlock();
86153
86154 - return (ret == 0);
86155 + return ret;
86156 }
86157
86158 /**
86159 @@ -375,7 +379,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
86160 BUG();
86161 }
86162
86163 - if (security_capable(current_cred(), ns, cap) == 0) {
86164 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
86165 current->flags |= PF_SUPERPRIV;
86166 return true;
86167 }
86168 @@ -383,6 +387,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
86169 }
86170 EXPORT_SYMBOL(ns_capable);
86171
86172 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
86173 +{
86174 + if (unlikely(!cap_valid(cap))) {
86175 + printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
86176 + BUG();
86177 + }
86178 +
86179 + if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
86180 + current->flags |= PF_SUPERPRIV;
86181 + return true;
86182 + }
86183 + return false;
86184 +}
86185 +EXPORT_SYMBOL(ns_capable_nolog);
86186 +
86187 /**
86188 * file_ns_capable - Determine if the file's opener had a capability in effect
86189 * @file: The file we want to check
86190 @@ -423,6 +442,12 @@ bool capable(int cap)
86191 }
86192 EXPORT_SYMBOL(capable);
86193
86194 +bool capable_nolog(int cap)
86195 +{
86196 + return ns_capable_nolog(&init_user_ns, cap);
86197 +}
86198 +EXPORT_SYMBOL(capable_nolog);
86199 +
86200 /**
86201 * capable_wrt_inode_uidgid - Check nsown_capable and uid and gid mapped
86202 * @inode: The inode in question
86203 @@ -440,3 +465,12 @@ bool capable_wrt_inode_uidgid(const struct inode *inode, int cap)
86204 kgid_has_mapping(ns, inode->i_gid);
86205 }
86206 EXPORT_SYMBOL(capable_wrt_inode_uidgid);
86207 +
86208 +bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap)
86209 +{
86210 + struct user_namespace *ns = current_user_ns();
86211 +
86212 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid) &&
86213 + kgid_has_mapping(ns, inode->i_gid);
86214 +}
86215 +EXPORT_SYMBOL(capable_wrt_inode_uidgid_nolog);
86216 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
86217 index 073226b..969c746 100644
86218 --- a/kernel/cgroup.c
86219 +++ b/kernel/cgroup.c
86220 @@ -4808,7 +4808,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
86221 struct task_struct *task;
86222 int count = 0;
86223
86224 - seq_printf(seq, "css_set %p\n", cset);
86225 + seq_printf(seq, "css_set %pK\n", cset);
86226
86227 list_for_each_entry(task, &cset->tasks, cg_list) {
86228 if (count++ > MAX_TASKS_SHOWN_PER_CSS)
86229 diff --git a/kernel/compat.c b/kernel/compat.c
86230 index e40b043..3da8f51 100644
86231 --- a/kernel/compat.c
86232 +++ b/kernel/compat.c
86233 @@ -13,6 +13,7 @@
86234
86235 #include <linux/linkage.h>
86236 #include <linux/compat.h>
86237 +#include <linux/module.h>
86238 #include <linux/errno.h>
86239 #include <linux/time.h>
86240 #include <linux/signal.h>
86241 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
86242 mm_segment_t oldfs;
86243 long ret;
86244
86245 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
86246 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
86247 oldfs = get_fs();
86248 set_fs(KERNEL_DS);
86249 ret = hrtimer_nanosleep_restart(restart);
86250 @@ -252,7 +253,7 @@ COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec __user *, rqtp,
86251 oldfs = get_fs();
86252 set_fs(KERNEL_DS);
86253 ret = hrtimer_nanosleep(&tu,
86254 - rmtp ? (struct timespec __user *)&rmt : NULL,
86255 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
86256 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
86257 set_fs(oldfs);
86258
86259 @@ -361,7 +362,7 @@ COMPAT_SYSCALL_DEFINE1(sigpending, compat_old_sigset_t __user *, set)
86260 mm_segment_t old_fs = get_fs();
86261
86262 set_fs(KERNEL_DS);
86263 - ret = sys_sigpending((old_sigset_t __user *) &s);
86264 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
86265 set_fs(old_fs);
86266 if (ret == 0)
86267 ret = put_user(s, set);
86268 @@ -451,7 +452,7 @@ COMPAT_SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
86269 mm_segment_t old_fs = get_fs();
86270
86271 set_fs(KERNEL_DS);
86272 - ret = sys_old_getrlimit(resource, (struct rlimit __user *)&r);
86273 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
86274 set_fs(old_fs);
86275
86276 if (!ret) {
86277 @@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
86278 set_fs (KERNEL_DS);
86279 ret = sys_wait4(pid,
86280 (stat_addr ?
86281 - (unsigned int __user *) &status : NULL),
86282 - options, (struct rusage __user *) &r);
86283 + (unsigned int __force_user *) &status : NULL),
86284 + options, (struct rusage __force_user *) &r);
86285 set_fs (old_fs);
86286
86287 if (ret > 0) {
86288 @@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
86289 memset(&info, 0, sizeof(info));
86290
86291 set_fs(KERNEL_DS);
86292 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
86293 - uru ? (struct rusage __user *)&ru : NULL);
86294 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
86295 + uru ? (struct rusage __force_user *)&ru : NULL);
86296 set_fs(old_fs);
86297
86298 if ((ret < 0) || (info.si_signo == 0))
86299 @@ -695,8 +696,8 @@ COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
86300 oldfs = get_fs();
86301 set_fs(KERNEL_DS);
86302 err = sys_timer_settime(timer_id, flags,
86303 - (struct itimerspec __user *) &newts,
86304 - (struct itimerspec __user *) &oldts);
86305 + (struct itimerspec __force_user *) &newts,
86306 + (struct itimerspec __force_user *) &oldts);
86307 set_fs(oldfs);
86308 if (!err && old && put_compat_itimerspec(old, &oldts))
86309 return -EFAULT;
86310 @@ -713,7 +714,7 @@ COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
86311 oldfs = get_fs();
86312 set_fs(KERNEL_DS);
86313 err = sys_timer_gettime(timer_id,
86314 - (struct itimerspec __user *) &ts);
86315 + (struct itimerspec __force_user *) &ts);
86316 set_fs(oldfs);
86317 if (!err && put_compat_itimerspec(setting, &ts))
86318 return -EFAULT;
86319 @@ -732,7 +733,7 @@ COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock,
86320 oldfs = get_fs();
86321 set_fs(KERNEL_DS);
86322 err = sys_clock_settime(which_clock,
86323 - (struct timespec __user *) &ts);
86324 + (struct timespec __force_user *) &ts);
86325 set_fs(oldfs);
86326 return err;
86327 }
86328 @@ -747,7 +748,7 @@ COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock,
86329 oldfs = get_fs();
86330 set_fs(KERNEL_DS);
86331 err = sys_clock_gettime(which_clock,
86332 - (struct timespec __user *) &ts);
86333 + (struct timespec __force_user *) &ts);
86334 set_fs(oldfs);
86335 if (!err && compat_put_timespec(&ts, tp))
86336 return -EFAULT;
86337 @@ -767,7 +768,7 @@ COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock,
86338
86339 oldfs = get_fs();
86340 set_fs(KERNEL_DS);
86341 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
86342 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
86343 set_fs(oldfs);
86344
86345 err = compat_put_timex(utp, &txc);
86346 @@ -787,7 +788,7 @@ COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock,
86347 oldfs = get_fs();
86348 set_fs(KERNEL_DS);
86349 err = sys_clock_getres(which_clock,
86350 - (struct timespec __user *) &ts);
86351 + (struct timespec __force_user *) &ts);
86352 set_fs(oldfs);
86353 if (!err && tp && compat_put_timespec(&ts, tp))
86354 return -EFAULT;
86355 @@ -801,7 +802,7 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
86356 struct timespec tu;
86357 struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
86358
86359 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
86360 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
86361 oldfs = get_fs();
86362 set_fs(KERNEL_DS);
86363 err = clock_nanosleep_restart(restart);
86364 @@ -833,8 +834,8 @@ COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags,
86365 oldfs = get_fs();
86366 set_fs(KERNEL_DS);
86367 err = sys_clock_nanosleep(which_clock, flags,
86368 - (struct timespec __user *) &in,
86369 - (struct timespec __user *) &out);
86370 + (struct timespec __force_user *) &in,
86371 + (struct timespec __force_user *) &out);
86372 set_fs(oldfs);
86373
86374 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
86375 @@ -1128,7 +1129,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
86376 mm_segment_t old_fs = get_fs();
86377
86378 set_fs(KERNEL_DS);
86379 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
86380 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
86381 set_fs(old_fs);
86382 if (compat_put_timespec(&t, interval))
86383 return -EFAULT;
86384 diff --git a/kernel/configs.c b/kernel/configs.c
86385 index c18b1f1..b9a0132 100644
86386 --- a/kernel/configs.c
86387 +++ b/kernel/configs.c
86388 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
86389 struct proc_dir_entry *entry;
86390
86391 /* create the current config file */
86392 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
86393 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
86394 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
86395 + &ikconfig_file_ops);
86396 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
86397 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
86398 + &ikconfig_file_ops);
86399 +#endif
86400 +#else
86401 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
86402 &ikconfig_file_ops);
86403 +#endif
86404 +
86405 if (!entry)
86406 return -ENOMEM;
86407
86408 diff --git a/kernel/cred.c b/kernel/cred.c
86409 index e0573a4..26c0fd3 100644
86410 --- a/kernel/cred.c
86411 +++ b/kernel/cred.c
86412 @@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
86413 validate_creds(cred);
86414 alter_cred_subscribers(cred, -1);
86415 put_cred(cred);
86416 +
86417 +#ifdef CONFIG_GRKERNSEC_SETXID
86418 + cred = (struct cred *) tsk->delayed_cred;
86419 + if (cred != NULL) {
86420 + tsk->delayed_cred = NULL;
86421 + validate_creds(cred);
86422 + alter_cred_subscribers(cred, -1);
86423 + put_cred(cred);
86424 + }
86425 +#endif
86426 }
86427
86428 /**
86429 @@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
86430 * Always returns 0 thus allowing this function to be tail-called at the end
86431 * of, say, sys_setgid().
86432 */
86433 -int commit_creds(struct cred *new)
86434 +static int __commit_creds(struct cred *new)
86435 {
86436 struct task_struct *task = current;
86437 const struct cred *old = task->real_cred;
86438 @@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
86439
86440 get_cred(new); /* we will require a ref for the subj creds too */
86441
86442 + gr_set_role_label(task, new->uid, new->gid);
86443 +
86444 /* dumpability changes */
86445 if (!uid_eq(old->euid, new->euid) ||
86446 !gid_eq(old->egid, new->egid) ||
86447 @@ -479,6 +491,105 @@ int commit_creds(struct cred *new)
86448 put_cred(old);
86449 return 0;
86450 }
86451 +#ifdef CONFIG_GRKERNSEC_SETXID
86452 +extern int set_user(struct cred *new);
86453 +
86454 +void gr_delayed_cred_worker(void)
86455 +{
86456 + const struct cred *new = current->delayed_cred;
86457 + struct cred *ncred;
86458 +
86459 + current->delayed_cred = NULL;
86460 +
86461 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
86462 + // from doing get_cred on it when queueing this
86463 + put_cred(new);
86464 + return;
86465 + } else if (new == NULL)
86466 + return;
86467 +
86468 + ncred = prepare_creds();
86469 + if (!ncred)
86470 + goto die;
86471 + // uids
86472 + ncred->uid = new->uid;
86473 + ncred->euid = new->euid;
86474 + ncred->suid = new->suid;
86475 + ncred->fsuid = new->fsuid;
86476 + // gids
86477 + ncred->gid = new->gid;
86478 + ncred->egid = new->egid;
86479 + ncred->sgid = new->sgid;
86480 + ncred->fsgid = new->fsgid;
86481 + // groups
86482 + set_groups(ncred, new->group_info);
86483 + // caps
86484 + ncred->securebits = new->securebits;
86485 + ncred->cap_inheritable = new->cap_inheritable;
86486 + ncred->cap_permitted = new->cap_permitted;
86487 + ncred->cap_effective = new->cap_effective;
86488 + ncred->cap_bset = new->cap_bset;
86489 +
86490 + if (set_user(ncred)) {
86491 + abort_creds(ncred);
86492 + goto die;
86493 + }
86494 +
86495 + // from doing get_cred on it when queueing this
86496 + put_cred(new);
86497 +
86498 + __commit_creds(ncred);
86499 + return;
86500 +die:
86501 + // from doing get_cred on it when queueing this
86502 + put_cred(new);
86503 + do_group_exit(SIGKILL);
86504 +}
86505 +#endif
86506 +
86507 +int commit_creds(struct cred *new)
86508 +{
86509 +#ifdef CONFIG_GRKERNSEC_SETXID
86510 + int ret;
86511 + int schedule_it = 0;
86512 + struct task_struct *t;
86513 + unsigned oldsecurebits = current_cred()->securebits;
86514 +
86515 + /* we won't get called with tasklist_lock held for writing
86516 + and interrupts disabled as the cred struct in that case is
86517 + init_cred
86518 + */
86519 + if (grsec_enable_setxid && !current_is_single_threaded() &&
86520 + uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
86521 + !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
86522 + schedule_it = 1;
86523 + }
86524 + ret = __commit_creds(new);
86525 + if (schedule_it) {
86526 + rcu_read_lock();
86527 + read_lock(&tasklist_lock);
86528 + for (t = next_thread(current); t != current;
86529 + t = next_thread(t)) {
86530 + /* we'll check if the thread has uid 0 in
86531 + * the delayed worker routine
86532 + */
86533 + if (task_securebits(t) == oldsecurebits &&
86534 + t->delayed_cred == NULL) {
86535 + t->delayed_cred = get_cred(new);
86536 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
86537 + set_tsk_need_resched(t);
86538 + }
86539 + }
86540 + read_unlock(&tasklist_lock);
86541 + rcu_read_unlock();
86542 + }
86543 +
86544 + return ret;
86545 +#else
86546 + return __commit_creds(new);
86547 +#endif
86548 +}
86549 +
86550 EXPORT_SYMBOL(commit_creds);
86551
86552 /**
86553 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
86554 index 2956c8d..cfe1e2e 100644
86555 --- a/kernel/debug/debug_core.c
86556 +++ b/kernel/debug/debug_core.c
86557 @@ -124,7 +124,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
86558 */
86559 static atomic_t masters_in_kgdb;
86560 static atomic_t slaves_in_kgdb;
86561 -static atomic_t kgdb_break_tasklet_var;
86562 +static atomic_unchecked_t kgdb_break_tasklet_var;
86563 atomic_t kgdb_setting_breakpoint;
86564
86565 struct task_struct *kgdb_usethread;
86566 @@ -134,7 +134,7 @@ int kgdb_single_step;
86567 static pid_t kgdb_sstep_pid;
86568
86569 /* to keep track of the CPU which is doing the single stepping*/
86570 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
86571 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
86572
86573 /*
86574 * If you are debugging a problem where roundup (the collection of
86575 @@ -549,7 +549,7 @@ return_normal:
86576 * kernel will only try for the value of sstep_tries before
86577 * giving up and continuing on.
86578 */
86579 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
86580 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
86581 (kgdb_info[cpu].task &&
86582 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
86583 atomic_set(&kgdb_active, -1);
86584 @@ -647,8 +647,8 @@ cpu_master_loop:
86585 }
86586
86587 kgdb_restore:
86588 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
86589 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
86590 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
86591 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
86592 if (kgdb_info[sstep_cpu].task)
86593 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
86594 else
86595 @@ -925,18 +925,18 @@ static void kgdb_unregister_callbacks(void)
86596 static void kgdb_tasklet_bpt(unsigned long ing)
86597 {
86598 kgdb_breakpoint();
86599 - atomic_set(&kgdb_break_tasklet_var, 0);
86600 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
86601 }
86602
86603 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
86604
86605 void kgdb_schedule_breakpoint(void)
86606 {
86607 - if (atomic_read(&kgdb_break_tasklet_var) ||
86608 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
86609 atomic_read(&kgdb_active) != -1 ||
86610 atomic_read(&kgdb_setting_breakpoint))
86611 return;
86612 - atomic_inc(&kgdb_break_tasklet_var);
86613 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
86614 tasklet_schedule(&kgdb_tasklet_breakpoint);
86615 }
86616 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
86617 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
86618 index 0b097c8..11dd5c5 100644
86619 --- a/kernel/debug/kdb/kdb_main.c
86620 +++ b/kernel/debug/kdb/kdb_main.c
86621 @@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
86622 continue;
86623
86624 kdb_printf("%-20s%8u 0x%p ", mod->name,
86625 - mod->core_size, (void *)mod);
86626 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
86627 #ifdef CONFIG_MODULE_UNLOAD
86628 kdb_printf("%4ld ", module_refcount(mod));
86629 #endif
86630 @@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
86631 kdb_printf(" (Loading)");
86632 else
86633 kdb_printf(" (Live)");
86634 - kdb_printf(" 0x%p", mod->module_core);
86635 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
86636
86637 #ifdef CONFIG_MODULE_UNLOAD
86638 {
86639 diff --git a/kernel/events/core.c b/kernel/events/core.c
86640 index 935271c..8888f93 100644
86641 --- a/kernel/events/core.c
86642 +++ b/kernel/events/core.c
86643 @@ -158,8 +158,15 @@ static struct srcu_struct pmus_srcu;
86644 * 0 - disallow raw tracepoint access for unpriv
86645 * 1 - disallow cpu events for unpriv
86646 * 2 - disallow kernel profiling for unpriv
86647 + * 3 - disallow all unpriv perf event use
86648 */
86649 -int sysctl_perf_event_paranoid __read_mostly = 1;
86650 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
86651 +int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
86652 +#elif defined(CONFIG_GRKERNSEC_HIDESYM)
86653 +int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
86654 +#else
86655 +int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
86656 +#endif
86657
86658 /* Minimum for 512 kiB + 1 user control page */
86659 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
86660 @@ -185,7 +192,7 @@ void update_perf_cpu_limits(void)
86661
86662 tmp *= sysctl_perf_cpu_time_max_percent;
86663 do_div(tmp, 100);
86664 - ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
86665 + ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
86666 }
86667
86668 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
86669 @@ -291,7 +298,7 @@ void perf_sample_event_took(u64 sample_len_ns)
86670 }
86671 }
86672
86673 -static atomic64_t perf_event_id;
86674 +static atomic64_unchecked_t perf_event_id;
86675
86676 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
86677 enum event_type_t event_type);
86678 @@ -3002,7 +3009,7 @@ static void __perf_event_read(void *info)
86679
86680 static inline u64 perf_event_count(struct perf_event *event)
86681 {
86682 - return local64_read(&event->count) + atomic64_read(&event->child_count);
86683 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
86684 }
86685
86686 static u64 perf_event_read(struct perf_event *event)
86687 @@ -3361,9 +3368,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
86688 mutex_lock(&event->child_mutex);
86689 total += perf_event_read(event);
86690 *enabled += event->total_time_enabled +
86691 - atomic64_read(&event->child_total_time_enabled);
86692 + atomic64_read_unchecked(&event->child_total_time_enabled);
86693 *running += event->total_time_running +
86694 - atomic64_read(&event->child_total_time_running);
86695 + atomic64_read_unchecked(&event->child_total_time_running);
86696
86697 list_for_each_entry(child, &event->child_list, child_list) {
86698 total += perf_event_read(child);
86699 @@ -3792,10 +3799,10 @@ void perf_event_update_userpage(struct perf_event *event)
86700 userpg->offset -= local64_read(&event->hw.prev_count);
86701
86702 userpg->time_enabled = enabled +
86703 - atomic64_read(&event->child_total_time_enabled);
86704 + atomic64_read_unchecked(&event->child_total_time_enabled);
86705
86706 userpg->time_running = running +
86707 - atomic64_read(&event->child_total_time_running);
86708 + atomic64_read_unchecked(&event->child_total_time_running);
86709
86710 arch_perf_update_userpage(userpg, now);
86711
86712 @@ -4359,7 +4366,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
86713
86714 /* Data. */
86715 sp = perf_user_stack_pointer(regs);
86716 - rem = __output_copy_user(handle, (void *) sp, dump_size);
86717 + rem = __output_copy_user(handle, (void __user *) sp, dump_size);
86718 dyn_size = dump_size - rem;
86719
86720 perf_output_skip(handle, rem);
86721 @@ -4450,11 +4457,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
86722 values[n++] = perf_event_count(event);
86723 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
86724 values[n++] = enabled +
86725 - atomic64_read(&event->child_total_time_enabled);
86726 + atomic64_read_unchecked(&event->child_total_time_enabled);
86727 }
86728 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
86729 values[n++] = running +
86730 - atomic64_read(&event->child_total_time_running);
86731 + atomic64_read_unchecked(&event->child_total_time_running);
86732 }
86733 if (read_format & PERF_FORMAT_ID)
86734 values[n++] = primary_event_id(event);
86735 @@ -6733,7 +6740,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
86736 event->parent = parent_event;
86737
86738 event->ns = get_pid_ns(task_active_pid_ns(current));
86739 - event->id = atomic64_inc_return(&perf_event_id);
86740 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
86741
86742 event->state = PERF_EVENT_STATE_INACTIVE;
86743
86744 @@ -7015,6 +7022,11 @@ SYSCALL_DEFINE5(perf_event_open,
86745 if (flags & ~PERF_FLAG_ALL)
86746 return -EINVAL;
86747
86748 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
86749 + if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
86750 + return -EACCES;
86751 +#endif
86752 +
86753 err = perf_copy_attr(attr_uptr, &attr);
86754 if (err)
86755 return err;
86756 @@ -7353,10 +7365,10 @@ static void sync_child_event(struct perf_event *child_event,
86757 /*
86758 * Add back the child's count to the parent's count:
86759 */
86760 - atomic64_add(child_val, &parent_event->child_count);
86761 - atomic64_add(child_event->total_time_enabled,
86762 + atomic64_add_unchecked(child_val, &parent_event->child_count);
86763 + atomic64_add_unchecked(child_event->total_time_enabled,
86764 &parent_event->child_total_time_enabled);
86765 - atomic64_add(child_event->total_time_running,
86766 + atomic64_add_unchecked(child_event->total_time_running,
86767 &parent_event->child_total_time_running);
86768
86769 /*
86770 diff --git a/kernel/events/internal.h b/kernel/events/internal.h
86771 index 569b2187..19940d9 100644
86772 --- a/kernel/events/internal.h
86773 +++ b/kernel/events/internal.h
86774 @@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
86775 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
86776 }
86777
86778 -#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
86779 +#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
86780 static inline unsigned long \
86781 func_name(struct perf_output_handle *handle, \
86782 - const void *buf, unsigned long len) \
86783 + const void user *buf, unsigned long len) \
86784 { \
86785 unsigned long size, written; \
86786 \
86787 @@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
86788 return 0;
86789 }
86790
86791 -DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
86792 +DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
86793
86794 static inline unsigned long
86795 memcpy_skip(void *dst, const void *src, unsigned long n)
86796 @@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
86797 return 0;
86798 }
86799
86800 -DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
86801 +DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
86802
86803 #ifndef arch_perf_out_copy_user
86804 #define arch_perf_out_copy_user arch_perf_out_copy_user
86805 @@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
86806 }
86807 #endif
86808
86809 -DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
86810 +DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
86811
86812 /* Callchain handling */
86813 extern struct perf_callchain_entry *
86814 diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
86815 index 04709b6..d330828 100644
86816 --- a/kernel/events/uprobes.c
86817 +++ b/kernel/events/uprobes.c
86818 @@ -1666,7 +1666,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
86819 {
86820 struct page *page;
86821 uprobe_opcode_t opcode;
86822 - int result;
86823 + long result;
86824
86825 pagefault_disable();
86826 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
86827 diff --git a/kernel/exit.c b/kernel/exit.c
86828 index 6ed6a1d..edecb0e 100644
86829 --- a/kernel/exit.c
86830 +++ b/kernel/exit.c
86831 @@ -173,6 +173,10 @@ void release_task(struct task_struct * p)
86832 struct task_struct *leader;
86833 int zap_leader;
86834 repeat:
86835 +#ifdef CONFIG_NET
86836 + gr_del_task_from_ip_table(p);
86837 +#endif
86838 +
86839 /* don't need to get the RCU readlock here - the process is dead and
86840 * can't be modifying its own credentials. But shut RCU-lockdep up */
86841 rcu_read_lock();
86842 @@ -330,7 +334,7 @@ int allow_signal(int sig)
86843 * know it'll be handled, so that they don't get converted to
86844 * SIGKILL or just silently dropped.
86845 */
86846 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
86847 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
86848 recalc_sigpending();
86849 spin_unlock_irq(&current->sighand->siglock);
86850 return 0;
86851 @@ -699,6 +703,8 @@ void do_exit(long code)
86852 struct task_struct *tsk = current;
86853 int group_dead;
86854
86855 + set_fs(USER_DS);
86856 +
86857 profile_task_exit(tsk);
86858
86859 WARN_ON(blk_needs_flush_plug(tsk));
86860 @@ -715,7 +721,6 @@ void do_exit(long code)
86861 * mm_release()->clear_child_tid() from writing to a user-controlled
86862 * kernel address.
86863 */
86864 - set_fs(USER_DS);
86865
86866 ptrace_event(PTRACE_EVENT_EXIT, code);
86867
86868 @@ -774,6 +779,9 @@ void do_exit(long code)
86869 tsk->exit_code = code;
86870 taskstats_exit(tsk, group_dead);
86871
86872 + gr_acl_handle_psacct(tsk, code);
86873 + gr_acl_handle_exit();
86874 +
86875 exit_mm(tsk);
86876
86877 if (group_dead)
86878 @@ -893,7 +901,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
86879 * Take down every thread in the group. This is called by fatal signals
86880 * as well as by sys_exit_group (below).
86881 */
86882 -void
86883 +__noreturn void
86884 do_group_exit(int exit_code)
86885 {
86886 struct signal_struct *sig = current->signal;
86887 diff --git a/kernel/fork.c b/kernel/fork.c
86888 index 68b9226..0700bf6 100644
86889 --- a/kernel/fork.c
86890 +++ b/kernel/fork.c
86891 @@ -183,6 +183,48 @@ void thread_info_cache_init(void)
86892 # endif
86893 #endif
86894
86895 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86896 +static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
86897 + int node, void **lowmem_stack)
86898 +{
86899 + struct page *pages[THREAD_SIZE / PAGE_SIZE];
86900 + void *ret = NULL;
86901 + unsigned int i;
86902 +
86903 + *lowmem_stack = alloc_thread_info_node(tsk, node);
86904 + if (*lowmem_stack == NULL)
86905 + goto out;
86906 +
86907 + for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++)
86908 + pages[i] = virt_to_page(*lowmem_stack + (i * PAGE_SIZE));
86909 +
86910 + /* use VM_IOREMAP to gain THREAD_SIZE alignment */
86911 + ret = vmap(pages, THREAD_SIZE / PAGE_SIZE, VM_IOREMAP, PAGE_KERNEL);
86912 + if (ret == NULL) {
86913 + free_thread_info(*lowmem_stack);
86914 + *lowmem_stack = NULL;
86915 + }
86916 +
86917 +out:
86918 + return ret;
86919 +}
86920 +
86921 +static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
86922 +{
86923 + unmap_process_stacks(tsk);
86924 +}
86925 +#else
86926 +static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
86927 + int node, void **lowmem_stack)
86928 +{
86929 + return alloc_thread_info_node(tsk, node);
86930 +}
86931 +static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
86932 +{
86933 + free_thread_info(ti);
86934 +}
86935 +#endif
86936 +
86937 /* SLAB cache for signal_struct structures (tsk->signal) */
86938 static struct kmem_cache *signal_cachep;
86939
86940 @@ -201,18 +243,22 @@ struct kmem_cache *vm_area_cachep;
86941 /* SLAB cache for mm_struct structures (tsk->mm) */
86942 static struct kmem_cache *mm_cachep;
86943
86944 -static void account_kernel_stack(struct thread_info *ti, int account)
86945 +static void account_kernel_stack(struct task_struct *tsk, struct thread_info *ti, int account)
86946 {
86947 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86948 + struct zone *zone = page_zone(virt_to_page(tsk->lowmem_stack));
86949 +#else
86950 struct zone *zone = page_zone(virt_to_page(ti));
86951 +#endif
86952
86953 mod_zone_page_state(zone, NR_KERNEL_STACK, account);
86954 }
86955
86956 void free_task(struct task_struct *tsk)
86957 {
86958 - account_kernel_stack(tsk->stack, -1);
86959 + account_kernel_stack(tsk, tsk->stack, -1);
86960 arch_release_thread_info(tsk->stack);
86961 - free_thread_info(tsk->stack);
86962 + gr_free_thread_info(tsk, tsk->stack);
86963 rt_mutex_debug_task_free(tsk);
86964 ftrace_graph_exit_task(tsk);
86965 put_seccomp_filter(tsk);
86966 @@ -299,6 +345,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86967 struct task_struct *tsk;
86968 struct thread_info *ti;
86969 unsigned long *stackend;
86970 + void *lowmem_stack;
86971 int node = tsk_fork_get_node(orig);
86972 int err;
86973
86974 @@ -306,7 +353,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86975 if (!tsk)
86976 return NULL;
86977
86978 - ti = alloc_thread_info_node(tsk, node);
86979 + ti = gr_alloc_thread_info_node(tsk, node, &lowmem_stack);
86980 if (!ti)
86981 goto free_tsk;
86982
86983 @@ -315,6 +362,9 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86984 goto free_ti;
86985
86986 tsk->stack = ti;
86987 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86988 + tsk->lowmem_stack = lowmem_stack;
86989 +#endif
86990
86991 setup_thread_stack(tsk, orig);
86992 clear_user_return_notifier(tsk);
86993 @@ -323,7 +373,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86994 *stackend = STACK_END_MAGIC; /* for overflow detection */
86995
86996 #ifdef CONFIG_CC_STACKPROTECTOR
86997 - tsk->stack_canary = get_random_int();
86998 + tsk->stack_canary = pax_get_random_long();
86999 #endif
87000
87001 /*
87002 @@ -337,24 +387,92 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
87003 tsk->splice_pipe = NULL;
87004 tsk->task_frag.page = NULL;
87005
87006 - account_kernel_stack(ti, 1);
87007 + account_kernel_stack(tsk, ti, 1);
87008
87009 return tsk;
87010
87011 free_ti:
87012 - free_thread_info(ti);
87013 + gr_free_thread_info(tsk, ti);
87014 free_tsk:
87015 free_task_struct(tsk);
87016 return NULL;
87017 }
87018
87019 #ifdef CONFIG_MMU
87020 -static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
87021 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
87022 +{
87023 + struct vm_area_struct *tmp;
87024 + unsigned long charge;
87025 + struct file *file;
87026 + int retval;
87027 +
87028 + charge = 0;
87029 + if (mpnt->vm_flags & VM_ACCOUNT) {
87030 + unsigned long len = vma_pages(mpnt);
87031 +
87032 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
87033 + goto fail_nomem;
87034 + charge = len;
87035 + }
87036 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
87037 + if (!tmp)
87038 + goto fail_nomem;
87039 + *tmp = *mpnt;
87040 + tmp->vm_mm = mm;
87041 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
87042 + retval = vma_dup_policy(mpnt, tmp);
87043 + if (retval)
87044 + goto fail_nomem_policy;
87045 + if (anon_vma_fork(tmp, mpnt))
87046 + goto fail_nomem_anon_vma_fork;
87047 + tmp->vm_flags &= ~VM_LOCKED;
87048 + tmp->vm_next = tmp->vm_prev = NULL;
87049 + tmp->vm_mirror = NULL;
87050 + file = tmp->vm_file;
87051 + if (file) {
87052 + struct inode *inode = file_inode(file);
87053 + struct address_space *mapping = file->f_mapping;
87054 +
87055 + get_file(file);
87056 + if (tmp->vm_flags & VM_DENYWRITE)
87057 + atomic_dec(&inode->i_writecount);
87058 + mutex_lock(&mapping->i_mmap_mutex);
87059 + if (tmp->vm_flags & VM_SHARED)
87060 + mapping->i_mmap_writable++;
87061 + flush_dcache_mmap_lock(mapping);
87062 + /* insert tmp into the share list, just after mpnt */
87063 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
87064 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
87065 + else
87066 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
87067 + flush_dcache_mmap_unlock(mapping);
87068 + mutex_unlock(&mapping->i_mmap_mutex);
87069 + }
87070 +
87071 + /*
87072 + * Clear hugetlb-related page reserves for children. This only
87073 + * affects MAP_PRIVATE mappings. Faults generated by the child
87074 + * are not guaranteed to succeed, even if read-only
87075 + */
87076 + if (is_vm_hugetlb_page(tmp))
87077 + reset_vma_resv_huge_pages(tmp);
87078 +
87079 + return tmp;
87080 +
87081 +fail_nomem_anon_vma_fork:
87082 + mpol_put(vma_policy(tmp));
87083 +fail_nomem_policy:
87084 + kmem_cache_free(vm_area_cachep, tmp);
87085 +fail_nomem:
87086 + vm_unacct_memory(charge);
87087 + return NULL;
87088 +}
87089 +
87090 +static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
87091 {
87092 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
87093 struct rb_node **rb_link, *rb_parent;
87094 int retval;
87095 - unsigned long charge;
87096
87097 uprobe_start_dup_mmap();
87098 down_write(&oldmm->mmap_sem);
87099 @@ -383,55 +501,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
87100
87101 prev = NULL;
87102 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
87103 - struct file *file;
87104 -
87105 if (mpnt->vm_flags & VM_DONTCOPY) {
87106 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
87107 -vma_pages(mpnt));
87108 continue;
87109 }
87110 - charge = 0;
87111 - if (mpnt->vm_flags & VM_ACCOUNT) {
87112 - unsigned long len = vma_pages(mpnt);
87113 -
87114 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
87115 - goto fail_nomem;
87116 - charge = len;
87117 - }
87118 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
87119 - if (!tmp)
87120 - goto fail_nomem;
87121 - *tmp = *mpnt;
87122 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
87123 - retval = vma_dup_policy(mpnt, tmp);
87124 - if (retval)
87125 - goto fail_nomem_policy;
87126 - tmp->vm_mm = mm;
87127 - if (anon_vma_fork(tmp, mpnt))
87128 - goto fail_nomem_anon_vma_fork;
87129 - tmp->vm_flags &= ~VM_LOCKED;
87130 - tmp->vm_next = tmp->vm_prev = NULL;
87131 - file = tmp->vm_file;
87132 - if (file) {
87133 - struct inode *inode = file_inode(file);
87134 - struct address_space *mapping = file->f_mapping;
87135 -
87136 - get_file(file);
87137 - if (tmp->vm_flags & VM_DENYWRITE)
87138 - atomic_dec(&inode->i_writecount);
87139 - mutex_lock(&mapping->i_mmap_mutex);
87140 - if (tmp->vm_flags & VM_SHARED)
87141 - mapping->i_mmap_writable++;
87142 - flush_dcache_mmap_lock(mapping);
87143 - /* insert tmp into the share list, just after mpnt */
87144 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
87145 - vma_nonlinear_insert(tmp,
87146 - &mapping->i_mmap_nonlinear);
87147 - else
87148 - vma_interval_tree_insert_after(tmp, mpnt,
87149 - &mapping->i_mmap);
87150 - flush_dcache_mmap_unlock(mapping);
87151 - mutex_unlock(&mapping->i_mmap_mutex);
87152 + tmp = dup_vma(mm, oldmm, mpnt);
87153 + if (!tmp) {
87154 + retval = -ENOMEM;
87155 + goto out;
87156 }
87157
87158 /*
87159 @@ -463,6 +541,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
87160 if (retval)
87161 goto out;
87162 }
87163 +
87164 +#ifdef CONFIG_PAX_SEGMEXEC
87165 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
87166 + struct vm_area_struct *mpnt_m;
87167 +
87168 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
87169 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
87170 +
87171 + if (!mpnt->vm_mirror)
87172 + continue;
87173 +
87174 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
87175 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
87176 + mpnt->vm_mirror = mpnt_m;
87177 + } else {
87178 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
87179 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
87180 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
87181 + mpnt->vm_mirror->vm_mirror = mpnt;
87182 + }
87183 + }
87184 + BUG_ON(mpnt_m);
87185 + }
87186 +#endif
87187 +
87188 /* a new mm has just been created */
87189 arch_dup_mmap(oldmm, mm);
87190 retval = 0;
87191 @@ -472,14 +575,6 @@ out:
87192 up_write(&oldmm->mmap_sem);
87193 uprobe_end_dup_mmap();
87194 return retval;
87195 -fail_nomem_anon_vma_fork:
87196 - mpol_put(vma_policy(tmp));
87197 -fail_nomem_policy:
87198 - kmem_cache_free(vm_area_cachep, tmp);
87199 -fail_nomem:
87200 - retval = -ENOMEM;
87201 - vm_unacct_memory(charge);
87202 - goto out;
87203 }
87204
87205 static inline int mm_alloc_pgd(struct mm_struct *mm)
87206 @@ -698,8 +793,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
87207 return ERR_PTR(err);
87208
87209 mm = get_task_mm(task);
87210 - if (mm && mm != current->mm &&
87211 - !ptrace_may_access(task, mode)) {
87212 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
87213 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
87214 mmput(mm);
87215 mm = ERR_PTR(-EACCES);
87216 }
87217 @@ -918,13 +1013,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
87218 spin_unlock(&fs->lock);
87219 return -EAGAIN;
87220 }
87221 - fs->users++;
87222 + atomic_inc(&fs->users);
87223 spin_unlock(&fs->lock);
87224 return 0;
87225 }
87226 tsk->fs = copy_fs_struct(fs);
87227 if (!tsk->fs)
87228 return -ENOMEM;
87229 + /* Carry through gr_chroot_dentry and is_chrooted instead
87230 + of recomputing it here. Already copied when the task struct
87231 + is duplicated. This allows pivot_root to not be treated as
87232 + a chroot
87233 + */
87234 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
87235 +
87236 return 0;
87237 }
87238
87239 @@ -1133,7 +1235,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
87240 * parts of the process environment (as per the clone
87241 * flags). The actual kick-off is left to the caller.
87242 */
87243 -static struct task_struct *copy_process(unsigned long clone_flags,
87244 +static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
87245 unsigned long stack_start,
87246 unsigned long stack_size,
87247 int __user *child_tidptr,
87248 @@ -1205,6 +1307,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
87249 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
87250 #endif
87251 retval = -EAGAIN;
87252 +
87253 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
87254 +
87255 if (atomic_read(&p->real_cred->user->processes) >=
87256 task_rlimit(p, RLIMIT_NPROC)) {
87257 if (p->real_cred->user != INIT_USER &&
87258 @@ -1452,6 +1557,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
87259 goto bad_fork_free_pid;
87260 }
87261
87262 + /* synchronizes with gr_set_acls()
87263 + we need to call this past the point of no return for fork()
87264 + */
87265 + gr_copy_label(p);
87266 +
87267 if (likely(p->pid)) {
87268 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
87269
87270 @@ -1541,6 +1651,8 @@ bad_fork_cleanup_count:
87271 bad_fork_free:
87272 free_task(p);
87273 fork_out:
87274 + gr_log_forkfail(retval);
87275 +
87276 return ERR_PTR(retval);
87277 }
87278
87279 @@ -1602,6 +1714,7 @@ long do_fork(unsigned long clone_flags,
87280
87281 p = copy_process(clone_flags, stack_start, stack_size,
87282 child_tidptr, NULL, trace);
87283 + add_latent_entropy();
87284 /*
87285 * Do this prior waking up the new thread - the thread pointer
87286 * might get invalid after that point, if the thread exits quickly.
87287 @@ -1618,6 +1731,8 @@ long do_fork(unsigned long clone_flags,
87288 if (clone_flags & CLONE_PARENT_SETTID)
87289 put_user(nr, parent_tidptr);
87290
87291 + gr_handle_brute_check();
87292 +
87293 if (clone_flags & CLONE_VFORK) {
87294 p->vfork_done = &vfork;
87295 init_completion(&vfork);
87296 @@ -1736,7 +1851,7 @@ void __init proc_caches_init(void)
87297 mm_cachep = kmem_cache_create("mm_struct",
87298 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
87299 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
87300 - vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
87301 + vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
87302 mmap_init();
87303 nsproxy_cache_init();
87304 }
87305 @@ -1776,7 +1891,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
87306 return 0;
87307
87308 /* don't need lock here; in the worst case we'll do useless copy */
87309 - if (fs->users == 1)
87310 + if (atomic_read(&fs->users) == 1)
87311 return 0;
87312
87313 *new_fsp = copy_fs_struct(fs);
87314 @@ -1883,7 +1998,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
87315 fs = current->fs;
87316 spin_lock(&fs->lock);
87317 current->fs = new_fs;
87318 - if (--fs->users)
87319 + gr_set_chroot_entries(current, &current->fs->root);
87320 + if (atomic_dec_return(&fs->users))
87321 new_fs = NULL;
87322 else
87323 new_fs = fs;
87324 diff --git a/kernel/futex.c b/kernel/futex.c
87325 index de938d2..c566038 100644
87326 --- a/kernel/futex.c
87327 +++ b/kernel/futex.c
87328 @@ -202,7 +202,7 @@ struct futex_pi_state {
87329 atomic_t refcount;
87330
87331 union futex_key key;
87332 -};
87333 +} __randomize_layout;
87334
87335 /**
87336 * struct futex_q - The hashed futex queue entry, one per waiting task
87337 @@ -236,7 +236,7 @@ struct futex_q {
87338 struct rt_mutex_waiter *rt_waiter;
87339 union futex_key *requeue_pi_key;
87340 u32 bitset;
87341 -};
87342 +} __randomize_layout;
87343
87344 static const struct futex_q futex_q_init = {
87345 /* list gets initialized in queue_me()*/
87346 @@ -394,6 +394,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
87347 struct page *page, *page_head;
87348 int err, ro = 0;
87349
87350 +#ifdef CONFIG_PAX_SEGMEXEC
87351 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
87352 + return -EFAULT;
87353 +#endif
87354 +
87355 /*
87356 * The futex address must be "naturally" aligned.
87357 */
87358 @@ -593,7 +598,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
87359
87360 static int get_futex_value_locked(u32 *dest, u32 __user *from)
87361 {
87362 - int ret;
87363 + unsigned long ret;
87364
87365 pagefault_disable();
87366 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
87367 @@ -3033,6 +3038,7 @@ static void __init futex_detect_cmpxchg(void)
87368 {
87369 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
87370 u32 curval;
87371 + mm_segment_t oldfs;
87372
87373 /*
87374 * This will fail and we want it. Some arch implementations do
87375 @@ -3044,8 +3050,11 @@ static void __init futex_detect_cmpxchg(void)
87376 * implementation, the non-functional ones will return
87377 * -ENOSYS.
87378 */
87379 + oldfs = get_fs();
87380 + set_fs(USER_DS);
87381 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
87382 futex_cmpxchg_enabled = 1;
87383 + set_fs(oldfs);
87384 #endif
87385 }
87386
87387 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
87388 index 55c8c93..9ba7ad6 100644
87389 --- a/kernel/futex_compat.c
87390 +++ b/kernel/futex_compat.c
87391 @@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
87392 return 0;
87393 }
87394
87395 -static void __user *futex_uaddr(struct robust_list __user *entry,
87396 +static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
87397 compat_long_t futex_offset)
87398 {
87399 compat_uptr_t base = ptr_to_compat(entry);
87400 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
87401 index f45b75b..bfac6d5 100644
87402 --- a/kernel/gcov/base.c
87403 +++ b/kernel/gcov/base.c
87404 @@ -108,11 +108,6 @@ void gcov_enable_events(void)
87405 }
87406
87407 #ifdef CONFIG_MODULES
87408 -static inline int within(void *addr, void *start, unsigned long size)
87409 -{
87410 - return ((addr >= start) && (addr < start + size));
87411 -}
87412 -
87413 /* Update list and generate events when modules are unloaded. */
87414 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
87415 void *data)
87416 @@ -127,7 +122,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
87417
87418 /* Remove entries located in module from linked list. */
87419 while ((info = gcov_info_next(info))) {
87420 - if (within(info, mod->module_core, mod->core_size)) {
87421 + if (within_module_core_rw((unsigned long)info, mod)) {
87422 gcov_info_unlink(prev, info);
87423 if (gcov_events_enabled)
87424 gcov_event(GCOV_REMOVE, info);
87425 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
87426 index e0501fe..312edd6 100644
87427 --- a/kernel/hrtimer.c
87428 +++ b/kernel/hrtimer.c
87429 @@ -1448,7 +1448,7 @@ void hrtimer_peek_ahead_timers(void)
87430 local_irq_restore(flags);
87431 }
87432
87433 -static void run_hrtimer_softirq(struct softirq_action *h)
87434 +static __latent_entropy void run_hrtimer_softirq(void)
87435 {
87436 hrtimer_peek_ahead_timers();
87437 }
87438 diff --git a/kernel/irq_work.c b/kernel/irq_work.c
87439 index a82170e..5b01e7f 100644
87440 --- a/kernel/irq_work.c
87441 +++ b/kernel/irq_work.c
87442 @@ -191,12 +191,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
87443 return NOTIFY_OK;
87444 }
87445
87446 -static struct notifier_block cpu_notify;
87447 +static struct notifier_block cpu_notify = {
87448 + .notifier_call = irq_work_cpu_notify,
87449 + .priority = 0,
87450 +};
87451
87452 static __init int irq_work_init_cpu_notifier(void)
87453 {
87454 - cpu_notify.notifier_call = irq_work_cpu_notify;
87455 - cpu_notify.priority = 0;
87456 register_cpu_notifier(&cpu_notify);
87457 return 0;
87458 }
87459 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
87460 index 9019f15..9a3c42e 100644
87461 --- a/kernel/jump_label.c
87462 +++ b/kernel/jump_label.c
87463 @@ -14,6 +14,7 @@
87464 #include <linux/err.h>
87465 #include <linux/static_key.h>
87466 #include <linux/jump_label_ratelimit.h>
87467 +#include <linux/mm.h>
87468
87469 #ifdef HAVE_JUMP_LABEL
87470
87471 @@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
87472
87473 size = (((unsigned long)stop - (unsigned long)start)
87474 / sizeof(struct jump_entry));
87475 + pax_open_kernel();
87476 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
87477 + pax_close_kernel();
87478 }
87479
87480 static void jump_label_update(struct static_key *key, int enable);
87481 @@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
87482 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
87483 struct jump_entry *iter;
87484
87485 + pax_open_kernel();
87486 for (iter = iter_start; iter < iter_stop; iter++) {
87487 if (within_module_init(iter->code, mod))
87488 iter->code = 0;
87489 }
87490 + pax_close_kernel();
87491 }
87492
87493 static int
87494 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
87495 index cb0cf37..b69e161 100644
87496 --- a/kernel/kallsyms.c
87497 +++ b/kernel/kallsyms.c
87498 @@ -11,6 +11,9 @@
87499 * Changed the compression method from stem compression to "table lookup"
87500 * compression (see scripts/kallsyms.c for a more complete description)
87501 */
87502 +#ifdef CONFIG_GRKERNSEC_HIDESYM
87503 +#define __INCLUDED_BY_HIDESYM 1
87504 +#endif
87505 #include <linux/kallsyms.h>
87506 #include <linux/module.h>
87507 #include <linux/init.h>
87508 @@ -54,12 +57,33 @@ extern const unsigned long kallsyms_markers[] __weak;
87509
87510 static inline int is_kernel_inittext(unsigned long addr)
87511 {
87512 + if (system_state != SYSTEM_BOOTING)
87513 + return 0;
87514 +
87515 if (addr >= (unsigned long)_sinittext
87516 && addr <= (unsigned long)_einittext)
87517 return 1;
87518 return 0;
87519 }
87520
87521 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
87522 +#ifdef CONFIG_MODULES
87523 +static inline int is_module_text(unsigned long addr)
87524 +{
87525 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
87526 + return 1;
87527 +
87528 + addr = ktla_ktva(addr);
87529 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
87530 +}
87531 +#else
87532 +static inline int is_module_text(unsigned long addr)
87533 +{
87534 + return 0;
87535 +}
87536 +#endif
87537 +#endif
87538 +
87539 static inline int is_kernel_text(unsigned long addr)
87540 {
87541 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
87542 @@ -70,13 +94,28 @@ static inline int is_kernel_text(unsigned long addr)
87543
87544 static inline int is_kernel(unsigned long addr)
87545 {
87546 +
87547 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
87548 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
87549 + return 1;
87550 +
87551 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
87552 +#else
87553 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
87554 +#endif
87555 +
87556 return 1;
87557 return in_gate_area_no_mm(addr);
87558 }
87559
87560 static int is_ksym_addr(unsigned long addr)
87561 {
87562 +
87563 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
87564 + if (is_module_text(addr))
87565 + return 0;
87566 +#endif
87567 +
87568 if (all_var)
87569 return is_kernel(addr);
87570
87571 @@ -481,7 +520,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
87572
87573 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
87574 {
87575 - iter->name[0] = '\0';
87576 iter->nameoff = get_symbol_offset(new_pos);
87577 iter->pos = new_pos;
87578 }
87579 @@ -529,6 +567,11 @@ static int s_show(struct seq_file *m, void *p)
87580 {
87581 struct kallsym_iter *iter = m->private;
87582
87583 +#ifdef CONFIG_GRKERNSEC_HIDESYM
87584 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
87585 + return 0;
87586 +#endif
87587 +
87588 /* Some debugging symbols have no name. Ignore them. */
87589 if (!iter->name[0])
87590 return 0;
87591 @@ -542,6 +585,7 @@ static int s_show(struct seq_file *m, void *p)
87592 */
87593 type = iter->exported ? toupper(iter->type) :
87594 tolower(iter->type);
87595 +
87596 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
87597 type, iter->name, iter->module_name);
87598 } else
87599 @@ -567,7 +611,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
87600 struct kallsym_iter *iter;
87601 int ret;
87602
87603 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
87604 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
87605 if (!iter)
87606 return -ENOMEM;
87607 reset_iter(iter, 0);
87608 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
87609 index e30ac0f..3528cac 100644
87610 --- a/kernel/kcmp.c
87611 +++ b/kernel/kcmp.c
87612 @@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
87613 struct task_struct *task1, *task2;
87614 int ret;
87615
87616 +#ifdef CONFIG_GRKERNSEC
87617 + return -ENOSYS;
87618 +#endif
87619 +
87620 rcu_read_lock();
87621
87622 /*
87623 diff --git a/kernel/kexec.c b/kernel/kexec.c
87624 index 28c5706..bfc8388 100644
87625 --- a/kernel/kexec.c
87626 +++ b/kernel/kexec.c
87627 @@ -1046,7 +1046,8 @@ COMPAT_SYSCALL_DEFINE4(kexec_load, compat_ulong_t, entry,
87628 compat_ulong_t, flags)
87629 {
87630 struct compat_kexec_segment in;
87631 - struct kexec_segment out, __user *ksegments;
87632 + struct kexec_segment out;
87633 + struct kexec_segment __user *ksegments;
87634 unsigned long i, result;
87635
87636 /* Don't allow clients that don't understand the native
87637 diff --git a/kernel/kmod.c b/kernel/kmod.c
87638 index 6b375af..eaff670 100644
87639 --- a/kernel/kmod.c
87640 +++ b/kernel/kmod.c
87641 @@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
87642 kfree(info->argv);
87643 }
87644
87645 -static int call_modprobe(char *module_name, int wait)
87646 +static int call_modprobe(char *module_name, char *module_param, int wait)
87647 {
87648 struct subprocess_info *info;
87649 static char *envp[] = {
87650 @@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
87651 NULL
87652 };
87653
87654 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
87655 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
87656 if (!argv)
87657 goto out;
87658
87659 @@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
87660 argv[1] = "-q";
87661 argv[2] = "--";
87662 argv[3] = module_name; /* check free_modprobe_argv() */
87663 - argv[4] = NULL;
87664 + argv[4] = module_param;
87665 + argv[5] = NULL;
87666
87667 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
87668 NULL, free_modprobe_argv, NULL);
87669 @@ -129,9 +130,8 @@ out:
87670 * If module auto-loading support is disabled then this function
87671 * becomes a no-operation.
87672 */
87673 -int __request_module(bool wait, const char *fmt, ...)
87674 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
87675 {
87676 - va_list args;
87677 char module_name[MODULE_NAME_LEN];
87678 unsigned int max_modprobes;
87679 int ret;
87680 @@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
87681 if (!modprobe_path[0])
87682 return 0;
87683
87684 - va_start(args, fmt);
87685 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
87686 - va_end(args);
87687 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
87688 if (ret >= MODULE_NAME_LEN)
87689 return -ENAMETOOLONG;
87690
87691 @@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
87692 if (ret)
87693 return ret;
87694
87695 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
87696 + if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
87697 + /* hack to workaround consolekit/udisks stupidity */
87698 + read_lock(&tasklist_lock);
87699 + if (!strcmp(current->comm, "mount") &&
87700 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
87701 + read_unlock(&tasklist_lock);
87702 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
87703 + return -EPERM;
87704 + }
87705 + read_unlock(&tasklist_lock);
87706 + }
87707 +#endif
87708 +
87709 /* If modprobe needs a service that is in a module, we get a recursive
87710 * loop. Limit the number of running kmod threads to max_threads/2 or
87711 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
87712 @@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
87713
87714 trace_module_request(module_name, wait, _RET_IP_);
87715
87716 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
87717 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
87718
87719 atomic_dec(&kmod_concurrent);
87720 return ret;
87721 }
87722 +
87723 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
87724 +{
87725 + va_list args;
87726 + int ret;
87727 +
87728 + va_start(args, fmt);
87729 + ret = ____request_module(wait, module_param, fmt, args);
87730 + va_end(args);
87731 +
87732 + return ret;
87733 +}
87734 +
87735 +int __request_module(bool wait, const char *fmt, ...)
87736 +{
87737 + va_list args;
87738 + int ret;
87739 +
87740 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
87741 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
87742 + char module_param[MODULE_NAME_LEN];
87743 +
87744 + memset(module_param, 0, sizeof(module_param));
87745 +
87746 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
87747 +
87748 + va_start(args, fmt);
87749 + ret = ____request_module(wait, module_param, fmt, args);
87750 + va_end(args);
87751 +
87752 + return ret;
87753 + }
87754 +#endif
87755 +
87756 + va_start(args, fmt);
87757 + ret = ____request_module(wait, NULL, fmt, args);
87758 + va_end(args);
87759 +
87760 + return ret;
87761 +}
87762 +
87763 EXPORT_SYMBOL(__request_module);
87764 #endif /* CONFIG_MODULES */
87765
87766 @@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
87767 */
87768 set_user_nice(current, 0);
87769
87770 +#ifdef CONFIG_GRKERNSEC
87771 + /* this is race-free as far as userland is concerned as we copied
87772 + out the path to be used prior to this point and are now operating
87773 + on that copy
87774 + */
87775 + if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
87776 + strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
87777 + strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
87778 + printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
87779 + retval = -EPERM;
87780 + goto fail;
87781 + }
87782 +#endif
87783 +
87784 retval = -ENOMEM;
87785 new = prepare_kernel_cred(current);
87786 if (!new)
87787 @@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
87788 commit_creds(new);
87789
87790 retval = do_execve(getname_kernel(sub_info->path),
87791 - (const char __user *const __user *)sub_info->argv,
87792 - (const char __user *const __user *)sub_info->envp);
87793 + (const char __user *const __force_user *)sub_info->argv,
87794 + (const char __user *const __force_user *)sub_info->envp);
87795 if (!retval)
87796 return 0;
87797
87798 @@ -260,6 +327,10 @@ static int call_helper(void *data)
87799
87800 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
87801 {
87802 +#ifdef CONFIG_GRKERNSEC
87803 + kfree(info->path);
87804 + info->path = info->origpath;
87805 +#endif
87806 if (info->cleanup)
87807 (*info->cleanup)(info);
87808 kfree(info);
87809 @@ -303,7 +374,7 @@ static int wait_for_helper(void *data)
87810 *
87811 * Thus the __user pointer cast is valid here.
87812 */
87813 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
87814 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
87815
87816 /*
87817 * If ret is 0, either ____call_usermodehelper failed and the
87818 @@ -542,7 +613,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
87819 goto out;
87820
87821 INIT_WORK(&sub_info->work, __call_usermodehelper);
87822 +#ifdef CONFIG_GRKERNSEC
87823 + sub_info->origpath = path;
87824 + sub_info->path = kstrdup(path, gfp_mask);
87825 +#else
87826 sub_info->path = path;
87827 +#endif
87828 sub_info->argv = argv;
87829 sub_info->envp = envp;
87830
87831 @@ -650,7 +726,7 @@ EXPORT_SYMBOL(call_usermodehelper);
87832 static int proc_cap_handler(struct ctl_table *table, int write,
87833 void __user *buffer, size_t *lenp, loff_t *ppos)
87834 {
87835 - struct ctl_table t;
87836 + ctl_table_no_const t;
87837 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
87838 kernel_cap_t new_cap;
87839 int err, i;
87840 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
87841 index ceeadfc..11c18b6 100644
87842 --- a/kernel/kprobes.c
87843 +++ b/kernel/kprobes.c
87844 @@ -31,6 +31,9 @@
87845 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
87846 * <prasanna@in.ibm.com> added function-return probes.
87847 */
87848 +#ifdef CONFIG_GRKERNSEC_HIDESYM
87849 +#define __INCLUDED_BY_HIDESYM 1
87850 +#endif
87851 #include <linux/kprobes.h>
87852 #include <linux/hash.h>
87853 #include <linux/init.h>
87854 @@ -135,12 +138,12 @@ enum kprobe_slot_state {
87855
87856 static void *alloc_insn_page(void)
87857 {
87858 - return module_alloc(PAGE_SIZE);
87859 + return module_alloc_exec(PAGE_SIZE);
87860 }
87861
87862 static void free_insn_page(void *page)
87863 {
87864 - module_free(NULL, page);
87865 + module_free_exec(NULL, page);
87866 }
87867
87868 struct kprobe_insn_cache kprobe_insn_slots = {
87869 @@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
87870 kprobe_type = "k";
87871
87872 if (sym)
87873 - seq_printf(pi, "%p %s %s+0x%x %s ",
87874 + seq_printf(pi, "%pK %s %s+0x%x %s ",
87875 p->addr, kprobe_type, sym, offset,
87876 (modname ? modname : " "));
87877 else
87878 - seq_printf(pi, "%p %s %p ",
87879 + seq_printf(pi, "%pK %s %pK ",
87880 p->addr, kprobe_type, p->addr);
87881
87882 if (!pp)
87883 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
87884 index 2495a9b..071b906 100644
87885 --- a/kernel/ksysfs.c
87886 +++ b/kernel/ksysfs.c
87887 @@ -49,6 +49,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
87888 {
87889 if (count+1 > UEVENT_HELPER_PATH_LEN)
87890 return -ENOENT;
87891 + if (!capable(CAP_SYS_ADMIN))
87892 + return -EPERM;
87893 memcpy(uevent_helper, buf, count);
87894 uevent_helper[count] = '\0';
87895 if (count && uevent_helper[count-1] == '\n')
87896 @@ -175,7 +177,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
87897 return count;
87898 }
87899
87900 -static struct bin_attribute notes_attr = {
87901 +static bin_attribute_no_const notes_attr __read_only = {
87902 .attr = {
87903 .name = "notes",
87904 .mode = S_IRUGO,
87905 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
87906 index d24e433..fa04fb8 100644
87907 --- a/kernel/locking/lockdep.c
87908 +++ b/kernel/locking/lockdep.c
87909 @@ -597,6 +597,10 @@ static int static_obj(void *obj)
87910 end = (unsigned long) &_end,
87911 addr = (unsigned long) obj;
87912
87913 +#ifdef CONFIG_PAX_KERNEXEC
87914 + start = ktla_ktva(start);
87915 +#endif
87916 +
87917 /*
87918 * static variable?
87919 */
87920 @@ -738,6 +742,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
87921 if (!static_obj(lock->key)) {
87922 debug_locks_off();
87923 printk("INFO: trying to register non-static key.\n");
87924 + printk("lock:%pS key:%pS.\n", lock, lock->key);
87925 printk("the code is fine but needs lockdep annotation.\n");
87926 printk("turning off the locking correctness validator.\n");
87927 dump_stack();
87928 @@ -3079,7 +3084,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
87929 if (!class)
87930 return 0;
87931 }
87932 - atomic_inc((atomic_t *)&class->ops);
87933 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
87934 if (very_verbose(class)) {
87935 printk("\nacquire class [%p] %s", class->key, class->name);
87936 if (class->name_version > 1)
87937 diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
87938 index ef43ac4..2720dfa 100644
87939 --- a/kernel/locking/lockdep_proc.c
87940 +++ b/kernel/locking/lockdep_proc.c
87941 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
87942 return 0;
87943 }
87944
87945 - seq_printf(m, "%p", class->key);
87946 + seq_printf(m, "%pK", class->key);
87947 #ifdef CONFIG_DEBUG_LOCKDEP
87948 seq_printf(m, " OPS:%8ld", class->ops);
87949 #endif
87950 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
87951
87952 list_for_each_entry(entry, &class->locks_after, entry) {
87953 if (entry->distance == 1) {
87954 - seq_printf(m, " -> [%p] ", entry->class->key);
87955 + seq_printf(m, " -> [%pK] ", entry->class->key);
87956 print_name(m, entry->class);
87957 seq_puts(m, "\n");
87958 }
87959 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
87960 if (!class->key)
87961 continue;
87962
87963 - seq_printf(m, "[%p] ", class->key);
87964 + seq_printf(m, "[%pK] ", class->key);
87965 print_name(m, class);
87966 seq_puts(m, "\n");
87967 }
87968 @@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
87969 if (!i)
87970 seq_line(m, '-', 40-namelen, namelen);
87971
87972 - snprintf(ip, sizeof(ip), "[<%p>]",
87973 + snprintf(ip, sizeof(ip), "[<%pK>]",
87974 (void *)class->contention_point[i]);
87975 seq_printf(m, "%40s %14lu %29s %pS\n",
87976 name, stats->contention_point[i],
87977 @@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
87978 if (!i)
87979 seq_line(m, '-', 40-namelen, namelen);
87980
87981 - snprintf(ip, sizeof(ip), "[<%p>]",
87982 + snprintf(ip, sizeof(ip), "[<%pK>]",
87983 (void *)class->contending_point[i]);
87984 seq_printf(m, "%40s %14lu %29s %pS\n",
87985 name, stats->contending_point[i],
87986 diff --git a/kernel/locking/mcs_spinlock.c b/kernel/locking/mcs_spinlock.c
87987 index 838dc9e..760e158 100644
87988 --- a/kernel/locking/mcs_spinlock.c
87989 +++ b/kernel/locking/mcs_spinlock.c
87990 @@ -71,7 +71,7 @@ bool osq_lock(struct optimistic_spin_queue **lock)
87991 if (likely(prev == NULL))
87992 return true;
87993
87994 - ACCESS_ONCE(prev->next) = node;
87995 + ACCESS_ONCE_RW(prev->next) = node;
87996
87997 /*
87998 * Normally @prev is untouchable after the above store; because at that
87999 @@ -143,8 +143,8 @@ unqueue:
88000 * it will wait in Step-A.
88001 */
88002
88003 - ACCESS_ONCE(next->prev) = prev;
88004 - ACCESS_ONCE(prev->next) = next;
88005 + ACCESS_ONCE_RW(next->prev) = prev;
88006 + ACCESS_ONCE_RW(prev->next) = next;
88007
88008 return false;
88009 }
88010 @@ -165,13 +165,13 @@ void osq_unlock(struct optimistic_spin_queue **lock)
88011 */
88012 next = xchg(&node->next, NULL);
88013 if (next) {
88014 - ACCESS_ONCE(next->locked) = 1;
88015 + ACCESS_ONCE_RW(next->locked) = 1;
88016 return;
88017 }
88018
88019 next = osq_wait_next(lock, node, NULL);
88020 if (next)
88021 - ACCESS_ONCE(next->locked) = 1;
88022 + ACCESS_ONCE_RW(next->locked) = 1;
88023 }
88024
88025 #endif
88026 diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h
88027 index a2dbac4..e02a34a 100644
88028 --- a/kernel/locking/mcs_spinlock.h
88029 +++ b/kernel/locking/mcs_spinlock.h
88030 @@ -81,7 +81,7 @@ void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node)
88031 */
88032 return;
88033 }
88034 - ACCESS_ONCE(prev->next) = node;
88035 + ACCESS_ONCE_RW(prev->next) = node;
88036
88037 /* Wait until the lock holder passes the lock down. */
88038 arch_mcs_spin_lock_contended(&node->locked);
88039 diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
88040 index 5cf6731..ce3bc5a 100644
88041 --- a/kernel/locking/mutex-debug.c
88042 +++ b/kernel/locking/mutex-debug.c
88043 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
88044 }
88045
88046 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
88047 - struct thread_info *ti)
88048 + struct task_struct *task)
88049 {
88050 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
88051
88052 /* Mark the current thread as blocked on the lock: */
88053 - ti->task->blocked_on = waiter;
88054 + task->blocked_on = waiter;
88055 }
88056
88057 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
88058 - struct thread_info *ti)
88059 + struct task_struct *task)
88060 {
88061 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
88062 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
88063 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
88064 - ti->task->blocked_on = NULL;
88065 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
88066 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
88067 + task->blocked_on = NULL;
88068
88069 list_del_init(&waiter->list);
88070 waiter->task = NULL;
88071 diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
88072 index 0799fd3..d06ae3b 100644
88073 --- a/kernel/locking/mutex-debug.h
88074 +++ b/kernel/locking/mutex-debug.h
88075 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
88076 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
88077 extern void debug_mutex_add_waiter(struct mutex *lock,
88078 struct mutex_waiter *waiter,
88079 - struct thread_info *ti);
88080 + struct task_struct *task);
88081 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
88082 - struct thread_info *ti);
88083 + struct task_struct *task);
88084 extern void debug_mutex_unlock(struct mutex *lock);
88085 extern void debug_mutex_init(struct mutex *lock, const char *name,
88086 struct lock_class_key *key);
88087 diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
88088 index bc73d33..6f308aa 100644
88089 --- a/kernel/locking/mutex.c
88090 +++ b/kernel/locking/mutex.c
88091 @@ -490,7 +490,7 @@ slowpath:
88092 goto skip_wait;
88093
88094 debug_mutex_lock_common(lock, &waiter);
88095 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
88096 + debug_mutex_add_waiter(lock, &waiter, task);
88097
88098 /* add waiting tasks to the end of the waitqueue (FIFO): */
88099 list_add_tail(&waiter.list, &lock->wait_list);
88100 @@ -534,7 +534,7 @@ slowpath:
88101 schedule_preempt_disabled();
88102 spin_lock_mutex(&lock->wait_lock, flags);
88103 }
88104 - mutex_remove_waiter(lock, &waiter, current_thread_info());
88105 + mutex_remove_waiter(lock, &waiter, task);
88106 /* set it to 0 if there are no waiters left: */
88107 if (likely(list_empty(&lock->wait_list)))
88108 atomic_set(&lock->count, 0);
88109 @@ -571,7 +571,7 @@ skip_wait:
88110 return 0;
88111
88112 err:
88113 - mutex_remove_waiter(lock, &waiter, task_thread_info(task));
88114 + mutex_remove_waiter(lock, &waiter, task);
88115 spin_unlock_mutex(&lock->wait_lock, flags);
88116 debug_mutex_free_waiter(&waiter);
88117 mutex_release(&lock->dep_map, 1, ip);
88118 diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
88119 index 1d96dd0..994ff19 100644
88120 --- a/kernel/locking/rtmutex-tester.c
88121 +++ b/kernel/locking/rtmutex-tester.c
88122 @@ -22,7 +22,7 @@
88123 #define MAX_RT_TEST_MUTEXES 8
88124
88125 static spinlock_t rttest_lock;
88126 -static atomic_t rttest_event;
88127 +static atomic_unchecked_t rttest_event;
88128
88129 struct test_thread_data {
88130 int opcode;
88131 @@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
88132
88133 case RTTEST_LOCKCONT:
88134 td->mutexes[td->opdata] = 1;
88135 - td->event = atomic_add_return(1, &rttest_event);
88136 + td->event = atomic_add_return_unchecked(1, &rttest_event);
88137 return 0;
88138
88139 case RTTEST_RESET:
88140 @@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
88141 return 0;
88142
88143 case RTTEST_RESETEVENT:
88144 - atomic_set(&rttest_event, 0);
88145 + atomic_set_unchecked(&rttest_event, 0);
88146 return 0;
88147
88148 default:
88149 @@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
88150 return ret;
88151
88152 td->mutexes[id] = 1;
88153 - td->event = atomic_add_return(1, &rttest_event);
88154 + td->event = atomic_add_return_unchecked(1, &rttest_event);
88155 rt_mutex_lock(&mutexes[id]);
88156 - td->event = atomic_add_return(1, &rttest_event);
88157 + td->event = atomic_add_return_unchecked(1, &rttest_event);
88158 td->mutexes[id] = 4;
88159 return 0;
88160
88161 @@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
88162 return ret;
88163
88164 td->mutexes[id] = 1;
88165 - td->event = atomic_add_return(1, &rttest_event);
88166 + td->event = atomic_add_return_unchecked(1, &rttest_event);
88167 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
88168 - td->event = atomic_add_return(1, &rttest_event);
88169 + td->event = atomic_add_return_unchecked(1, &rttest_event);
88170 td->mutexes[id] = ret ? 0 : 4;
88171 return ret ? -EINTR : 0;
88172
88173 @@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
88174 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
88175 return ret;
88176
88177 - td->event = atomic_add_return(1, &rttest_event);
88178 + td->event = atomic_add_return_unchecked(1, &rttest_event);
88179 rt_mutex_unlock(&mutexes[id]);
88180 - td->event = atomic_add_return(1, &rttest_event);
88181 + td->event = atomic_add_return_unchecked(1, &rttest_event);
88182 td->mutexes[id] = 0;
88183 return 0;
88184
88185 @@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
88186 break;
88187
88188 td->mutexes[dat] = 2;
88189 - td->event = atomic_add_return(1, &rttest_event);
88190 + td->event = atomic_add_return_unchecked(1, &rttest_event);
88191 break;
88192
88193 default:
88194 @@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
88195 return;
88196
88197 td->mutexes[dat] = 3;
88198 - td->event = atomic_add_return(1, &rttest_event);
88199 + td->event = atomic_add_return_unchecked(1, &rttest_event);
88200 break;
88201
88202 case RTTEST_LOCKNOWAIT:
88203 @@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
88204 return;
88205
88206 td->mutexes[dat] = 1;
88207 - td->event = atomic_add_return(1, &rttest_event);
88208 + td->event = atomic_add_return_unchecked(1, &rttest_event);
88209 return;
88210
88211 default:
88212 diff --git a/kernel/module.c b/kernel/module.c
88213 index 079c461..741f79c 100644
88214 --- a/kernel/module.c
88215 +++ b/kernel/module.c
88216 @@ -61,6 +61,7 @@
88217 #include <linux/pfn.h>
88218 #include <linux/bsearch.h>
88219 #include <linux/fips.h>
88220 +#include <linux/grsecurity.h>
88221 #include <uapi/linux/module.h>
88222 #include "module-internal.h"
88223
88224 @@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
88225
88226 /* Bounds of module allocation, for speeding __module_address.
88227 * Protected by module_mutex. */
88228 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
88229 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
88230 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
88231
88232 int register_module_notifier(struct notifier_block * nb)
88233 {
88234 @@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
88235 return true;
88236
88237 list_for_each_entry_rcu(mod, &modules, list) {
88238 - struct symsearch arr[] = {
88239 + struct symsearch modarr[] = {
88240 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
88241 NOT_GPL_ONLY, false },
88242 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
88243 @@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
88244 if (mod->state == MODULE_STATE_UNFORMED)
88245 continue;
88246
88247 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
88248 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
88249 return true;
88250 }
88251 return false;
88252 @@ -489,7 +491,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
88253 if (!pcpusec->sh_size)
88254 return 0;
88255
88256 - if (align > PAGE_SIZE) {
88257 + if (align-1 >= PAGE_SIZE) {
88258 pr_warn("%s: per-cpu alignment %li > %li\n",
88259 mod->name, align, PAGE_SIZE);
88260 align = PAGE_SIZE;
88261 @@ -1061,7 +1063,7 @@ struct module_attribute module_uevent =
88262 static ssize_t show_coresize(struct module_attribute *mattr,
88263 struct module_kobject *mk, char *buffer)
88264 {
88265 - return sprintf(buffer, "%u\n", mk->mod->core_size);
88266 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
88267 }
88268
88269 static struct module_attribute modinfo_coresize =
88270 @@ -1070,7 +1072,7 @@ static struct module_attribute modinfo_coresize =
88271 static ssize_t show_initsize(struct module_attribute *mattr,
88272 struct module_kobject *mk, char *buffer)
88273 {
88274 - return sprintf(buffer, "%u\n", mk->mod->init_size);
88275 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
88276 }
88277
88278 static struct module_attribute modinfo_initsize =
88279 @@ -1162,12 +1164,29 @@ static int check_version(Elf_Shdr *sechdrs,
88280 goto bad_version;
88281 }
88282
88283 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
88284 + /*
88285 + * avoid potentially printing jibberish on attempted load
88286 + * of a module randomized with a different seed
88287 + */
88288 + pr_warn("no symbol version for %s\n", symname);
88289 +#else
88290 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
88291 +#endif
88292 return 0;
88293
88294 bad_version:
88295 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
88296 + /*
88297 + * avoid potentially printing jibberish on attempted load
88298 + * of a module randomized with a different seed
88299 + */
88300 + printk("attempted module disagrees about version of symbol %s\n",
88301 + symname);
88302 +#else
88303 printk("%s: disagrees about version of symbol %s\n",
88304 mod->name, symname);
88305 +#endif
88306 return 0;
88307 }
88308
88309 @@ -1283,7 +1302,7 @@ resolve_symbol_wait(struct module *mod,
88310 */
88311 #ifdef CONFIG_SYSFS
88312
88313 -#ifdef CONFIG_KALLSYMS
88314 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
88315 static inline bool sect_empty(const Elf_Shdr *sect)
88316 {
88317 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
88318 @@ -1423,7 +1442,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
88319 {
88320 unsigned int notes, loaded, i;
88321 struct module_notes_attrs *notes_attrs;
88322 - struct bin_attribute *nattr;
88323 + bin_attribute_no_const *nattr;
88324
88325 /* failed to create section attributes, so can't create notes */
88326 if (!mod->sect_attrs)
88327 @@ -1535,7 +1554,7 @@ static void del_usage_links(struct module *mod)
88328 static int module_add_modinfo_attrs(struct module *mod)
88329 {
88330 struct module_attribute *attr;
88331 - struct module_attribute *temp_attr;
88332 + module_attribute_no_const *temp_attr;
88333 int error = 0;
88334 int i;
88335
88336 @@ -1756,21 +1775,21 @@ static void set_section_ro_nx(void *base,
88337
88338 static void unset_module_core_ro_nx(struct module *mod)
88339 {
88340 - set_page_attributes(mod->module_core + mod->core_text_size,
88341 - mod->module_core + mod->core_size,
88342 + set_page_attributes(mod->module_core_rw,
88343 + mod->module_core_rw + mod->core_size_rw,
88344 set_memory_x);
88345 - set_page_attributes(mod->module_core,
88346 - mod->module_core + mod->core_ro_size,
88347 + set_page_attributes(mod->module_core_rx,
88348 + mod->module_core_rx + mod->core_size_rx,
88349 set_memory_rw);
88350 }
88351
88352 static void unset_module_init_ro_nx(struct module *mod)
88353 {
88354 - set_page_attributes(mod->module_init + mod->init_text_size,
88355 - mod->module_init + mod->init_size,
88356 + set_page_attributes(mod->module_init_rw,
88357 + mod->module_init_rw + mod->init_size_rw,
88358 set_memory_x);
88359 - set_page_attributes(mod->module_init,
88360 - mod->module_init + mod->init_ro_size,
88361 + set_page_attributes(mod->module_init_rx,
88362 + mod->module_init_rx + mod->init_size_rx,
88363 set_memory_rw);
88364 }
88365
88366 @@ -1783,14 +1802,14 @@ void set_all_modules_text_rw(void)
88367 list_for_each_entry_rcu(mod, &modules, list) {
88368 if (mod->state == MODULE_STATE_UNFORMED)
88369 continue;
88370 - if ((mod->module_core) && (mod->core_text_size)) {
88371 - set_page_attributes(mod->module_core,
88372 - mod->module_core + mod->core_text_size,
88373 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
88374 + set_page_attributes(mod->module_core_rx,
88375 + mod->module_core_rx + mod->core_size_rx,
88376 set_memory_rw);
88377 }
88378 - if ((mod->module_init) && (mod->init_text_size)) {
88379 - set_page_attributes(mod->module_init,
88380 - mod->module_init + mod->init_text_size,
88381 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
88382 + set_page_attributes(mod->module_init_rx,
88383 + mod->module_init_rx + mod->init_size_rx,
88384 set_memory_rw);
88385 }
88386 }
88387 @@ -1806,14 +1825,14 @@ void set_all_modules_text_ro(void)
88388 list_for_each_entry_rcu(mod, &modules, list) {
88389 if (mod->state == MODULE_STATE_UNFORMED)
88390 continue;
88391 - if ((mod->module_core) && (mod->core_text_size)) {
88392 - set_page_attributes(mod->module_core,
88393 - mod->module_core + mod->core_text_size,
88394 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
88395 + set_page_attributes(mod->module_core_rx,
88396 + mod->module_core_rx + mod->core_size_rx,
88397 set_memory_ro);
88398 }
88399 - if ((mod->module_init) && (mod->init_text_size)) {
88400 - set_page_attributes(mod->module_init,
88401 - mod->module_init + mod->init_text_size,
88402 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
88403 + set_page_attributes(mod->module_init_rx,
88404 + mod->module_init_rx + mod->init_size_rx,
88405 set_memory_ro);
88406 }
88407 }
88408 @@ -1864,16 +1883,19 @@ static void free_module(struct module *mod)
88409
88410 /* This may be NULL, but that's OK */
88411 unset_module_init_ro_nx(mod);
88412 - module_free(mod, mod->module_init);
88413 + module_free(mod, mod->module_init_rw);
88414 + module_free_exec(mod, mod->module_init_rx);
88415 kfree(mod->args);
88416 percpu_modfree(mod);
88417
88418 /* Free lock-classes: */
88419 - lockdep_free_key_range(mod->module_core, mod->core_size);
88420 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
88421 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
88422
88423 /* Finally, free the core (containing the module structure) */
88424 unset_module_core_ro_nx(mod);
88425 - module_free(mod, mod->module_core);
88426 + module_free_exec(mod, mod->module_core_rx);
88427 + module_free(mod, mod->module_core_rw);
88428
88429 #ifdef CONFIG_MPU
88430 update_protections(current->mm);
88431 @@ -1942,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
88432 int ret = 0;
88433 const struct kernel_symbol *ksym;
88434
88435 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
88436 + int is_fs_load = 0;
88437 + int register_filesystem_found = 0;
88438 + char *p;
88439 +
88440 + p = strstr(mod->args, "grsec_modharden_fs");
88441 + if (p) {
88442 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
88443 + /* copy \0 as well */
88444 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
88445 + is_fs_load = 1;
88446 + }
88447 +#endif
88448 +
88449 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
88450 const char *name = info->strtab + sym[i].st_name;
88451
88452 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
88453 + /* it's a real shame this will never get ripped and copied
88454 + upstream! ;(
88455 + */
88456 + if (is_fs_load && !strcmp(name, "register_filesystem"))
88457 + register_filesystem_found = 1;
88458 +#endif
88459 +
88460 switch (sym[i].st_shndx) {
88461 case SHN_COMMON:
88462 /* Ignore common symbols */
88463 @@ -1969,7 +2013,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
88464 ksym = resolve_symbol_wait(mod, info, name);
88465 /* Ok if resolved. */
88466 if (ksym && !IS_ERR(ksym)) {
88467 + pax_open_kernel();
88468 sym[i].st_value = ksym->value;
88469 + pax_close_kernel();
88470 break;
88471 }
88472
88473 @@ -1988,11 +2034,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
88474 secbase = (unsigned long)mod_percpu(mod);
88475 else
88476 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
88477 + pax_open_kernel();
88478 sym[i].st_value += secbase;
88479 + pax_close_kernel();
88480 break;
88481 }
88482 }
88483
88484 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
88485 + if (is_fs_load && !register_filesystem_found) {
88486 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
88487 + ret = -EPERM;
88488 + }
88489 +#endif
88490 +
88491 return ret;
88492 }
88493
88494 @@ -2076,22 +2131,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
88495 || s->sh_entsize != ~0UL
88496 || strstarts(sname, ".init"))
88497 continue;
88498 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
88499 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
88500 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
88501 + else
88502 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
88503 pr_debug("\t%s\n", sname);
88504 }
88505 - switch (m) {
88506 - case 0: /* executable */
88507 - mod->core_size = debug_align(mod->core_size);
88508 - mod->core_text_size = mod->core_size;
88509 - break;
88510 - case 1: /* RO: text and ro-data */
88511 - mod->core_size = debug_align(mod->core_size);
88512 - mod->core_ro_size = mod->core_size;
88513 - break;
88514 - case 3: /* whole core */
88515 - mod->core_size = debug_align(mod->core_size);
88516 - break;
88517 - }
88518 }
88519
88520 pr_debug("Init section allocation order:\n");
88521 @@ -2105,23 +2150,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
88522 || s->sh_entsize != ~0UL
88523 || !strstarts(sname, ".init"))
88524 continue;
88525 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
88526 - | INIT_OFFSET_MASK);
88527 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
88528 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
88529 + else
88530 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
88531 + s->sh_entsize |= INIT_OFFSET_MASK;
88532 pr_debug("\t%s\n", sname);
88533 }
88534 - switch (m) {
88535 - case 0: /* executable */
88536 - mod->init_size = debug_align(mod->init_size);
88537 - mod->init_text_size = mod->init_size;
88538 - break;
88539 - case 1: /* RO: text and ro-data */
88540 - mod->init_size = debug_align(mod->init_size);
88541 - mod->init_ro_size = mod->init_size;
88542 - break;
88543 - case 3: /* whole init */
88544 - mod->init_size = debug_align(mod->init_size);
88545 - break;
88546 - }
88547 }
88548 }
88549
88550 @@ -2294,7 +2329,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
88551
88552 /* Put symbol section at end of init part of module. */
88553 symsect->sh_flags |= SHF_ALLOC;
88554 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
88555 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
88556 info->index.sym) | INIT_OFFSET_MASK;
88557 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
88558
88559 @@ -2311,13 +2346,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
88560 }
88561
88562 /* Append room for core symbols at end of core part. */
88563 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
88564 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
88565 - mod->core_size += strtab_size;
88566 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
88567 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
88568 + mod->core_size_rx += strtab_size;
88569
88570 /* Put string table section at end of init part of module. */
88571 strsect->sh_flags |= SHF_ALLOC;
88572 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
88573 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
88574 info->index.str) | INIT_OFFSET_MASK;
88575 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
88576 }
88577 @@ -2335,12 +2370,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
88578 /* Make sure we get permanent strtab: don't use info->strtab. */
88579 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
88580
88581 + pax_open_kernel();
88582 +
88583 /* Set types up while we still have access to sections. */
88584 for (i = 0; i < mod->num_symtab; i++)
88585 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
88586
88587 - mod->core_symtab = dst = mod->module_core + info->symoffs;
88588 - mod->core_strtab = s = mod->module_core + info->stroffs;
88589 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
88590 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
88591 src = mod->symtab;
88592 for (ndst = i = 0; i < mod->num_symtab; i++) {
88593 if (i == 0 ||
88594 @@ -2352,6 +2389,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
88595 }
88596 }
88597 mod->core_num_syms = ndst;
88598 +
88599 + pax_close_kernel();
88600 }
88601 #else
88602 static inline void layout_symtab(struct module *mod, struct load_info *info)
88603 @@ -2385,17 +2424,33 @@ void * __weak module_alloc(unsigned long size)
88604 return vmalloc_exec(size);
88605 }
88606
88607 -static void *module_alloc_update_bounds(unsigned long size)
88608 +static void *module_alloc_update_bounds_rw(unsigned long size)
88609 {
88610 void *ret = module_alloc(size);
88611
88612 if (ret) {
88613 mutex_lock(&module_mutex);
88614 /* Update module bounds. */
88615 - if ((unsigned long)ret < module_addr_min)
88616 - module_addr_min = (unsigned long)ret;
88617 - if ((unsigned long)ret + size > module_addr_max)
88618 - module_addr_max = (unsigned long)ret + size;
88619 + if ((unsigned long)ret < module_addr_min_rw)
88620 + module_addr_min_rw = (unsigned long)ret;
88621 + if ((unsigned long)ret + size > module_addr_max_rw)
88622 + module_addr_max_rw = (unsigned long)ret + size;
88623 + mutex_unlock(&module_mutex);
88624 + }
88625 + return ret;
88626 +}
88627 +
88628 +static void *module_alloc_update_bounds_rx(unsigned long size)
88629 +{
88630 + void *ret = module_alloc_exec(size);
88631 +
88632 + if (ret) {
88633 + mutex_lock(&module_mutex);
88634 + /* Update module bounds. */
88635 + if ((unsigned long)ret < module_addr_min_rx)
88636 + module_addr_min_rx = (unsigned long)ret;
88637 + if ((unsigned long)ret + size > module_addr_max_rx)
88638 + module_addr_max_rx = (unsigned long)ret + size;
88639 mutex_unlock(&module_mutex);
88640 }
88641 return ret;
88642 @@ -2652,7 +2707,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
88643 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
88644
88645 if (info->index.sym == 0) {
88646 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
88647 + /*
88648 + * avoid potentially printing jibberish on attempted load
88649 + * of a module randomized with a different seed
88650 + */
88651 + pr_warn("module has no symbols (stripped?)\n");
88652 +#else
88653 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
88654 +#endif
88655 return ERR_PTR(-ENOEXEC);
88656 }
88657
88658 @@ -2668,8 +2731,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
88659 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
88660 {
88661 const char *modmagic = get_modinfo(info, "vermagic");
88662 + const char *license = get_modinfo(info, "license");
88663 int err;
88664
88665 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
88666 + if (!license || !license_is_gpl_compatible(license))
88667 + return -ENOEXEC;
88668 +#endif
88669 +
88670 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
88671 modmagic = NULL;
88672
88673 @@ -2694,7 +2763,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
88674 }
88675
88676 /* Set up license info based on the info section */
88677 - set_license(mod, get_modinfo(info, "license"));
88678 + set_license(mod, license);
88679
88680 return 0;
88681 }
88682 @@ -2788,7 +2857,7 @@ static int move_module(struct module *mod, struct load_info *info)
88683 void *ptr;
88684
88685 /* Do the allocs. */
88686 - ptr = module_alloc_update_bounds(mod->core_size);
88687 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
88688 /*
88689 * The pointer to this block is stored in the module structure
88690 * which is inside the block. Just mark it as not being a
88691 @@ -2798,11 +2867,11 @@ static int move_module(struct module *mod, struct load_info *info)
88692 if (!ptr)
88693 return -ENOMEM;
88694
88695 - memset(ptr, 0, mod->core_size);
88696 - mod->module_core = ptr;
88697 + memset(ptr, 0, mod->core_size_rw);
88698 + mod->module_core_rw = ptr;
88699
88700 - if (mod->init_size) {
88701 - ptr = module_alloc_update_bounds(mod->init_size);
88702 + if (mod->init_size_rw) {
88703 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
88704 /*
88705 * The pointer to this block is stored in the module structure
88706 * which is inside the block. This block doesn't need to be
88707 @@ -2811,13 +2880,45 @@ static int move_module(struct module *mod, struct load_info *info)
88708 */
88709 kmemleak_ignore(ptr);
88710 if (!ptr) {
88711 - module_free(mod, mod->module_core);
88712 + module_free(mod, mod->module_core_rw);
88713 return -ENOMEM;
88714 }
88715 - memset(ptr, 0, mod->init_size);
88716 - mod->module_init = ptr;
88717 + memset(ptr, 0, mod->init_size_rw);
88718 + mod->module_init_rw = ptr;
88719 } else
88720 - mod->module_init = NULL;
88721 + mod->module_init_rw = NULL;
88722 +
88723 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
88724 + kmemleak_not_leak(ptr);
88725 + if (!ptr) {
88726 + if (mod->module_init_rw)
88727 + module_free(mod, mod->module_init_rw);
88728 + module_free(mod, mod->module_core_rw);
88729 + return -ENOMEM;
88730 + }
88731 +
88732 + pax_open_kernel();
88733 + memset(ptr, 0, mod->core_size_rx);
88734 + pax_close_kernel();
88735 + mod->module_core_rx = ptr;
88736 +
88737 + if (mod->init_size_rx) {
88738 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
88739 + kmemleak_ignore(ptr);
88740 + if (!ptr && mod->init_size_rx) {
88741 + module_free_exec(mod, mod->module_core_rx);
88742 + if (mod->module_init_rw)
88743 + module_free(mod, mod->module_init_rw);
88744 + module_free(mod, mod->module_core_rw);
88745 + return -ENOMEM;
88746 + }
88747 +
88748 + pax_open_kernel();
88749 + memset(ptr, 0, mod->init_size_rx);
88750 + pax_close_kernel();
88751 + mod->module_init_rx = ptr;
88752 + } else
88753 + mod->module_init_rx = NULL;
88754
88755 /* Transfer each section which specifies SHF_ALLOC */
88756 pr_debug("final section addresses:\n");
88757 @@ -2828,16 +2929,45 @@ static int move_module(struct module *mod, struct load_info *info)
88758 if (!(shdr->sh_flags & SHF_ALLOC))
88759 continue;
88760
88761 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
88762 - dest = mod->module_init
88763 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88764 - else
88765 - dest = mod->module_core + shdr->sh_entsize;
88766 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
88767 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
88768 + dest = mod->module_init_rw
88769 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88770 + else
88771 + dest = mod->module_init_rx
88772 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88773 + } else {
88774 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
88775 + dest = mod->module_core_rw + shdr->sh_entsize;
88776 + else
88777 + dest = mod->module_core_rx + shdr->sh_entsize;
88778 + }
88779 +
88780 + if (shdr->sh_type != SHT_NOBITS) {
88781 +
88782 +#ifdef CONFIG_PAX_KERNEXEC
88783 +#ifdef CONFIG_X86_64
88784 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
88785 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
88786 +#endif
88787 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
88788 + pax_open_kernel();
88789 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
88790 + pax_close_kernel();
88791 + } else
88792 +#endif
88793
88794 - if (shdr->sh_type != SHT_NOBITS)
88795 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
88796 + }
88797 /* Update sh_addr to point to copy in image. */
88798 - shdr->sh_addr = (unsigned long)dest;
88799 +
88800 +#ifdef CONFIG_PAX_KERNEXEC
88801 + if (shdr->sh_flags & SHF_EXECINSTR)
88802 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
88803 + else
88804 +#endif
88805 +
88806 + shdr->sh_addr = (unsigned long)dest;
88807 pr_debug("\t0x%lx %s\n",
88808 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
88809 }
88810 @@ -2894,12 +3024,12 @@ static void flush_module_icache(const struct module *mod)
88811 * Do it before processing of module parameters, so the module
88812 * can provide parameter accessor functions of its own.
88813 */
88814 - if (mod->module_init)
88815 - flush_icache_range((unsigned long)mod->module_init,
88816 - (unsigned long)mod->module_init
88817 - + mod->init_size);
88818 - flush_icache_range((unsigned long)mod->module_core,
88819 - (unsigned long)mod->module_core + mod->core_size);
88820 + if (mod->module_init_rx)
88821 + flush_icache_range((unsigned long)mod->module_init_rx,
88822 + (unsigned long)mod->module_init_rx
88823 + + mod->init_size_rx);
88824 + flush_icache_range((unsigned long)mod->module_core_rx,
88825 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
88826
88827 set_fs(old_fs);
88828 }
88829 @@ -2956,8 +3086,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
88830 static void module_deallocate(struct module *mod, struct load_info *info)
88831 {
88832 percpu_modfree(mod);
88833 - module_free(mod, mod->module_init);
88834 - module_free(mod, mod->module_core);
88835 + module_free_exec(mod, mod->module_init_rx);
88836 + module_free_exec(mod, mod->module_core_rx);
88837 + module_free(mod, mod->module_init_rw);
88838 + module_free(mod, mod->module_core_rw);
88839 }
88840
88841 int __weak module_finalize(const Elf_Ehdr *hdr,
88842 @@ -2970,7 +3102,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
88843 static int post_relocation(struct module *mod, const struct load_info *info)
88844 {
88845 /* Sort exception table now relocations are done. */
88846 + pax_open_kernel();
88847 sort_extable(mod->extable, mod->extable + mod->num_exentries);
88848 + pax_close_kernel();
88849
88850 /* Copy relocated percpu area over. */
88851 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
88852 @@ -3024,16 +3158,16 @@ static int do_init_module(struct module *mod)
88853 MODULE_STATE_COMING, mod);
88854
88855 /* Set RO and NX regions for core */
88856 - set_section_ro_nx(mod->module_core,
88857 - mod->core_text_size,
88858 - mod->core_ro_size,
88859 - mod->core_size);
88860 + set_section_ro_nx(mod->module_core_rx,
88861 + mod->core_size_rx,
88862 + mod->core_size_rx,
88863 + mod->core_size_rx);
88864
88865 /* Set RO and NX regions for init */
88866 - set_section_ro_nx(mod->module_init,
88867 - mod->init_text_size,
88868 - mod->init_ro_size,
88869 - mod->init_size);
88870 + set_section_ro_nx(mod->module_init_rx,
88871 + mod->init_size_rx,
88872 + mod->init_size_rx,
88873 + mod->init_size_rx);
88874
88875 do_mod_ctors(mod);
88876 /* Start the module */
88877 @@ -3094,11 +3228,12 @@ static int do_init_module(struct module *mod)
88878 mod->strtab = mod->core_strtab;
88879 #endif
88880 unset_module_init_ro_nx(mod);
88881 - module_free(mod, mod->module_init);
88882 - mod->module_init = NULL;
88883 - mod->init_size = 0;
88884 - mod->init_ro_size = 0;
88885 - mod->init_text_size = 0;
88886 + module_free(mod, mod->module_init_rw);
88887 + module_free_exec(mod, mod->module_init_rx);
88888 + mod->module_init_rw = NULL;
88889 + mod->module_init_rx = NULL;
88890 + mod->init_size_rw = 0;
88891 + mod->init_size_rx = 0;
88892 mutex_unlock(&module_mutex);
88893 wake_up_all(&module_wq);
88894
88895 @@ -3241,9 +3376,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
88896 if (err)
88897 goto free_unload;
88898
88899 + /* Now copy in args */
88900 + mod->args = strndup_user(uargs, ~0UL >> 1);
88901 + if (IS_ERR(mod->args)) {
88902 + err = PTR_ERR(mod->args);
88903 + goto free_unload;
88904 + }
88905 +
88906 /* Set up MODINFO_ATTR fields */
88907 setup_modinfo(mod, info);
88908
88909 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
88910 + {
88911 + char *p, *p2;
88912 +
88913 + if (strstr(mod->args, "grsec_modharden_netdev")) {
88914 + 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);
88915 + err = -EPERM;
88916 + goto free_modinfo;
88917 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
88918 + p += sizeof("grsec_modharden_normal") - 1;
88919 + p2 = strstr(p, "_");
88920 + if (p2) {
88921 + *p2 = '\0';
88922 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
88923 + *p2 = '_';
88924 + }
88925 + err = -EPERM;
88926 + goto free_modinfo;
88927 + }
88928 + }
88929 +#endif
88930 +
88931 /* Fix up syms, so that st_value is a pointer to location. */
88932 err = simplify_symbols(mod, info);
88933 if (err < 0)
88934 @@ -3259,13 +3423,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
88935
88936 flush_module_icache(mod);
88937
88938 - /* Now copy in args */
88939 - mod->args = strndup_user(uargs, ~0UL >> 1);
88940 - if (IS_ERR(mod->args)) {
88941 - err = PTR_ERR(mod->args);
88942 - goto free_arch_cleanup;
88943 - }
88944 -
88945 dynamic_debug_setup(info->debug, info->num_debug);
88946
88947 /* Ftrace init must be called in the MODULE_STATE_UNFORMED state */
88948 @@ -3303,11 +3460,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
88949 ddebug_cleanup:
88950 dynamic_debug_remove(info->debug);
88951 synchronize_sched();
88952 - kfree(mod->args);
88953 - free_arch_cleanup:
88954 module_arch_cleanup(mod);
88955 free_modinfo:
88956 free_modinfo(mod);
88957 + kfree(mod->args);
88958 free_unload:
88959 module_unload_free(mod);
88960 unlink_mod:
88961 @@ -3390,10 +3546,16 @@ static const char *get_ksymbol(struct module *mod,
88962 unsigned long nextval;
88963
88964 /* At worse, next value is at end of module */
88965 - if (within_module_init(addr, mod))
88966 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
88967 + if (within_module_init_rx(addr, mod))
88968 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
88969 + else if (within_module_init_rw(addr, mod))
88970 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
88971 + else if (within_module_core_rx(addr, mod))
88972 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
88973 + else if (within_module_core_rw(addr, mod))
88974 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
88975 else
88976 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
88977 + return NULL;
88978
88979 /* Scan for closest preceding symbol, and next symbol. (ELF
88980 starts real symbols at 1). */
88981 @@ -3644,7 +3806,7 @@ static int m_show(struct seq_file *m, void *p)
88982 return 0;
88983
88984 seq_printf(m, "%s %u",
88985 - mod->name, mod->init_size + mod->core_size);
88986 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
88987 print_unload_info(m, mod);
88988
88989 /* Informative for users. */
88990 @@ -3653,7 +3815,7 @@ static int m_show(struct seq_file *m, void *p)
88991 mod->state == MODULE_STATE_COMING ? "Loading":
88992 "Live");
88993 /* Used by oprofile and other similar tools. */
88994 - seq_printf(m, " 0x%pK", mod->module_core);
88995 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
88996
88997 /* Taints info */
88998 if (mod->taints)
88999 @@ -3689,7 +3851,17 @@ static const struct file_operations proc_modules_operations = {
89000
89001 static int __init proc_modules_init(void)
89002 {
89003 +#ifndef CONFIG_GRKERNSEC_HIDESYM
89004 +#ifdef CONFIG_GRKERNSEC_PROC_USER
89005 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
89006 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
89007 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
89008 +#else
89009 proc_create("modules", 0, NULL, &proc_modules_operations);
89010 +#endif
89011 +#else
89012 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
89013 +#endif
89014 return 0;
89015 }
89016 module_init(proc_modules_init);
89017 @@ -3750,14 +3922,14 @@ struct module *__module_address(unsigned long addr)
89018 {
89019 struct module *mod;
89020
89021 - if (addr < module_addr_min || addr > module_addr_max)
89022 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
89023 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
89024 return NULL;
89025
89026 list_for_each_entry_rcu(mod, &modules, list) {
89027 if (mod->state == MODULE_STATE_UNFORMED)
89028 continue;
89029 - if (within_module_core(addr, mod)
89030 - || within_module_init(addr, mod))
89031 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
89032 return mod;
89033 }
89034 return NULL;
89035 @@ -3792,11 +3964,20 @@ bool is_module_text_address(unsigned long addr)
89036 */
89037 struct module *__module_text_address(unsigned long addr)
89038 {
89039 - struct module *mod = __module_address(addr);
89040 + struct module *mod;
89041 +
89042 +#ifdef CONFIG_X86_32
89043 + addr = ktla_ktva(addr);
89044 +#endif
89045 +
89046 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
89047 + return NULL;
89048 +
89049 + mod = __module_address(addr);
89050 +
89051 if (mod) {
89052 /* Make sure it's within the text section. */
89053 - if (!within(addr, mod->module_init, mod->init_text_size)
89054 - && !within(addr, mod->module_core, mod->core_text_size))
89055 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
89056 mod = NULL;
89057 }
89058 return mod;
89059 diff --git a/kernel/notifier.c b/kernel/notifier.c
89060 index db4c8b0..ad011c5 100644
89061 --- a/kernel/notifier.c
89062 +++ b/kernel/notifier.c
89063 @@ -5,6 +5,7 @@
89064 #include <linux/rcupdate.h>
89065 #include <linux/vmalloc.h>
89066 #include <linux/reboot.h>
89067 +#include <linux/mm.h>
89068
89069 /*
89070 * Notifier list for kernel code which wants to be called
89071 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
89072 while ((*nl) != NULL) {
89073 if (n->priority > (*nl)->priority)
89074 break;
89075 - nl = &((*nl)->next);
89076 + nl = (struct notifier_block **)&((*nl)->next);
89077 }
89078 - n->next = *nl;
89079 + pax_open_kernel();
89080 + *(const void **)&n->next = *nl;
89081 rcu_assign_pointer(*nl, n);
89082 + pax_close_kernel();
89083 return 0;
89084 }
89085
89086 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
89087 return 0;
89088 if (n->priority > (*nl)->priority)
89089 break;
89090 - nl = &((*nl)->next);
89091 + nl = (struct notifier_block **)&((*nl)->next);
89092 }
89093 - n->next = *nl;
89094 + pax_open_kernel();
89095 + *(const void **)&n->next = *nl;
89096 rcu_assign_pointer(*nl, n);
89097 + pax_close_kernel();
89098 return 0;
89099 }
89100
89101 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
89102 {
89103 while ((*nl) != NULL) {
89104 if ((*nl) == n) {
89105 + pax_open_kernel();
89106 rcu_assign_pointer(*nl, n->next);
89107 + pax_close_kernel();
89108 return 0;
89109 }
89110 - nl = &((*nl)->next);
89111 + nl = (struct notifier_block **)&((*nl)->next);
89112 }
89113 return -ENOENT;
89114 }
89115 diff --git a/kernel/padata.c b/kernel/padata.c
89116 index 161402f..598814c 100644
89117 --- a/kernel/padata.c
89118 +++ b/kernel/padata.c
89119 @@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
89120 * seq_nr mod. number of cpus in use.
89121 */
89122
89123 - seq_nr = atomic_inc_return(&pd->seq_nr);
89124 + seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
89125 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
89126
89127 return padata_index_to_cpu(pd, cpu_index);
89128 @@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
89129 padata_init_pqueues(pd);
89130 padata_init_squeues(pd);
89131 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
89132 - atomic_set(&pd->seq_nr, -1);
89133 + atomic_set_unchecked(&pd->seq_nr, -1);
89134 atomic_set(&pd->reorder_objects, 0);
89135 atomic_set(&pd->refcnt, 0);
89136 pd->pinst = pinst;
89137 diff --git a/kernel/panic.c b/kernel/panic.c
89138 index d02fa9f..9faec0a 100644
89139 --- a/kernel/panic.c
89140 +++ b/kernel/panic.c
89141 @@ -52,7 +52,7 @@ EXPORT_SYMBOL(panic_blink);
89142 /*
89143 * Stop ourself in panic -- architecture code may override this
89144 */
89145 -void __weak panic_smp_self_stop(void)
89146 +void __weak __noreturn panic_smp_self_stop(void)
89147 {
89148 while (1)
89149 cpu_relax();
89150 @@ -408,7 +408,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
89151 disable_trace_on_warning();
89152
89153 pr_warn("------------[ cut here ]------------\n");
89154 - pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
89155 + pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
89156 raw_smp_processor_id(), current->pid, file, line, caller);
89157
89158 if (args)
89159 @@ -462,7 +462,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
89160 */
89161 __visible void __stack_chk_fail(void)
89162 {
89163 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
89164 + dump_stack();
89165 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
89166 __builtin_return_address(0));
89167 }
89168 EXPORT_SYMBOL(__stack_chk_fail);
89169 diff --git a/kernel/pid.c b/kernel/pid.c
89170 index 9b9a266..c20ef80 100644
89171 --- a/kernel/pid.c
89172 +++ b/kernel/pid.c
89173 @@ -33,6 +33,7 @@
89174 #include <linux/rculist.h>
89175 #include <linux/bootmem.h>
89176 #include <linux/hash.h>
89177 +#include <linux/security.h>
89178 #include <linux/pid_namespace.h>
89179 #include <linux/init_task.h>
89180 #include <linux/syscalls.h>
89181 @@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
89182
89183 int pid_max = PID_MAX_DEFAULT;
89184
89185 -#define RESERVED_PIDS 300
89186 +#define RESERVED_PIDS 500
89187
89188 int pid_max_min = RESERVED_PIDS + 1;
89189 int pid_max_max = PID_MAX_LIMIT;
89190 @@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
89191 */
89192 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
89193 {
89194 + struct task_struct *task;
89195 +
89196 rcu_lockdep_assert(rcu_read_lock_held(),
89197 "find_task_by_pid_ns() needs rcu_read_lock()"
89198 " protection");
89199 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
89200 +
89201 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
89202 +
89203 + if (gr_pid_is_chrooted(task))
89204 + return NULL;
89205 +
89206 + return task;
89207 }
89208
89209 struct task_struct *find_task_by_vpid(pid_t vnr)
89210 @@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
89211 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
89212 }
89213
89214 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
89215 +{
89216 + rcu_lockdep_assert(rcu_read_lock_held(),
89217 + "find_task_by_pid_ns() needs rcu_read_lock()"
89218 + " protection");
89219 + return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
89220 +}
89221 +
89222 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
89223 {
89224 struct pid *pid;
89225 diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
89226 index db95d8e..a0ca23f 100644
89227 --- a/kernel/pid_namespace.c
89228 +++ b/kernel/pid_namespace.c
89229 @@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
89230 void __user *buffer, size_t *lenp, loff_t *ppos)
89231 {
89232 struct pid_namespace *pid_ns = task_active_pid_ns(current);
89233 - struct ctl_table tmp = *table;
89234 + ctl_table_no_const tmp = *table;
89235
89236 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
89237 return -EPERM;
89238 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
89239 index 3b89464..5e38379 100644
89240 --- a/kernel/posix-cpu-timers.c
89241 +++ b/kernel/posix-cpu-timers.c
89242 @@ -1464,14 +1464,14 @@ struct k_clock clock_posix_cpu = {
89243
89244 static __init int init_posix_cpu_timers(void)
89245 {
89246 - struct k_clock process = {
89247 + static struct k_clock process = {
89248 .clock_getres = process_cpu_clock_getres,
89249 .clock_get = process_cpu_clock_get,
89250 .timer_create = process_cpu_timer_create,
89251 .nsleep = process_cpu_nsleep,
89252 .nsleep_restart = process_cpu_nsleep_restart,
89253 };
89254 - struct k_clock thread = {
89255 + static struct k_clock thread = {
89256 .clock_getres = thread_cpu_clock_getres,
89257 .clock_get = thread_cpu_clock_get,
89258 .timer_create = thread_cpu_timer_create,
89259 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
89260 index 424c2d4..679242f 100644
89261 --- a/kernel/posix-timers.c
89262 +++ b/kernel/posix-timers.c
89263 @@ -43,6 +43,7 @@
89264 #include <linux/hash.h>
89265 #include <linux/posix-clock.h>
89266 #include <linux/posix-timers.h>
89267 +#include <linux/grsecurity.h>
89268 #include <linux/syscalls.h>
89269 #include <linux/wait.h>
89270 #include <linux/workqueue.h>
89271 @@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
89272 * which we beg off on and pass to do_sys_settimeofday().
89273 */
89274
89275 -static struct k_clock posix_clocks[MAX_CLOCKS];
89276 +static struct k_clock *posix_clocks[MAX_CLOCKS];
89277
89278 /*
89279 * These ones are defined below.
89280 @@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
89281 */
89282 static __init int init_posix_timers(void)
89283 {
89284 - struct k_clock clock_realtime = {
89285 + static struct k_clock clock_realtime = {
89286 .clock_getres = hrtimer_get_res,
89287 .clock_get = posix_clock_realtime_get,
89288 .clock_set = posix_clock_realtime_set,
89289 @@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
89290 .timer_get = common_timer_get,
89291 .timer_del = common_timer_del,
89292 };
89293 - struct k_clock clock_monotonic = {
89294 + static struct k_clock clock_monotonic = {
89295 .clock_getres = hrtimer_get_res,
89296 .clock_get = posix_ktime_get_ts,
89297 .nsleep = common_nsleep,
89298 @@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
89299 .timer_get = common_timer_get,
89300 .timer_del = common_timer_del,
89301 };
89302 - struct k_clock clock_monotonic_raw = {
89303 + static struct k_clock clock_monotonic_raw = {
89304 .clock_getres = hrtimer_get_res,
89305 .clock_get = posix_get_monotonic_raw,
89306 };
89307 - struct k_clock clock_realtime_coarse = {
89308 + static struct k_clock clock_realtime_coarse = {
89309 .clock_getres = posix_get_coarse_res,
89310 .clock_get = posix_get_realtime_coarse,
89311 };
89312 - struct k_clock clock_monotonic_coarse = {
89313 + static struct k_clock clock_monotonic_coarse = {
89314 .clock_getres = posix_get_coarse_res,
89315 .clock_get = posix_get_monotonic_coarse,
89316 };
89317 - struct k_clock clock_tai = {
89318 + static struct k_clock clock_tai = {
89319 .clock_getres = hrtimer_get_res,
89320 .clock_get = posix_get_tai,
89321 .nsleep = common_nsleep,
89322 @@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
89323 .timer_get = common_timer_get,
89324 .timer_del = common_timer_del,
89325 };
89326 - struct k_clock clock_boottime = {
89327 + static struct k_clock clock_boottime = {
89328 .clock_getres = hrtimer_get_res,
89329 .clock_get = posix_get_boottime,
89330 .nsleep = common_nsleep,
89331 @@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
89332 return;
89333 }
89334
89335 - posix_clocks[clock_id] = *new_clock;
89336 + posix_clocks[clock_id] = new_clock;
89337 }
89338 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
89339
89340 @@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
89341 return (id & CLOCKFD_MASK) == CLOCKFD ?
89342 &clock_posix_dynamic : &clock_posix_cpu;
89343
89344 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
89345 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
89346 return NULL;
89347 - return &posix_clocks[id];
89348 + return posix_clocks[id];
89349 }
89350
89351 static int common_timer_create(struct k_itimer *new_timer)
89352 @@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
89353 struct k_clock *kc = clockid_to_kclock(which_clock);
89354 struct k_itimer *new_timer;
89355 int error, new_timer_id;
89356 - sigevent_t event;
89357 + sigevent_t event = { };
89358 int it_id_set = IT_ID_NOT_SET;
89359
89360 if (!kc)
89361 @@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
89362 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
89363 return -EFAULT;
89364
89365 + /* only the CLOCK_REALTIME clock can be set, all other clocks
89366 + have their clock_set fptr set to a nosettime dummy function
89367 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
89368 + call common_clock_set, which calls do_sys_settimeofday, which
89369 + we hook
89370 + */
89371 +
89372 return kc->clock_set(which_clock, &new_tp);
89373 }
89374
89375 diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
89376 index 2fac9cc..56fef29 100644
89377 --- a/kernel/power/Kconfig
89378 +++ b/kernel/power/Kconfig
89379 @@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
89380 config HIBERNATION
89381 bool "Hibernation (aka 'suspend to disk')"
89382 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
89383 + depends on !GRKERNSEC_KMEM
89384 + depends on !PAX_MEMORY_SANITIZE
89385 select HIBERNATE_CALLBACKS
89386 select LZO_COMPRESS
89387 select LZO_DECOMPRESS
89388 diff --git a/kernel/power/process.c b/kernel/power/process.c
89389 index 14f9a8d..98ee610 100644
89390 --- a/kernel/power/process.c
89391 +++ b/kernel/power/process.c
89392 @@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
89393 unsigned int elapsed_msecs;
89394 bool wakeup = false;
89395 int sleep_usecs = USEC_PER_MSEC;
89396 + bool timedout = false;
89397
89398 do_gettimeofday(&start);
89399
89400 @@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
89401
89402 while (true) {
89403 todo = 0;
89404 + if (time_after(jiffies, end_time))
89405 + timedout = true;
89406 read_lock(&tasklist_lock);
89407 do_each_thread(g, p) {
89408 if (p == current || !freeze_task(p))
89409 continue;
89410
89411 - if (!freezer_should_skip(p))
89412 + if (!freezer_should_skip(p)) {
89413 todo++;
89414 + if (timedout) {
89415 + printk(KERN_ERR "Task refusing to freeze:\n");
89416 + sched_show_task(p);
89417 + }
89418 + }
89419 } while_each_thread(g, p);
89420 read_unlock(&tasklist_lock);
89421
89422 @@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
89423 todo += wq_busy;
89424 }
89425
89426 - if (!todo || time_after(jiffies, end_time))
89427 + if (!todo || timedout)
89428 break;
89429
89430 if (pm_wakeup_pending()) {
89431 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
89432 index 63594be..8444e0f 100644
89433 --- a/kernel/printk/printk.c
89434 +++ b/kernel/printk/printk.c
89435 @@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
89436 if (from_file && type != SYSLOG_ACTION_OPEN)
89437 return 0;
89438
89439 +#ifdef CONFIG_GRKERNSEC_DMESG
89440 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
89441 + return -EPERM;
89442 +#endif
89443 +
89444 if (syslog_action_restricted(type)) {
89445 if (capable(CAP_SYSLOG))
89446 return 0;
89447 diff --git a/kernel/profile.c b/kernel/profile.c
89448 index cb980f0..ccd8782 100644
89449 --- a/kernel/profile.c
89450 +++ b/kernel/profile.c
89451 @@ -37,7 +37,7 @@ struct profile_hit {
89452 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
89453 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
89454
89455 -static atomic_t *prof_buffer;
89456 +static atomic_unchecked_t *prof_buffer;
89457 static unsigned long prof_len, prof_shift;
89458
89459 int prof_on __read_mostly;
89460 @@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
89461 hits[i].pc = 0;
89462 continue;
89463 }
89464 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
89465 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
89466 hits[i].hits = hits[i].pc = 0;
89467 }
89468 }
89469 @@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
89470 * Add the current hit(s) and flush the write-queue out
89471 * to the global buffer:
89472 */
89473 - atomic_add(nr_hits, &prof_buffer[pc]);
89474 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
89475 for (i = 0; i < NR_PROFILE_HIT; ++i) {
89476 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
89477 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
89478 hits[i].pc = hits[i].hits = 0;
89479 }
89480 out:
89481 @@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
89482 {
89483 unsigned long pc;
89484 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
89485 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
89486 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
89487 }
89488 #endif /* !CONFIG_SMP */
89489
89490 @@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
89491 return -EFAULT;
89492 buf++; p++; count--; read++;
89493 }
89494 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
89495 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
89496 if (copy_to_user(buf, (void *)pnt, count))
89497 return -EFAULT;
89498 read += count;
89499 @@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
89500 }
89501 #endif
89502 profile_discard_flip_buffers();
89503 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
89504 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
89505 return count;
89506 }
89507
89508 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
89509 index adf9862..9d86345 100644
89510 --- a/kernel/ptrace.c
89511 +++ b/kernel/ptrace.c
89512 @@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
89513 if (seize)
89514 flags |= PT_SEIZED;
89515 rcu_read_lock();
89516 - if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
89517 + if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
89518 flags |= PT_PTRACE_CAP;
89519 rcu_read_unlock();
89520 task->ptrace = flags;
89521 @@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
89522 break;
89523 return -EIO;
89524 }
89525 - if (copy_to_user(dst, buf, retval))
89526 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
89527 return -EFAULT;
89528 copied += retval;
89529 src += retval;
89530 @@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
89531 bool seized = child->ptrace & PT_SEIZED;
89532 int ret = -EIO;
89533 siginfo_t siginfo, *si;
89534 - void __user *datavp = (void __user *) data;
89535 + void __user *datavp = (__force void __user *) data;
89536 unsigned long __user *datalp = datavp;
89537 unsigned long flags;
89538
89539 @@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
89540 goto out;
89541 }
89542
89543 + if (gr_handle_ptrace(child, request)) {
89544 + ret = -EPERM;
89545 + goto out_put_task_struct;
89546 + }
89547 +
89548 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
89549 ret = ptrace_attach(child, request, addr, data);
89550 /*
89551 * Some architectures need to do book-keeping after
89552 * a ptrace attach.
89553 */
89554 - if (!ret)
89555 + if (!ret) {
89556 arch_ptrace_attach(child);
89557 + gr_audit_ptrace(child);
89558 + }
89559 goto out_put_task_struct;
89560 }
89561
89562 @@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
89563 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
89564 if (copied != sizeof(tmp))
89565 return -EIO;
89566 - return put_user(tmp, (unsigned long __user *)data);
89567 + return put_user(tmp, (__force unsigned long __user *)data);
89568 }
89569
89570 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
89571 @@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
89572 }
89573
89574 COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
89575 - compat_long_t, addr, compat_long_t, data)
89576 + compat_ulong_t, addr, compat_ulong_t, data)
89577 {
89578 struct task_struct *child;
89579 long ret;
89580 @@ -1197,14 +1204,21 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
89581 goto out;
89582 }
89583
89584 + if (gr_handle_ptrace(child, request)) {
89585 + ret = -EPERM;
89586 + goto out_put_task_struct;
89587 + }
89588 +
89589 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
89590 ret = ptrace_attach(child, request, addr, data);
89591 /*
89592 * Some architectures need to do book-keeping after
89593 * a ptrace attach.
89594 */
89595 - if (!ret)
89596 + if (!ret) {
89597 arch_ptrace_attach(child);
89598 + gr_audit_ptrace(child);
89599 + }
89600 goto out_put_task_struct;
89601 }
89602
89603 diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
89604 index bd30bc6..dce23da 100644
89605 --- a/kernel/rcu/rcutorture.c
89606 +++ b/kernel/rcu/rcutorture.c
89607 @@ -122,12 +122,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
89608 rcu_torture_count) = { 0 };
89609 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
89610 rcu_torture_batch) = { 0 };
89611 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
89612 -static atomic_t n_rcu_torture_alloc;
89613 -static atomic_t n_rcu_torture_alloc_fail;
89614 -static atomic_t n_rcu_torture_free;
89615 -static atomic_t n_rcu_torture_mberror;
89616 -static atomic_t n_rcu_torture_error;
89617 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
89618 +static atomic_unchecked_t n_rcu_torture_alloc;
89619 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
89620 +static atomic_unchecked_t n_rcu_torture_free;
89621 +static atomic_unchecked_t n_rcu_torture_mberror;
89622 +static atomic_unchecked_t n_rcu_torture_error;
89623 static long n_rcu_torture_barrier_error;
89624 static long n_rcu_torture_boost_ktrerror;
89625 static long n_rcu_torture_boost_rterror;
89626 @@ -186,11 +186,11 @@ rcu_torture_alloc(void)
89627
89628 spin_lock_bh(&rcu_torture_lock);
89629 if (list_empty(&rcu_torture_freelist)) {
89630 - atomic_inc(&n_rcu_torture_alloc_fail);
89631 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
89632 spin_unlock_bh(&rcu_torture_lock);
89633 return NULL;
89634 }
89635 - atomic_inc(&n_rcu_torture_alloc);
89636 + atomic_inc_unchecked(&n_rcu_torture_alloc);
89637 p = rcu_torture_freelist.next;
89638 list_del_init(p);
89639 spin_unlock_bh(&rcu_torture_lock);
89640 @@ -203,7 +203,7 @@ rcu_torture_alloc(void)
89641 static void
89642 rcu_torture_free(struct rcu_torture *p)
89643 {
89644 - atomic_inc(&n_rcu_torture_free);
89645 + atomic_inc_unchecked(&n_rcu_torture_free);
89646 spin_lock_bh(&rcu_torture_lock);
89647 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
89648 spin_unlock_bh(&rcu_torture_lock);
89649 @@ -287,7 +287,7 @@ rcu_torture_cb(struct rcu_head *p)
89650 i = rp->rtort_pipe_count;
89651 if (i > RCU_TORTURE_PIPE_LEN)
89652 i = RCU_TORTURE_PIPE_LEN;
89653 - atomic_inc(&rcu_torture_wcount[i]);
89654 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
89655 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
89656 rp->rtort_mbtest = 0;
89657 rcu_torture_free(rp);
89658 @@ -714,7 +714,7 @@ rcu_torture_writer(void *arg)
89659 i = old_rp->rtort_pipe_count;
89660 if (i > RCU_TORTURE_PIPE_LEN)
89661 i = RCU_TORTURE_PIPE_LEN;
89662 - atomic_inc(&rcu_torture_wcount[i]);
89663 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
89664 old_rp->rtort_pipe_count++;
89665 if (gp_normal == gp_exp)
89666 exp = !!(torture_random(&rand) & 0x80);
89667 @@ -732,7 +732,7 @@ rcu_torture_writer(void *arg)
89668 i = rp->rtort_pipe_count;
89669 if (i > RCU_TORTURE_PIPE_LEN)
89670 i = RCU_TORTURE_PIPE_LEN;
89671 - atomic_inc(&rcu_torture_wcount[i]);
89672 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
89673 if (++rp->rtort_pipe_count >=
89674 RCU_TORTURE_PIPE_LEN) {
89675 rp->rtort_mbtest = 0;
89676 @@ -825,7 +825,7 @@ static void rcu_torture_timer(unsigned long unused)
89677 return;
89678 }
89679 if (p->rtort_mbtest == 0)
89680 - atomic_inc(&n_rcu_torture_mberror);
89681 + atomic_inc_unchecked(&n_rcu_torture_mberror);
89682 spin_lock(&rand_lock);
89683 cur_ops->read_delay(&rand);
89684 n_rcu_torture_timers++;
89685 @@ -895,7 +895,7 @@ rcu_torture_reader(void *arg)
89686 continue;
89687 }
89688 if (p->rtort_mbtest == 0)
89689 - atomic_inc(&n_rcu_torture_mberror);
89690 + atomic_inc_unchecked(&n_rcu_torture_mberror);
89691 cur_ops->read_delay(&rand);
89692 preempt_disable();
89693 pipe_count = p->rtort_pipe_count;
89694 @@ -950,15 +950,15 @@ rcu_torture_printk(char *page)
89695 }
89696 page += sprintf(page, "%s%s ", torture_type, TORTURE_FLAG);
89697 page += sprintf(page,
89698 - "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
89699 + "rtc: %pP ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
89700 rcu_torture_current,
89701 rcu_torture_current_version,
89702 list_empty(&rcu_torture_freelist),
89703 - atomic_read(&n_rcu_torture_alloc),
89704 - atomic_read(&n_rcu_torture_alloc_fail),
89705 - atomic_read(&n_rcu_torture_free));
89706 + atomic_read_unchecked(&n_rcu_torture_alloc),
89707 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
89708 + atomic_read_unchecked(&n_rcu_torture_free));
89709 page += sprintf(page, "rtmbe: %d rtbke: %ld rtbre: %ld ",
89710 - atomic_read(&n_rcu_torture_mberror),
89711 + atomic_read_unchecked(&n_rcu_torture_mberror),
89712 n_rcu_torture_boost_ktrerror,
89713 n_rcu_torture_boost_rterror);
89714 page += sprintf(page, "rtbf: %ld rtb: %ld nt: %ld ",
89715 @@ -971,14 +971,14 @@ rcu_torture_printk(char *page)
89716 n_barrier_attempts,
89717 n_rcu_torture_barrier_error);
89718 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
89719 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
89720 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
89721 n_rcu_torture_barrier_error != 0 ||
89722 n_rcu_torture_boost_ktrerror != 0 ||
89723 n_rcu_torture_boost_rterror != 0 ||
89724 n_rcu_torture_boost_failure != 0 ||
89725 i > 1) {
89726 page += sprintf(page, "!!! ");
89727 - atomic_inc(&n_rcu_torture_error);
89728 + atomic_inc_unchecked(&n_rcu_torture_error);
89729 WARN_ON_ONCE(1);
89730 }
89731 page += sprintf(page, "Reader Pipe: ");
89732 @@ -992,7 +992,7 @@ rcu_torture_printk(char *page)
89733 page += sprintf(page, "Free-Block Circulation: ");
89734 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
89735 page += sprintf(page, " %d",
89736 - atomic_read(&rcu_torture_wcount[i]));
89737 + atomic_read_unchecked(&rcu_torture_wcount[i]));
89738 }
89739 page += sprintf(page, "\n");
89740 if (cur_ops->stats)
89741 @@ -1341,7 +1341,7 @@ rcu_torture_cleanup(void)
89742
89743 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
89744
89745 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
89746 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
89747 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
89748 else if (torture_onoff_failures())
89749 rcu_torture_print_module_parms(cur_ops,
89750 @@ -1460,18 +1460,18 @@ rcu_torture_init(void)
89751
89752 rcu_torture_current = NULL;
89753 rcu_torture_current_version = 0;
89754 - atomic_set(&n_rcu_torture_alloc, 0);
89755 - atomic_set(&n_rcu_torture_alloc_fail, 0);
89756 - atomic_set(&n_rcu_torture_free, 0);
89757 - atomic_set(&n_rcu_torture_mberror, 0);
89758 - atomic_set(&n_rcu_torture_error, 0);
89759 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
89760 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
89761 + atomic_set_unchecked(&n_rcu_torture_free, 0);
89762 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
89763 + atomic_set_unchecked(&n_rcu_torture_error, 0);
89764 n_rcu_torture_barrier_error = 0;
89765 n_rcu_torture_boost_ktrerror = 0;
89766 n_rcu_torture_boost_rterror = 0;
89767 n_rcu_torture_boost_failure = 0;
89768 n_rcu_torture_boosts = 0;
89769 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
89770 - atomic_set(&rcu_torture_wcount[i], 0);
89771 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
89772 for_each_possible_cpu(cpu) {
89773 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
89774 per_cpu(rcu_torture_count, cpu)[i] = 0;
89775 diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
89776 index c639556..cf0a0d5 100644
89777 --- a/kernel/rcu/srcu.c
89778 +++ b/kernel/rcu/srcu.c
89779 @@ -298,9 +298,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
89780
89781 idx = ACCESS_ONCE(sp->completed) & 0x1;
89782 preempt_disable();
89783 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
89784 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
89785 smp_mb(); /* B */ /* Avoid leaking the critical section. */
89786 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
89787 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
89788 preempt_enable();
89789 return idx;
89790 }
89791 diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
89792 index d9efcc1..ea543e9 100644
89793 --- a/kernel/rcu/tiny.c
89794 +++ b/kernel/rcu/tiny.c
89795 @@ -42,7 +42,7 @@
89796 /* Forward declarations for tiny_plugin.h. */
89797 struct rcu_ctrlblk;
89798 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
89799 -static void rcu_process_callbacks(struct softirq_action *unused);
89800 +static void rcu_process_callbacks(void);
89801 static void __call_rcu(struct rcu_head *head,
89802 void (*func)(struct rcu_head *rcu),
89803 struct rcu_ctrlblk *rcp);
89804 @@ -308,7 +308,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
89805 false));
89806 }
89807
89808 -static void rcu_process_callbacks(struct softirq_action *unused)
89809 +static __latent_entropy void rcu_process_callbacks(void)
89810 {
89811 __rcu_process_callbacks(&rcu_sched_ctrlblk);
89812 __rcu_process_callbacks(&rcu_bh_ctrlblk);
89813 diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
89814 index 0c47e30..a084591 100644
89815 --- a/kernel/rcu/tree.c
89816 +++ b/kernel/rcu/tree.c
89817 @@ -388,9 +388,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
89818 rcu_prepare_for_idle(smp_processor_id());
89819 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
89820 smp_mb__before_atomic_inc(); /* See above. */
89821 - atomic_inc(&rdtp->dynticks);
89822 + atomic_inc_unchecked(&rdtp->dynticks);
89823 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
89824 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
89825 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
89826
89827 /*
89828 * It is illegal to enter an extended quiescent state while
89829 @@ -508,10 +508,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
89830 int user)
89831 {
89832 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
89833 - atomic_inc(&rdtp->dynticks);
89834 + atomic_inc_unchecked(&rdtp->dynticks);
89835 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
89836 smp_mb__after_atomic_inc(); /* See above. */
89837 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
89838 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
89839 rcu_cleanup_after_idle(smp_processor_id());
89840 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
89841 if (!user && !is_idle_task(current)) {
89842 @@ -632,14 +632,14 @@ void rcu_nmi_enter(void)
89843 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
89844
89845 if (rdtp->dynticks_nmi_nesting == 0 &&
89846 - (atomic_read(&rdtp->dynticks) & 0x1))
89847 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
89848 return;
89849 rdtp->dynticks_nmi_nesting++;
89850 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
89851 - atomic_inc(&rdtp->dynticks);
89852 + atomic_inc_unchecked(&rdtp->dynticks);
89853 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
89854 smp_mb__after_atomic_inc(); /* See above. */
89855 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
89856 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
89857 }
89858
89859 /**
89860 @@ -658,9 +658,9 @@ void rcu_nmi_exit(void)
89861 return;
89862 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
89863 smp_mb__before_atomic_inc(); /* See above. */
89864 - atomic_inc(&rdtp->dynticks);
89865 + atomic_inc_unchecked(&rdtp->dynticks);
89866 smp_mb__after_atomic_inc(); /* Force delay to next write. */
89867 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
89868 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
89869 }
89870
89871 /**
89872 @@ -673,7 +673,7 @@ void rcu_nmi_exit(void)
89873 */
89874 bool notrace __rcu_is_watching(void)
89875 {
89876 - return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
89877 + return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
89878 }
89879
89880 /**
89881 @@ -756,7 +756,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
89882 static int dyntick_save_progress_counter(struct rcu_data *rdp,
89883 bool *isidle, unsigned long *maxj)
89884 {
89885 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
89886 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
89887 rcu_sysidle_check_cpu(rdp, isidle, maxj);
89888 return (rdp->dynticks_snap & 0x1) == 0;
89889 }
89890 @@ -779,7 +779,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
89891 unsigned int curr;
89892 unsigned int snap;
89893
89894 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
89895 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
89896 snap = (unsigned int)rdp->dynticks_snap;
89897
89898 /*
89899 @@ -1449,9 +1449,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
89900 rdp = this_cpu_ptr(rsp->rda);
89901 rcu_preempt_check_blocked_tasks(rnp);
89902 rnp->qsmask = rnp->qsmaskinit;
89903 - ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
89904 + ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
89905 WARN_ON_ONCE(rnp->completed != rsp->completed);
89906 - ACCESS_ONCE(rnp->completed) = rsp->completed;
89907 + ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
89908 if (rnp == rdp->mynode)
89909 __note_gp_changes(rsp, rnp, rdp);
89910 rcu_preempt_boost_start_gp(rnp);
89911 @@ -1545,7 +1545,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
89912 rcu_for_each_node_breadth_first(rsp, rnp) {
89913 raw_spin_lock_irq(&rnp->lock);
89914 smp_mb__after_unlock_lock();
89915 - ACCESS_ONCE(rnp->completed) = rsp->gpnum;
89916 + ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
89917 rdp = this_cpu_ptr(rsp->rda);
89918 if (rnp == rdp->mynode)
89919 __note_gp_changes(rsp, rnp, rdp);
89920 @@ -1560,7 +1560,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
89921 rcu_nocb_gp_set(rnp, nocb);
89922
89923 /* Declare grace period done. */
89924 - ACCESS_ONCE(rsp->completed) = rsp->gpnum;
89925 + ACCESS_ONCE_RW(rsp->completed) = rsp->gpnum;
89926 trace_rcu_grace_period(rsp->name, rsp->completed, TPS("end"));
89927 rsp->fqs_state = RCU_GP_IDLE;
89928 rdp = this_cpu_ptr(rsp->rda);
89929 @@ -1912,7 +1912,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
89930 rsp->qlen += rdp->qlen;
89931 rdp->n_cbs_orphaned += rdp->qlen;
89932 rdp->qlen_lazy = 0;
89933 - ACCESS_ONCE(rdp->qlen) = 0;
89934 + ACCESS_ONCE_RW(rdp->qlen) = 0;
89935 }
89936
89937 /*
89938 @@ -2159,7 +2159,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
89939 }
89940 smp_mb(); /* List handling before counting for rcu_barrier(). */
89941 rdp->qlen_lazy -= count_lazy;
89942 - ACCESS_ONCE(rdp->qlen) -= count;
89943 + ACCESS_ONCE_RW(rdp->qlen) -= count;
89944 rdp->n_cbs_invoked += count;
89945
89946 /* Reinstate batch limit if we have worked down the excess. */
89947 @@ -2304,7 +2304,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
89948 if (rnp_old != NULL)
89949 raw_spin_unlock(&rnp_old->fqslock);
89950 if (ret) {
89951 - ACCESS_ONCE(rsp->n_force_qs_lh)++;
89952 + ACCESS_ONCE_RW(rsp->n_force_qs_lh)++;
89953 return;
89954 }
89955 rnp_old = rnp;
89956 @@ -2316,7 +2316,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
89957 smp_mb__after_unlock_lock();
89958 raw_spin_unlock(&rnp_old->fqslock);
89959 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
89960 - ACCESS_ONCE(rsp->n_force_qs_lh)++;
89961 + ACCESS_ONCE_RW(rsp->n_force_qs_lh)++;
89962 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
89963 return; /* Someone beat us to it. */
89964 }
89965 @@ -2362,7 +2362,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
89966 /*
89967 * Do RCU core processing for the current CPU.
89968 */
89969 -static void rcu_process_callbacks(struct softirq_action *unused)
89970 +static void rcu_process_callbacks(void)
89971 {
89972 struct rcu_state *rsp;
89973
89974 @@ -2470,7 +2470,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
89975 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
89976 if (debug_rcu_head_queue(head)) {
89977 /* Probable double call_rcu(), so leak the callback. */
89978 - ACCESS_ONCE(head->func) = rcu_leak_callback;
89979 + ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
89980 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
89981 return;
89982 }
89983 @@ -2498,7 +2498,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
89984 local_irq_restore(flags);
89985 return;
89986 }
89987 - ACCESS_ONCE(rdp->qlen)++;
89988 + ACCESS_ONCE_RW(rdp->qlen)++;
89989 if (lazy)
89990 rdp->qlen_lazy++;
89991 else
89992 @@ -2759,11 +2759,11 @@ void synchronize_sched_expedited(void)
89993 * counter wrap on a 32-bit system. Quite a few more CPUs would of
89994 * course be required on a 64-bit system.
89995 */
89996 - if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
89997 + if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
89998 (ulong)atomic_long_read(&rsp->expedited_done) +
89999 ULONG_MAX / 8)) {
90000 synchronize_sched();
90001 - atomic_long_inc(&rsp->expedited_wrap);
90002 + atomic_long_inc_unchecked(&rsp->expedited_wrap);
90003 return;
90004 }
90005
90006 @@ -2771,7 +2771,7 @@ void synchronize_sched_expedited(void)
90007 * Take a ticket. Note that atomic_inc_return() implies a
90008 * full memory barrier.
90009 */
90010 - snap = atomic_long_inc_return(&rsp->expedited_start);
90011 + snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
90012 firstsnap = snap;
90013 get_online_cpus();
90014 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
90015 @@ -2784,14 +2784,14 @@ void synchronize_sched_expedited(void)
90016 synchronize_sched_expedited_cpu_stop,
90017 NULL) == -EAGAIN) {
90018 put_online_cpus();
90019 - atomic_long_inc(&rsp->expedited_tryfail);
90020 + atomic_long_inc_unchecked(&rsp->expedited_tryfail);
90021
90022 /* Check to see if someone else did our work for us. */
90023 s = atomic_long_read(&rsp->expedited_done);
90024 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
90025 /* ensure test happens before caller kfree */
90026 smp_mb__before_atomic_inc(); /* ^^^ */
90027 - atomic_long_inc(&rsp->expedited_workdone1);
90028 + atomic_long_inc_unchecked(&rsp->expedited_workdone1);
90029 return;
90030 }
90031
90032 @@ -2800,7 +2800,7 @@ void synchronize_sched_expedited(void)
90033 udelay(trycount * num_online_cpus());
90034 } else {
90035 wait_rcu_gp(call_rcu_sched);
90036 - atomic_long_inc(&rsp->expedited_normal);
90037 + atomic_long_inc_unchecked(&rsp->expedited_normal);
90038 return;
90039 }
90040
90041 @@ -2809,7 +2809,7 @@ void synchronize_sched_expedited(void)
90042 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
90043 /* ensure test happens before caller kfree */
90044 smp_mb__before_atomic_inc(); /* ^^^ */
90045 - atomic_long_inc(&rsp->expedited_workdone2);
90046 + atomic_long_inc_unchecked(&rsp->expedited_workdone2);
90047 return;
90048 }
90049
90050 @@ -2821,10 +2821,10 @@ void synchronize_sched_expedited(void)
90051 * period works for us.
90052 */
90053 get_online_cpus();
90054 - snap = atomic_long_read(&rsp->expedited_start);
90055 + snap = atomic_long_read_unchecked(&rsp->expedited_start);
90056 smp_mb(); /* ensure read is before try_stop_cpus(). */
90057 }
90058 - atomic_long_inc(&rsp->expedited_stoppedcpus);
90059 + atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
90060
90061 /*
90062 * Everyone up to our most recent fetch is covered by our grace
90063 @@ -2833,16 +2833,16 @@ void synchronize_sched_expedited(void)
90064 * than we did already did their update.
90065 */
90066 do {
90067 - atomic_long_inc(&rsp->expedited_done_tries);
90068 + atomic_long_inc_unchecked(&rsp->expedited_done_tries);
90069 s = atomic_long_read(&rsp->expedited_done);
90070 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
90071 /* ensure test happens before caller kfree */
90072 smp_mb__before_atomic_inc(); /* ^^^ */
90073 - atomic_long_inc(&rsp->expedited_done_lost);
90074 + atomic_long_inc_unchecked(&rsp->expedited_done_lost);
90075 break;
90076 }
90077 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
90078 - atomic_long_inc(&rsp->expedited_done_exit);
90079 + atomic_long_inc_unchecked(&rsp->expedited_done_exit);
90080
90081 put_online_cpus();
90082 }
90083 @@ -3048,7 +3048,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
90084 * ACCESS_ONCE() to prevent the compiler from speculating
90085 * the increment to precede the early-exit check.
90086 */
90087 - ACCESS_ONCE(rsp->n_barrier_done)++;
90088 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
90089 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
90090 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
90091 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
90092 @@ -3098,7 +3098,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
90093
90094 /* Increment ->n_barrier_done to prevent duplicate work. */
90095 smp_mb(); /* Keep increment after above mechanism. */
90096 - ACCESS_ONCE(rsp->n_barrier_done)++;
90097 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
90098 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
90099 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
90100 smp_mb(); /* Keep increment before caller's subsequent code. */
90101 @@ -3143,10 +3143,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
90102 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
90103 init_callback_list(rdp);
90104 rdp->qlen_lazy = 0;
90105 - ACCESS_ONCE(rdp->qlen) = 0;
90106 + ACCESS_ONCE_RW(rdp->qlen) = 0;
90107 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
90108 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
90109 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
90110 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
90111 rdp->cpu = cpu;
90112 rdp->rsp = rsp;
90113 rcu_boot_init_nocb_percpu_data(rdp);
90114 @@ -3180,8 +3180,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
90115 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
90116 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
90117 rcu_sysidle_init_percpu_data(rdp->dynticks);
90118 - atomic_set(&rdp->dynticks->dynticks,
90119 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
90120 + atomic_set_unchecked(&rdp->dynticks->dynticks,
90121 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
90122 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
90123
90124 /* Add CPU to rcu_node bitmasks. */
90125 diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
90126 index 75dc3c3..b95d624 100644
90127 --- a/kernel/rcu/tree.h
90128 +++ b/kernel/rcu/tree.h
90129 @@ -87,11 +87,11 @@ struct rcu_dynticks {
90130 long long dynticks_nesting; /* Track irq/process nesting level. */
90131 /* Process level is worth LLONG_MAX/2. */
90132 int dynticks_nmi_nesting; /* Track NMI nesting level. */
90133 - atomic_t dynticks; /* Even value for idle, else odd. */
90134 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
90135 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
90136 long long dynticks_idle_nesting;
90137 /* irq/process nesting level from idle. */
90138 - atomic_t dynticks_idle; /* Even value for idle, else odd. */
90139 + atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
90140 /* "Idle" excludes userspace execution. */
90141 unsigned long dynticks_idle_jiffies;
90142 /* End of last non-NMI non-idle period. */
90143 @@ -431,17 +431,17 @@ struct rcu_state {
90144 /* _rcu_barrier(). */
90145 /* End of fields guarded by barrier_mutex. */
90146
90147 - atomic_long_t expedited_start; /* Starting ticket. */
90148 - atomic_long_t expedited_done; /* Done ticket. */
90149 - atomic_long_t expedited_wrap; /* # near-wrap incidents. */
90150 - atomic_long_t expedited_tryfail; /* # acquisition failures. */
90151 - atomic_long_t expedited_workdone1; /* # done by others #1. */
90152 - atomic_long_t expedited_workdone2; /* # done by others #2. */
90153 - atomic_long_t expedited_normal; /* # fallbacks to normal. */
90154 - atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
90155 - atomic_long_t expedited_done_tries; /* # tries to update _done. */
90156 - atomic_long_t expedited_done_lost; /* # times beaten to _done. */
90157 - atomic_long_t expedited_done_exit; /* # times exited _done loop. */
90158 + atomic_long_unchecked_t expedited_start; /* Starting ticket. */
90159 + atomic_long_t expedited_done; /* Done ticket. */
90160 + atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
90161 + atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
90162 + atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
90163 + atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
90164 + atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
90165 + atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
90166 + atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
90167 + atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
90168 + atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
90169
90170 unsigned long jiffies_force_qs; /* Time at which to invoke */
90171 /* force_quiescent_state(). */
90172 diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
90173 index 962d1d5..c6c62d12d 100644
90174 --- a/kernel/rcu/tree_plugin.h
90175 +++ b/kernel/rcu/tree_plugin.h
90176 @@ -758,7 +758,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
90177 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
90178 {
90179 return !rcu_preempted_readers_exp(rnp) &&
90180 - ACCESS_ONCE(rnp->expmask) == 0;
90181 + ACCESS_ONCE_RW(rnp->expmask) == 0;
90182 }
90183
90184 /*
90185 @@ -920,7 +920,7 @@ void synchronize_rcu_expedited(void)
90186
90187 /* Clean up and exit. */
90188 smp_mb(); /* ensure expedited GP seen before counter increment. */
90189 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
90190 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
90191 unlock_mb_ret:
90192 mutex_unlock(&sync_rcu_preempt_exp_mutex);
90193 mb_ret:
90194 @@ -1496,7 +1496,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
90195 free_cpumask_var(cm);
90196 }
90197
90198 -static struct smp_hotplug_thread rcu_cpu_thread_spec = {
90199 +static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
90200 .store = &rcu_cpu_kthread_task,
90201 .thread_should_run = rcu_cpu_kthread_should_run,
90202 .thread_fn = rcu_cpu_kthread,
90203 @@ -1972,7 +1972,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
90204 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
90205 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
90206 cpu, ticks_value, ticks_title,
90207 - atomic_read(&rdtp->dynticks) & 0xfff,
90208 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
90209 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
90210 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
90211 fast_no_hz);
90212 @@ -2138,7 +2138,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
90213
90214 /* Enqueue the callback on the nocb list and update counts. */
90215 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
90216 - ACCESS_ONCE(*old_rhpp) = rhp;
90217 + ACCESS_ONCE_RW(*old_rhpp) = rhp;
90218 atomic_long_add(rhcount, &rdp->nocb_q_count);
90219 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
90220
90221 @@ -2311,12 +2311,12 @@ static int rcu_nocb_kthread(void *arg)
90222 * Extract queued callbacks, update counts, and wait
90223 * for a grace period to elapse.
90224 */
90225 - ACCESS_ONCE(rdp->nocb_head) = NULL;
90226 + ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
90227 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
90228 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
90229 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
90230 - ACCESS_ONCE(rdp->nocb_p_count) += c;
90231 - ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
90232 + ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
90233 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
90234 rcu_nocb_wait_gp(rdp);
90235
90236 /* Each pass through the following loop invokes a callback. */
90237 @@ -2342,8 +2342,8 @@ static int rcu_nocb_kthread(void *arg)
90238 list = next;
90239 }
90240 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
90241 - ACCESS_ONCE(rdp->nocb_p_count) -= c;
90242 - ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
90243 + ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
90244 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
90245 rdp->n_nocbs_invoked += c;
90246 }
90247 return 0;
90248 @@ -2360,7 +2360,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
90249 {
90250 if (!rcu_nocb_need_deferred_wakeup(rdp))
90251 return;
90252 - ACCESS_ONCE(rdp->nocb_defer_wakeup) = false;
90253 + ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = false;
90254 wake_up(&rdp->nocb_wq);
90255 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWakeEmpty"));
90256 }
90257 @@ -2386,7 +2386,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
90258 t = kthread_run(rcu_nocb_kthread, rdp,
90259 "rcuo%c/%d", rsp->abbr, cpu);
90260 BUG_ON(IS_ERR(t));
90261 - ACCESS_ONCE(rdp->nocb_kthread) = t;
90262 + ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
90263 }
90264 }
90265
90266 @@ -2522,11 +2522,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
90267
90268 /* Record start of fully idle period. */
90269 j = jiffies;
90270 - ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
90271 + ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
90272 smp_mb__before_atomic_inc();
90273 - atomic_inc(&rdtp->dynticks_idle);
90274 + atomic_inc_unchecked(&rdtp->dynticks_idle);
90275 smp_mb__after_atomic_inc();
90276 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
90277 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
90278 }
90279
90280 /*
90281 @@ -2591,9 +2591,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
90282
90283 /* Record end of idle period. */
90284 smp_mb__before_atomic_inc();
90285 - atomic_inc(&rdtp->dynticks_idle);
90286 + atomic_inc_unchecked(&rdtp->dynticks_idle);
90287 smp_mb__after_atomic_inc();
90288 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
90289 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
90290
90291 /*
90292 * If we are the timekeeping CPU, we are permitted to be non-idle
90293 @@ -2634,7 +2634,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
90294 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
90295
90296 /* Pick up current idle and NMI-nesting counter and check. */
90297 - cur = atomic_read(&rdtp->dynticks_idle);
90298 + cur = atomic_read_unchecked(&rdtp->dynticks_idle);
90299 if (cur & 0x1) {
90300 *isidle = false; /* We are not idle! */
90301 return;
90302 @@ -2697,7 +2697,7 @@ static void rcu_sysidle(unsigned long j)
90303 case RCU_SYSIDLE_NOT:
90304
90305 /* First time all are idle, so note a short idle period. */
90306 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
90307 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
90308 break;
90309
90310 case RCU_SYSIDLE_SHORT:
90311 @@ -2734,7 +2734,7 @@ static void rcu_sysidle(unsigned long j)
90312 static void rcu_sysidle_cancel(void)
90313 {
90314 smp_mb();
90315 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
90316 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
90317 }
90318
90319 /*
90320 @@ -2782,7 +2782,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
90321 smp_mb(); /* grace period precedes setting inuse. */
90322
90323 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
90324 - ACCESS_ONCE(rshp->inuse) = 0;
90325 + ACCESS_ONCE_RW(rshp->inuse) = 0;
90326 }
90327
90328 /*
90329 diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
90330 index 5cdc62e..cc52e88 100644
90331 --- a/kernel/rcu/tree_trace.c
90332 +++ b/kernel/rcu/tree_trace.c
90333 @@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
90334 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
90335 rdp->passed_quiesce, rdp->qs_pending);
90336 seq_printf(m, " dt=%d/%llx/%d df=%lu",
90337 - atomic_read(&rdp->dynticks->dynticks),
90338 + atomic_read_unchecked(&rdp->dynticks->dynticks),
90339 rdp->dynticks->dynticks_nesting,
90340 rdp->dynticks->dynticks_nmi_nesting,
90341 rdp->dynticks_fqs);
90342 @@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
90343 struct rcu_state *rsp = (struct rcu_state *)m->private;
90344
90345 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",
90346 - atomic_long_read(&rsp->expedited_start),
90347 + atomic_long_read_unchecked(&rsp->expedited_start),
90348 atomic_long_read(&rsp->expedited_done),
90349 - atomic_long_read(&rsp->expedited_wrap),
90350 - atomic_long_read(&rsp->expedited_tryfail),
90351 - atomic_long_read(&rsp->expedited_workdone1),
90352 - atomic_long_read(&rsp->expedited_workdone2),
90353 - atomic_long_read(&rsp->expedited_normal),
90354 - atomic_long_read(&rsp->expedited_stoppedcpus),
90355 - atomic_long_read(&rsp->expedited_done_tries),
90356 - atomic_long_read(&rsp->expedited_done_lost),
90357 - atomic_long_read(&rsp->expedited_done_exit));
90358 + atomic_long_read_unchecked(&rsp->expedited_wrap),
90359 + atomic_long_read_unchecked(&rsp->expedited_tryfail),
90360 + atomic_long_read_unchecked(&rsp->expedited_workdone1),
90361 + atomic_long_read_unchecked(&rsp->expedited_workdone2),
90362 + atomic_long_read_unchecked(&rsp->expedited_normal),
90363 + atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
90364 + atomic_long_read_unchecked(&rsp->expedited_done_tries),
90365 + atomic_long_read_unchecked(&rsp->expedited_done_lost),
90366 + atomic_long_read_unchecked(&rsp->expedited_done_exit));
90367 return 0;
90368 }
90369
90370 diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
90371 index 4c0a9b0..7e81362 100644
90372 --- a/kernel/rcu/update.c
90373 +++ b/kernel/rcu/update.c
90374 @@ -311,10 +311,10 @@ int rcu_jiffies_till_stall_check(void)
90375 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
90376 */
90377 if (till_stall_check < 3) {
90378 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
90379 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
90380 till_stall_check = 3;
90381 } else if (till_stall_check > 300) {
90382 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
90383 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
90384 till_stall_check = 300;
90385 }
90386 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
90387 diff --git a/kernel/resource.c b/kernel/resource.c
90388 index 8957d68..770cbe4 100644
90389 --- a/kernel/resource.c
90390 +++ b/kernel/resource.c
90391 @@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
90392
90393 static int __init ioresources_init(void)
90394 {
90395 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
90396 +#ifdef CONFIG_GRKERNSEC_PROC_USER
90397 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
90398 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
90399 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
90400 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
90401 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
90402 +#endif
90403 +#else
90404 proc_create("ioports", 0, NULL, &proc_ioports_operations);
90405 proc_create("iomem", 0, NULL, &proc_iomem_operations);
90406 +#endif
90407 return 0;
90408 }
90409 __initcall(ioresources_init);
90410 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
90411 index e73efba..c9bfbd4 100644
90412 --- a/kernel/sched/auto_group.c
90413 +++ b/kernel/sched/auto_group.c
90414 @@ -11,7 +11,7 @@
90415
90416 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
90417 static struct autogroup autogroup_default;
90418 -static atomic_t autogroup_seq_nr;
90419 +static atomic_unchecked_t autogroup_seq_nr;
90420
90421 void __init autogroup_init(struct task_struct *init_task)
90422 {
90423 @@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
90424
90425 kref_init(&ag->kref);
90426 init_rwsem(&ag->lock);
90427 - ag->id = atomic_inc_return(&autogroup_seq_nr);
90428 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
90429 ag->tg = tg;
90430 #ifdef CONFIG_RT_GROUP_SCHED
90431 /*
90432 diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
90433 index a63f4dc..349bbb0 100644
90434 --- a/kernel/sched/completion.c
90435 +++ b/kernel/sched/completion.c
90436 @@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
90437 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
90438 * or number of jiffies left till timeout) if completed.
90439 */
90440 -long __sched
90441 +long __sched __intentional_overflow(-1)
90442 wait_for_completion_interruptible_timeout(struct completion *x,
90443 unsigned long timeout)
90444 {
90445 @@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
90446 *
90447 * Return: -ERESTARTSYS if interrupted, 0 if completed.
90448 */
90449 -int __sched wait_for_completion_killable(struct completion *x)
90450 +int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
90451 {
90452 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
90453 if (t == -ERESTARTSYS)
90454 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
90455 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
90456 * or number of jiffies left till timeout) if completed.
90457 */
90458 -long __sched
90459 +long __sched __intentional_overflow(-1)
90460 wait_for_completion_killable_timeout(struct completion *x,
90461 unsigned long timeout)
90462 {
90463 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
90464 index 8da7e49..ef10a02 100644
90465 --- a/kernel/sched/core.c
90466 +++ b/kernel/sched/core.c
90467 @@ -1775,7 +1775,7 @@ void set_numabalancing_state(bool enabled)
90468 int sysctl_numa_balancing(struct ctl_table *table, int write,
90469 void __user *buffer, size_t *lenp, loff_t *ppos)
90470 {
90471 - struct ctl_table t;
90472 + ctl_table_no_const t;
90473 int err;
90474 int state = numabalancing_enabled;
90475
90476 @@ -2238,8 +2238,10 @@ context_switch(struct rq *rq, struct task_struct *prev,
90477 next->active_mm = oldmm;
90478 atomic_inc(&oldmm->mm_count);
90479 enter_lazy_tlb(oldmm, next);
90480 - } else
90481 + } else {
90482 switch_mm(oldmm, mm, next);
90483 + populate_stack();
90484 + }
90485
90486 if (!prev->mm) {
90487 prev->active_mm = NULL;
90488 @@ -3004,6 +3006,8 @@ int can_nice(const struct task_struct *p, const int nice)
90489 /* convert nice value [19,-20] to rlimit style value [1,40] */
90490 int nice_rlim = 20 - nice;
90491
90492 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
90493 +
90494 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
90495 capable(CAP_SYS_NICE));
90496 }
90497 @@ -3037,7 +3041,8 @@ SYSCALL_DEFINE1(nice, int, increment)
90498 if (nice > MAX_NICE)
90499 nice = MAX_NICE;
90500
90501 - if (increment < 0 && !can_nice(current, nice))
90502 + if (increment < 0 && (!can_nice(current, nice) ||
90503 + gr_handle_chroot_nice()))
90504 return -EPERM;
90505
90506 retval = security_task_setnice(current, nice);
90507 @@ -3310,6 +3315,7 @@ recheck:
90508 if (policy != p->policy && !rlim_rtprio)
90509 return -EPERM;
90510
90511 + gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
90512 /* can't increase priority */
90513 if (attr->sched_priority > p->rt_priority &&
90514 attr->sched_priority > rlim_rtprio)
90515 @@ -4708,6 +4714,7 @@ void idle_task_exit(void)
90516
90517 if (mm != &init_mm) {
90518 switch_mm(mm, &init_mm, current);
90519 + populate_stack();
90520 finish_arch_post_lock_switch();
90521 }
90522 mmdrop(mm);
90523 @@ -4803,7 +4810,7 @@ static void migrate_tasks(unsigned int dead_cpu)
90524
90525 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
90526
90527 -static struct ctl_table sd_ctl_dir[] = {
90528 +static ctl_table_no_const sd_ctl_dir[] __read_only = {
90529 {
90530 .procname = "sched_domain",
90531 .mode = 0555,
90532 @@ -4820,17 +4827,17 @@ static struct ctl_table sd_ctl_root[] = {
90533 {}
90534 };
90535
90536 -static struct ctl_table *sd_alloc_ctl_entry(int n)
90537 +static ctl_table_no_const *sd_alloc_ctl_entry(int n)
90538 {
90539 - struct ctl_table *entry =
90540 + ctl_table_no_const *entry =
90541 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
90542
90543 return entry;
90544 }
90545
90546 -static void sd_free_ctl_entry(struct ctl_table **tablep)
90547 +static void sd_free_ctl_entry(ctl_table_no_const *tablep)
90548 {
90549 - struct ctl_table *entry;
90550 + ctl_table_no_const *entry;
90551
90552 /*
90553 * In the intermediate directories, both the child directory and
90554 @@ -4838,22 +4845,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
90555 * will always be set. In the lowest directory the names are
90556 * static strings and all have proc handlers.
90557 */
90558 - for (entry = *tablep; entry->mode; entry++) {
90559 - if (entry->child)
90560 - sd_free_ctl_entry(&entry->child);
90561 + for (entry = tablep; entry->mode; entry++) {
90562 + if (entry->child) {
90563 + sd_free_ctl_entry(entry->child);
90564 + pax_open_kernel();
90565 + entry->child = NULL;
90566 + pax_close_kernel();
90567 + }
90568 if (entry->proc_handler == NULL)
90569 kfree(entry->procname);
90570 }
90571
90572 - kfree(*tablep);
90573 - *tablep = NULL;
90574 + kfree(tablep);
90575 }
90576
90577 static int min_load_idx = 0;
90578 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
90579
90580 static void
90581 -set_table_entry(struct ctl_table *entry,
90582 +set_table_entry(ctl_table_no_const *entry,
90583 const char *procname, void *data, int maxlen,
90584 umode_t mode, proc_handler *proc_handler,
90585 bool load_idx)
90586 @@ -4873,7 +4883,7 @@ set_table_entry(struct ctl_table *entry,
90587 static struct ctl_table *
90588 sd_alloc_ctl_domain_table(struct sched_domain *sd)
90589 {
90590 - struct ctl_table *table = sd_alloc_ctl_entry(14);
90591 + ctl_table_no_const *table = sd_alloc_ctl_entry(14);
90592
90593 if (table == NULL)
90594 return NULL;
90595 @@ -4911,9 +4921,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
90596 return table;
90597 }
90598
90599 -static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
90600 +static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
90601 {
90602 - struct ctl_table *entry, *table;
90603 + ctl_table_no_const *entry, *table;
90604 struct sched_domain *sd;
90605 int domain_num = 0, i;
90606 char buf[32];
90607 @@ -4940,11 +4950,13 @@ static struct ctl_table_header *sd_sysctl_header;
90608 static void register_sched_domain_sysctl(void)
90609 {
90610 int i, cpu_num = num_possible_cpus();
90611 - struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
90612 + ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
90613 char buf[32];
90614
90615 WARN_ON(sd_ctl_dir[0].child);
90616 + pax_open_kernel();
90617 sd_ctl_dir[0].child = entry;
90618 + pax_close_kernel();
90619
90620 if (entry == NULL)
90621 return;
90622 @@ -4967,8 +4979,12 @@ static void unregister_sched_domain_sysctl(void)
90623 if (sd_sysctl_header)
90624 unregister_sysctl_table(sd_sysctl_header);
90625 sd_sysctl_header = NULL;
90626 - if (sd_ctl_dir[0].child)
90627 - sd_free_ctl_entry(&sd_ctl_dir[0].child);
90628 + if (sd_ctl_dir[0].child) {
90629 + sd_free_ctl_entry(sd_ctl_dir[0].child);
90630 + pax_open_kernel();
90631 + sd_ctl_dir[0].child = NULL;
90632 + pax_close_kernel();
90633 + }
90634 }
90635 #else
90636 static void register_sched_domain_sysctl(void)
90637 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
90638 index 8cbe2d2..61f20a1 100644
90639 --- a/kernel/sched/fair.c
90640 +++ b/kernel/sched/fair.c
90641 @@ -1806,7 +1806,7 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)
90642
90643 static void reset_ptenuma_scan(struct task_struct *p)
90644 {
90645 - ACCESS_ONCE(p->mm->numa_scan_seq)++;
90646 + ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
90647 p->mm->numa_scan_offset = 0;
90648 }
90649
90650 @@ -7181,7 +7181,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
90651 * run_rebalance_domains is triggered when needed from the scheduler tick.
90652 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
90653 */
90654 -static void run_rebalance_domains(struct softirq_action *h)
90655 +static __latent_entropy void run_rebalance_domains(void)
90656 {
90657 struct rq *this_rq = this_rq();
90658 enum cpu_idle_type idle = this_rq->idle_balance ?
90659 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
90660 index 369b4d6..fa4eb3b 100644
90661 --- a/kernel/sched/sched.h
90662 +++ b/kernel/sched/sched.h
90663 @@ -1157,7 +1157,7 @@ struct sched_class {
90664 #ifdef CONFIG_FAIR_GROUP_SCHED
90665 void (*task_move_group) (struct task_struct *p, int on_rq);
90666 #endif
90667 -};
90668 +} __do_const;
90669
90670 static inline void put_prev_task(struct rq *rq, struct task_struct *prev)
90671 {
90672 diff --git a/kernel/signal.c b/kernel/signal.c
90673 index 6ea13c0..31e3b25 100644
90674 --- a/kernel/signal.c
90675 +++ b/kernel/signal.c
90676 @@ -53,12 +53,12 @@ static struct kmem_cache *sigqueue_cachep;
90677
90678 int print_fatal_signals __read_mostly;
90679
90680 -static void __user *sig_handler(struct task_struct *t, int sig)
90681 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
90682 {
90683 return t->sighand->action[sig - 1].sa.sa_handler;
90684 }
90685
90686 -static int sig_handler_ignored(void __user *handler, int sig)
90687 +static int sig_handler_ignored(__sighandler_t handler, int sig)
90688 {
90689 /* Is it explicitly or implicitly ignored? */
90690 return handler == SIG_IGN ||
90691 @@ -67,7 +67,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
90692
90693 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
90694 {
90695 - void __user *handler;
90696 + __sighandler_t handler;
90697
90698 handler = sig_handler(t, sig);
90699
90700 @@ -371,6 +371,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
90701 atomic_inc(&user->sigpending);
90702 rcu_read_unlock();
90703
90704 + if (!override_rlimit)
90705 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
90706 +
90707 if (override_rlimit ||
90708 atomic_read(&user->sigpending) <=
90709 task_rlimit(t, RLIMIT_SIGPENDING)) {
90710 @@ -498,7 +501,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
90711
90712 int unhandled_signal(struct task_struct *tsk, int sig)
90713 {
90714 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
90715 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
90716 if (is_global_init(tsk))
90717 return 1;
90718 if (handler != SIG_IGN && handler != SIG_DFL)
90719 @@ -818,6 +821,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
90720 }
90721 }
90722
90723 + /* allow glibc communication via tgkill to other threads in our
90724 + thread group */
90725 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
90726 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
90727 + && gr_handle_signal(t, sig))
90728 + return -EPERM;
90729 +
90730 return security_task_kill(t, info, sig, 0);
90731 }
90732
90733 @@ -1201,7 +1211,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
90734 return send_signal(sig, info, p, 1);
90735 }
90736
90737 -static int
90738 +int
90739 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90740 {
90741 return send_signal(sig, info, t, 0);
90742 @@ -1238,6 +1248,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90743 unsigned long int flags;
90744 int ret, blocked, ignored;
90745 struct k_sigaction *action;
90746 + int is_unhandled = 0;
90747
90748 spin_lock_irqsave(&t->sighand->siglock, flags);
90749 action = &t->sighand->action[sig-1];
90750 @@ -1252,9 +1263,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90751 }
90752 if (action->sa.sa_handler == SIG_DFL)
90753 t->signal->flags &= ~SIGNAL_UNKILLABLE;
90754 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
90755 + is_unhandled = 1;
90756 ret = specific_send_sig_info(sig, info, t);
90757 spin_unlock_irqrestore(&t->sighand->siglock, flags);
90758
90759 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
90760 + normal operation */
90761 + if (is_unhandled) {
90762 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
90763 + gr_handle_crash(t, sig);
90764 + }
90765 +
90766 return ret;
90767 }
90768
90769 @@ -1321,8 +1341,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
90770 ret = check_kill_permission(sig, info, p);
90771 rcu_read_unlock();
90772
90773 - if (!ret && sig)
90774 + if (!ret && sig) {
90775 ret = do_send_sig_info(sig, info, p, true);
90776 + if (!ret)
90777 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
90778 + }
90779
90780 return ret;
90781 }
90782 @@ -2928,7 +2951,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
90783 int error = -ESRCH;
90784
90785 rcu_read_lock();
90786 - p = find_task_by_vpid(pid);
90787 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
90788 + /* allow glibc communication via tgkill to other threads in our
90789 + thread group */
90790 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
90791 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
90792 + p = find_task_by_vpid_unrestricted(pid);
90793 + else
90794 +#endif
90795 + p = find_task_by_vpid(pid);
90796 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
90797 error = check_kill_permission(sig, info, p);
90798 /*
90799 @@ -3241,8 +3272,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
90800 }
90801 seg = get_fs();
90802 set_fs(KERNEL_DS);
90803 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
90804 - (stack_t __force __user *) &uoss,
90805 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
90806 + (stack_t __force_user *) &uoss,
90807 compat_user_stack_pointer());
90808 set_fs(seg);
90809 if (ret >= 0 && uoss_ptr) {
90810 diff --git a/kernel/smpboot.c b/kernel/smpboot.c
90811 index eb89e18..a4e6792 100644
90812 --- a/kernel/smpboot.c
90813 +++ b/kernel/smpboot.c
90814 @@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
90815 }
90816 smpboot_unpark_thread(plug_thread, cpu);
90817 }
90818 - list_add(&plug_thread->list, &hotplug_threads);
90819 + pax_list_add(&plug_thread->list, &hotplug_threads);
90820 out:
90821 mutex_unlock(&smpboot_threads_lock);
90822 return ret;
90823 @@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
90824 {
90825 get_online_cpus();
90826 mutex_lock(&smpboot_threads_lock);
90827 - list_del(&plug_thread->list);
90828 + pax_list_del(&plug_thread->list);
90829 smpboot_destroy_threads(plug_thread);
90830 mutex_unlock(&smpboot_threads_lock);
90831 put_online_cpus();
90832 diff --git a/kernel/softirq.c b/kernel/softirq.c
90833 index 92f24f5..db41501 100644
90834 --- a/kernel/softirq.c
90835 +++ b/kernel/softirq.c
90836 @@ -53,7 +53,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
90837 EXPORT_SYMBOL(irq_stat);
90838 #endif
90839
90840 -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
90841 +static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
90842
90843 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
90844
90845 @@ -268,7 +268,7 @@ restart:
90846 kstat_incr_softirqs_this_cpu(vec_nr);
90847
90848 trace_softirq_entry(vec_nr);
90849 - h->action(h);
90850 + h->action();
90851 trace_softirq_exit(vec_nr);
90852 if (unlikely(prev_count != preempt_count())) {
90853 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
90854 @@ -428,7 +428,7 @@ void __raise_softirq_irqoff(unsigned int nr)
90855 or_softirq_pending(1UL << nr);
90856 }
90857
90858 -void open_softirq(int nr, void (*action)(struct softirq_action *))
90859 +void __init open_softirq(int nr, void (*action)(void))
90860 {
90861 softirq_vec[nr].action = action;
90862 }
90863 @@ -480,7 +480,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
90864 }
90865 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
90866
90867 -static void tasklet_action(struct softirq_action *a)
90868 +static void tasklet_action(void)
90869 {
90870 struct tasklet_struct *list;
90871
90872 @@ -516,7 +516,7 @@ static void tasklet_action(struct softirq_action *a)
90873 }
90874 }
90875
90876 -static void tasklet_hi_action(struct softirq_action *a)
90877 +static __latent_entropy void tasklet_hi_action(void)
90878 {
90879 struct tasklet_struct *list;
90880
90881 @@ -743,7 +743,7 @@ static struct notifier_block cpu_nfb = {
90882 .notifier_call = cpu_callback
90883 };
90884
90885 -static struct smp_hotplug_thread softirq_threads = {
90886 +static struct smp_hotplug_thread softirq_threads __read_only = {
90887 .store = &ksoftirqd,
90888 .thread_should_run = ksoftirqd_should_run,
90889 .thread_fn = run_ksoftirqd,
90890 diff --git a/kernel/sys.c b/kernel/sys.c
90891 index fba0f29..84400e2 100644
90892 --- a/kernel/sys.c
90893 +++ b/kernel/sys.c
90894 @@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
90895 error = -EACCES;
90896 goto out;
90897 }
90898 +
90899 + if (gr_handle_chroot_setpriority(p, niceval)) {
90900 + error = -EACCES;
90901 + goto out;
90902 + }
90903 +
90904 no_nice = security_task_setnice(p, niceval);
90905 if (no_nice) {
90906 error = no_nice;
90907 @@ -351,6 +357,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
90908 goto error;
90909 }
90910
90911 + if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
90912 + goto error;
90913 +
90914 if (rgid != (gid_t) -1 ||
90915 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
90916 new->sgid = new->egid;
90917 @@ -386,6 +395,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
90918 old = current_cred();
90919
90920 retval = -EPERM;
90921 +
90922 + if (gr_check_group_change(kgid, kgid, kgid))
90923 + goto error;
90924 +
90925 if (ns_capable(old->user_ns, CAP_SETGID))
90926 new->gid = new->egid = new->sgid = new->fsgid = kgid;
90927 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
90928 @@ -403,7 +416,7 @@ error:
90929 /*
90930 * change the user struct in a credentials set to match the new UID
90931 */
90932 -static int set_user(struct cred *new)
90933 +int set_user(struct cred *new)
90934 {
90935 struct user_struct *new_user;
90936
90937 @@ -483,6 +496,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
90938 goto error;
90939 }
90940
90941 + if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
90942 + goto error;
90943 +
90944 if (!uid_eq(new->uid, old->uid)) {
90945 retval = set_user(new);
90946 if (retval < 0)
90947 @@ -533,6 +549,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
90948 old = current_cred();
90949
90950 retval = -EPERM;
90951 +
90952 + if (gr_check_crash_uid(kuid))
90953 + goto error;
90954 + if (gr_check_user_change(kuid, kuid, kuid))
90955 + goto error;
90956 +
90957 if (ns_capable(old->user_ns, CAP_SETUID)) {
90958 new->suid = new->uid = kuid;
90959 if (!uid_eq(kuid, old->uid)) {
90960 @@ -602,6 +624,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
90961 goto error;
90962 }
90963
90964 + if (gr_check_user_change(kruid, keuid, INVALID_UID))
90965 + goto error;
90966 +
90967 if (ruid != (uid_t) -1) {
90968 new->uid = kruid;
90969 if (!uid_eq(kruid, old->uid)) {
90970 @@ -684,6 +709,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
90971 goto error;
90972 }
90973
90974 + if (gr_check_group_change(krgid, kegid, INVALID_GID))
90975 + goto error;
90976 +
90977 if (rgid != (gid_t) -1)
90978 new->gid = krgid;
90979 if (egid != (gid_t) -1)
90980 @@ -745,12 +773,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
90981 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
90982 ns_capable(old->user_ns, CAP_SETUID)) {
90983 if (!uid_eq(kuid, old->fsuid)) {
90984 + if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
90985 + goto error;
90986 +
90987 new->fsuid = kuid;
90988 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
90989 goto change_okay;
90990 }
90991 }
90992
90993 +error:
90994 abort_creds(new);
90995 return old_fsuid;
90996
90997 @@ -783,12 +815,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
90998 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
90999 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
91000 ns_capable(old->user_ns, CAP_SETGID)) {
91001 + if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
91002 + goto error;
91003 +
91004 if (!gid_eq(kgid, old->fsgid)) {
91005 new->fsgid = kgid;
91006 goto change_okay;
91007 }
91008 }
91009
91010 +error:
91011 abort_creds(new);
91012 return old_fsgid;
91013
91014 @@ -1167,19 +1203,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
91015 return -EFAULT;
91016
91017 down_read(&uts_sem);
91018 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
91019 + error = __copy_to_user(name->sysname, &utsname()->sysname,
91020 __OLD_UTS_LEN);
91021 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
91022 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
91023 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
91024 __OLD_UTS_LEN);
91025 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
91026 - error |= __copy_to_user(&name->release, &utsname()->release,
91027 + error |= __copy_to_user(name->release, &utsname()->release,
91028 __OLD_UTS_LEN);
91029 error |= __put_user(0, name->release + __OLD_UTS_LEN);
91030 - error |= __copy_to_user(&name->version, &utsname()->version,
91031 + error |= __copy_to_user(name->version, &utsname()->version,
91032 __OLD_UTS_LEN);
91033 error |= __put_user(0, name->version + __OLD_UTS_LEN);
91034 - error |= __copy_to_user(&name->machine, &utsname()->machine,
91035 + error |= __copy_to_user(name->machine, &utsname()->machine,
91036 __OLD_UTS_LEN);
91037 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
91038 up_read(&uts_sem);
91039 @@ -1381,6 +1417,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
91040 */
91041 new_rlim->rlim_cur = 1;
91042 }
91043 + /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
91044 + is changed to a lower value. Since tasks can be created by the same
91045 + user in between this limit change and an execve by this task, force
91046 + a recheck only for this task by setting PF_NPROC_EXCEEDED
91047 + */
91048 + if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
91049 + tsk->flags |= PF_NPROC_EXCEEDED;
91050 }
91051 if (!retval) {
91052 if (old_rlim)
91053 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
91054 index 0e0373f..69f5181 100644
91055 --- a/kernel/sysctl.c
91056 +++ b/kernel/sysctl.c
91057 @@ -94,7 +94,6 @@
91058
91059
91060 #if defined(CONFIG_SYSCTL)
91061 -
91062 /* External variables not in a header file. */
91063 extern int max_threads;
91064 extern int suid_dumpable;
91065 @@ -115,19 +114,20 @@ extern int sysctl_nr_trim_pages;
91066
91067 /* Constants used for minimum and maximum */
91068 #ifdef CONFIG_LOCKUP_DETECTOR
91069 -static int sixty = 60;
91070 +static int sixty __read_only = 60;
91071 #endif
91072
91073 -static int __maybe_unused neg_one = -1;
91074 +static int __maybe_unused neg_one __read_only = -1;
91075
91076 -static int zero;
91077 -static int __maybe_unused one = 1;
91078 -static int __maybe_unused two = 2;
91079 -static int __maybe_unused four = 4;
91080 -static unsigned long one_ul = 1;
91081 -static int one_hundred = 100;
91082 +static int zero __read_only = 0;
91083 +static int __maybe_unused one __read_only = 1;
91084 +static int __maybe_unused two __read_only = 2;
91085 +static int __maybe_unused three __read_only = 3;
91086 +static int __maybe_unused four __read_only = 4;
91087 +static unsigned long one_ul __read_only = 1;
91088 +static int one_hundred __read_only = 100;
91089 #ifdef CONFIG_PRINTK
91090 -static int ten_thousand = 10000;
91091 +static int ten_thousand __read_only = 10000;
91092 #endif
91093
91094 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
91095 @@ -178,10 +178,8 @@ static int proc_taint(struct ctl_table *table, int write,
91096 void __user *buffer, size_t *lenp, loff_t *ppos);
91097 #endif
91098
91099 -#ifdef CONFIG_PRINTK
91100 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
91101 void __user *buffer, size_t *lenp, loff_t *ppos);
91102 -#endif
91103
91104 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
91105 void __user *buffer, size_t *lenp, loff_t *ppos);
91106 @@ -212,6 +210,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
91107
91108 #endif
91109
91110 +extern struct ctl_table grsecurity_table[];
91111 +
91112 static struct ctl_table kern_table[];
91113 static struct ctl_table vm_table[];
91114 static struct ctl_table fs_table[];
91115 @@ -226,6 +226,20 @@ extern struct ctl_table epoll_table[];
91116 int sysctl_legacy_va_layout;
91117 #endif
91118
91119 +#ifdef CONFIG_PAX_SOFTMODE
91120 +static ctl_table pax_table[] = {
91121 + {
91122 + .procname = "softmode",
91123 + .data = &pax_softmode,
91124 + .maxlen = sizeof(unsigned int),
91125 + .mode = 0600,
91126 + .proc_handler = &proc_dointvec,
91127 + },
91128 +
91129 + { }
91130 +};
91131 +#endif
91132 +
91133 /* The default sysctl tables: */
91134
91135 static struct ctl_table sysctl_base_table[] = {
91136 @@ -274,6 +288,22 @@ static int max_extfrag_threshold = 1000;
91137 #endif
91138
91139 static struct ctl_table kern_table[] = {
91140 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
91141 + {
91142 + .procname = "grsecurity",
91143 + .mode = 0500,
91144 + .child = grsecurity_table,
91145 + },
91146 +#endif
91147 +
91148 +#ifdef CONFIG_PAX_SOFTMODE
91149 + {
91150 + .procname = "pax",
91151 + .mode = 0500,
91152 + .child = pax_table,
91153 + },
91154 +#endif
91155 +
91156 {
91157 .procname = "sched_child_runs_first",
91158 .data = &sysctl_sched_child_runs_first,
91159 @@ -629,7 +659,7 @@ static struct ctl_table kern_table[] = {
91160 .data = &modprobe_path,
91161 .maxlen = KMOD_PATH_LEN,
91162 .mode = 0644,
91163 - .proc_handler = proc_dostring,
91164 + .proc_handler = proc_dostring_modpriv,
91165 },
91166 {
91167 .procname = "modules_disabled",
91168 @@ -796,16 +826,20 @@ static struct ctl_table kern_table[] = {
91169 .extra1 = &zero,
91170 .extra2 = &one,
91171 },
91172 +#endif
91173 {
91174 .procname = "kptr_restrict",
91175 .data = &kptr_restrict,
91176 .maxlen = sizeof(int),
91177 .mode = 0644,
91178 .proc_handler = proc_dointvec_minmax_sysadmin,
91179 +#ifdef CONFIG_GRKERNSEC_HIDESYM
91180 + .extra1 = &two,
91181 +#else
91182 .extra1 = &zero,
91183 +#endif
91184 .extra2 = &two,
91185 },
91186 -#endif
91187 {
91188 .procname = "ngroups_max",
91189 .data = &ngroups_max,
91190 @@ -1050,10 +1084,17 @@ static struct ctl_table kern_table[] = {
91191 */
91192 {
91193 .procname = "perf_event_paranoid",
91194 - .data = &sysctl_perf_event_paranoid,
91195 - .maxlen = sizeof(sysctl_perf_event_paranoid),
91196 + .data = &sysctl_perf_event_legitimately_concerned,
91197 + .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
91198 .mode = 0644,
91199 - .proc_handler = proc_dointvec,
91200 + /* go ahead, be a hero */
91201 + .proc_handler = proc_dointvec_minmax_sysadmin,
91202 + .extra1 = &neg_one,
91203 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
91204 + .extra2 = &three,
91205 +#else
91206 + .extra2 = &two,
91207 +#endif
91208 },
91209 {
91210 .procname = "perf_event_mlock_kb",
91211 @@ -1315,6 +1356,13 @@ static struct ctl_table vm_table[] = {
91212 .proc_handler = proc_dointvec_minmax,
91213 .extra1 = &zero,
91214 },
91215 + {
91216 + .procname = "heap_stack_gap",
91217 + .data = &sysctl_heap_stack_gap,
91218 + .maxlen = sizeof(sysctl_heap_stack_gap),
91219 + .mode = 0644,
91220 + .proc_handler = proc_doulongvec_minmax,
91221 + },
91222 #else
91223 {
91224 .procname = "nr_trim_pages",
91225 @@ -1779,6 +1827,16 @@ int proc_dostring(struct ctl_table *table, int write,
91226 buffer, lenp, ppos);
91227 }
91228
91229 +int proc_dostring_modpriv(struct ctl_table *table, int write,
91230 + void __user *buffer, size_t *lenp, loff_t *ppos)
91231 +{
91232 + if (write && !capable(CAP_SYS_MODULE))
91233 + return -EPERM;
91234 +
91235 + return _proc_do_string(table->data, table->maxlen, write,
91236 + buffer, lenp, ppos);
91237 +}
91238 +
91239 static size_t proc_skip_spaces(char **buf)
91240 {
91241 size_t ret;
91242 @@ -1884,6 +1942,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
91243 len = strlen(tmp);
91244 if (len > *size)
91245 len = *size;
91246 + if (len > sizeof(tmp))
91247 + len = sizeof(tmp);
91248 if (copy_to_user(*buf, tmp, len))
91249 return -EFAULT;
91250 *size -= len;
91251 @@ -2048,7 +2108,7 @@ int proc_dointvec(struct ctl_table *table, int write,
91252 static int proc_taint(struct ctl_table *table, int write,
91253 void __user *buffer, size_t *lenp, loff_t *ppos)
91254 {
91255 - struct ctl_table t;
91256 + ctl_table_no_const t;
91257 unsigned long tmptaint = get_taint();
91258 int err;
91259
91260 @@ -2076,7 +2136,6 @@ static int proc_taint(struct ctl_table *table, int write,
91261 return err;
91262 }
91263
91264 -#ifdef CONFIG_PRINTK
91265 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
91266 void __user *buffer, size_t *lenp, loff_t *ppos)
91267 {
91268 @@ -2085,7 +2144,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
91269
91270 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
91271 }
91272 -#endif
91273
91274 struct do_proc_dointvec_minmax_conv_param {
91275 int *min;
91276 @@ -2632,6 +2690,12 @@ int proc_dostring(struct ctl_table *table, int write,
91277 return -ENOSYS;
91278 }
91279
91280 +int proc_dostring_modpriv(struct ctl_table *table, int write,
91281 + void __user *buffer, size_t *lenp, loff_t *ppos)
91282 +{
91283 + return -ENOSYS;
91284 +}
91285 +
91286 int proc_dointvec(struct ctl_table *table, int write,
91287 void __user *buffer, size_t *lenp, loff_t *ppos)
91288 {
91289 @@ -2688,5 +2752,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
91290 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
91291 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
91292 EXPORT_SYMBOL(proc_dostring);
91293 +EXPORT_SYMBOL(proc_dostring_modpriv);
91294 EXPORT_SYMBOL(proc_doulongvec_minmax);
91295 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
91296 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
91297 index 13d2f7c..c93d0b0 100644
91298 --- a/kernel/taskstats.c
91299 +++ b/kernel/taskstats.c
91300 @@ -28,9 +28,12 @@
91301 #include <linux/fs.h>
91302 #include <linux/file.h>
91303 #include <linux/pid_namespace.h>
91304 +#include <linux/grsecurity.h>
91305 #include <net/genetlink.h>
91306 #include <linux/atomic.h>
91307
91308 +extern int gr_is_taskstats_denied(int pid);
91309 +
91310 /*
91311 * Maximum length of a cpumask that can be specified in
91312 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
91313 @@ -576,6 +579,9 @@ err:
91314
91315 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
91316 {
91317 + if (gr_is_taskstats_denied(current->pid))
91318 + return -EACCES;
91319 +
91320 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
91321 return cmd_attr_register_cpumask(info);
91322 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
91323 diff --git a/kernel/time.c b/kernel/time.c
91324 index 7c7964c..2a0d412 100644
91325 --- a/kernel/time.c
91326 +++ b/kernel/time.c
91327 @@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
91328 return error;
91329
91330 if (tz) {
91331 + /* we log in do_settimeofday called below, so don't log twice
91332 + */
91333 + if (!tv)
91334 + gr_log_timechange();
91335 +
91336 sys_tz = *tz;
91337 update_vsyscall_tz();
91338 if (firsttime) {
91339 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
91340 index fe75444..190c528 100644
91341 --- a/kernel/time/alarmtimer.c
91342 +++ b/kernel/time/alarmtimer.c
91343 @@ -811,7 +811,7 @@ static int __init alarmtimer_init(void)
91344 struct platform_device *pdev;
91345 int error = 0;
91346 int i;
91347 - struct k_clock alarm_clock = {
91348 + static struct k_clock alarm_clock = {
91349 .clock_getres = alarm_clock_getres,
91350 .clock_get = alarm_clock_get,
91351 .timer_create = alarm_timer_create,
91352 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
91353 index f7df8ea..0810193 100644
91354 --- a/kernel/time/timekeeping.c
91355 +++ b/kernel/time/timekeeping.c
91356 @@ -15,6 +15,7 @@
91357 #include <linux/init.h>
91358 #include <linux/mm.h>
91359 #include <linux/sched.h>
91360 +#include <linux/grsecurity.h>
91361 #include <linux/syscore_ops.h>
91362 #include <linux/clocksource.h>
91363 #include <linux/jiffies.h>
91364 @@ -502,6 +503,8 @@ int do_settimeofday(const struct timespec *tv)
91365 if (!timespec_valid_strict(tv))
91366 return -EINVAL;
91367
91368 + gr_log_timechange();
91369 +
91370 raw_spin_lock_irqsave(&timekeeper_lock, flags);
91371 write_seqcount_begin(&timekeeper_seq);
91372
91373 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
91374 index 61ed862..3b52c65 100644
91375 --- a/kernel/time/timer_list.c
91376 +++ b/kernel/time/timer_list.c
91377 @@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
91378
91379 static void print_name_offset(struct seq_file *m, void *sym)
91380 {
91381 +#ifdef CONFIG_GRKERNSEC_HIDESYM
91382 + SEQ_printf(m, "<%p>", NULL);
91383 +#else
91384 char symname[KSYM_NAME_LEN];
91385
91386 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
91387 SEQ_printf(m, "<%pK>", sym);
91388 else
91389 SEQ_printf(m, "%s", symname);
91390 +#endif
91391 }
91392
91393 static void
91394 @@ -119,7 +123,11 @@ next_one:
91395 static void
91396 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
91397 {
91398 +#ifdef CONFIG_GRKERNSEC_HIDESYM
91399 + SEQ_printf(m, " .base: %p\n", NULL);
91400 +#else
91401 SEQ_printf(m, " .base: %pK\n", base);
91402 +#endif
91403 SEQ_printf(m, " .index: %d\n",
91404 base->index);
91405 SEQ_printf(m, " .resolution: %Lu nsecs\n",
91406 @@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
91407 {
91408 struct proc_dir_entry *pe;
91409
91410 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
91411 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
91412 +#else
91413 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
91414 +#endif
91415 if (!pe)
91416 return -ENOMEM;
91417 return 0;
91418 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
91419 index 1fb08f2..ca4bb1e 100644
91420 --- a/kernel/time/timer_stats.c
91421 +++ b/kernel/time/timer_stats.c
91422 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
91423 static unsigned long nr_entries;
91424 static struct entry entries[MAX_ENTRIES];
91425
91426 -static atomic_t overflow_count;
91427 +static atomic_unchecked_t overflow_count;
91428
91429 /*
91430 * The entries are in a hash-table, for fast lookup:
91431 @@ -140,7 +140,7 @@ static void reset_entries(void)
91432 nr_entries = 0;
91433 memset(entries, 0, sizeof(entries));
91434 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
91435 - atomic_set(&overflow_count, 0);
91436 + atomic_set_unchecked(&overflow_count, 0);
91437 }
91438
91439 static struct entry *alloc_entry(void)
91440 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
91441 if (likely(entry))
91442 entry->count++;
91443 else
91444 - atomic_inc(&overflow_count);
91445 + atomic_inc_unchecked(&overflow_count);
91446
91447 out_unlock:
91448 raw_spin_unlock_irqrestore(lock, flags);
91449 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
91450
91451 static void print_name_offset(struct seq_file *m, unsigned long addr)
91452 {
91453 +#ifdef CONFIG_GRKERNSEC_HIDESYM
91454 + seq_printf(m, "<%p>", NULL);
91455 +#else
91456 char symname[KSYM_NAME_LEN];
91457
91458 if (lookup_symbol_name(addr, symname) < 0)
91459 - seq_printf(m, "<%p>", (void *)addr);
91460 + seq_printf(m, "<%pK>", (void *)addr);
91461 else
91462 seq_printf(m, "%s", symname);
91463 +#endif
91464 }
91465
91466 static int tstats_show(struct seq_file *m, void *v)
91467 @@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
91468
91469 seq_puts(m, "Timer Stats Version: v0.3\n");
91470 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
91471 - if (atomic_read(&overflow_count))
91472 - seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
91473 + if (atomic_read_unchecked(&overflow_count))
91474 + seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
91475 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
91476
91477 for (i = 0; i < nr_entries; i++) {
91478 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
91479 {
91480 struct proc_dir_entry *pe;
91481
91482 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
91483 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
91484 +#else
91485 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
91486 +#endif
91487 if (!pe)
91488 return -ENOMEM;
91489 return 0;
91490 diff --git a/kernel/timer.c b/kernel/timer.c
91491 index 3bb01a3..0e7760e 100644
91492 --- a/kernel/timer.c
91493 +++ b/kernel/timer.c
91494 @@ -1393,7 +1393,7 @@ void update_process_times(int user_tick)
91495 /*
91496 * This function runs timers and the timer-tq in bottom half context.
91497 */
91498 -static void run_timer_softirq(struct softirq_action *h)
91499 +static __latent_entropy void run_timer_softirq(void)
91500 {
91501 struct tvec_base *base = __this_cpu_read(tvec_bases);
91502
91503 @@ -1456,7 +1456,7 @@ static void process_timeout(unsigned long __data)
91504 *
91505 * In all cases the return value is guaranteed to be non-negative.
91506 */
91507 -signed long __sched schedule_timeout(signed long timeout)
91508 +signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
91509 {
91510 struct timer_list timer;
91511 unsigned long expire;
91512 diff --git a/kernel/torture.c b/kernel/torture.c
91513 index acc9afc..4f9eb49 100644
91514 --- a/kernel/torture.c
91515 +++ b/kernel/torture.c
91516 @@ -489,7 +489,7 @@ static int torture_shutdown_notify(struct notifier_block *unused1,
91517 mutex_lock(&fullstop_mutex);
91518 if (ACCESS_ONCE(fullstop) == FULLSTOP_DONTSTOP) {
91519 VERBOSE_TOROUT_STRING("Unscheduled system shutdown detected");
91520 - ACCESS_ONCE(fullstop) = FULLSTOP_SHUTDOWN;
91521 + ACCESS_ONCE_RW(fullstop) = FULLSTOP_SHUTDOWN;
91522 } else {
91523 pr_warn("Concurrent rmmod and shutdown illegal!\n");
91524 }
91525 @@ -551,11 +551,11 @@ static int torture_stutter(void *arg)
91526 do {
91527 if (!torture_must_stop()) {
91528 schedule_timeout_interruptible(stutter);
91529 - ACCESS_ONCE(stutter_pause_test) = 1;
91530 + ACCESS_ONCE_RW(stutter_pause_test) = 1;
91531 }
91532 if (!torture_must_stop())
91533 schedule_timeout_interruptible(stutter);
91534 - ACCESS_ONCE(stutter_pause_test) = 0;
91535 + ACCESS_ONCE_RW(stutter_pause_test) = 0;
91536 torture_shutdown_absorb("torture_stutter");
91537 } while (!torture_must_stop());
91538 torture_kthread_stopping("torture_stutter");
91539 @@ -636,7 +636,7 @@ bool torture_cleanup(void)
91540 schedule_timeout_uninterruptible(10);
91541 return true;
91542 }
91543 - ACCESS_ONCE(fullstop) = FULLSTOP_RMMOD;
91544 + ACCESS_ONCE_RW(fullstop) = FULLSTOP_RMMOD;
91545 mutex_unlock(&fullstop_mutex);
91546 torture_shutdown_cleanup();
91547 torture_shuffle_cleanup();
91548 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
91549 index c1bd4ad..4b861dc 100644
91550 --- a/kernel/trace/blktrace.c
91551 +++ b/kernel/trace/blktrace.c
91552 @@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
91553 struct blk_trace *bt = filp->private_data;
91554 char buf[16];
91555
91556 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
91557 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
91558
91559 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
91560 }
91561 @@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
91562 return 1;
91563
91564 bt = buf->chan->private_data;
91565 - atomic_inc(&bt->dropped);
91566 + atomic_inc_unchecked(&bt->dropped);
91567 return 0;
91568 }
91569
91570 @@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
91571
91572 bt->dir = dir;
91573 bt->dev = dev;
91574 - atomic_set(&bt->dropped, 0);
91575 + atomic_set_unchecked(&bt->dropped, 0);
91576 INIT_LIST_HEAD(&bt->running_list);
91577
91578 ret = -EIO;
91579 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
91580 index 5aeac53..863ed29 100644
91581 --- a/kernel/trace/ftrace.c
91582 +++ b/kernel/trace/ftrace.c
91583 @@ -1960,12 +1960,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
91584 if (unlikely(ftrace_disabled))
91585 return 0;
91586
91587 + ret = ftrace_arch_code_modify_prepare();
91588 + FTRACE_WARN_ON(ret);
91589 + if (ret)
91590 + return 0;
91591 +
91592 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
91593 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
91594 if (ret) {
91595 ftrace_bug(ret, ip);
91596 - return 0;
91597 }
91598 - return 1;
91599 + return ret ? 0 : 1;
91600 }
91601
91602 /*
91603 @@ -4195,8 +4200,10 @@ static int ftrace_process_locs(struct module *mod,
91604 if (!count)
91605 return 0;
91606
91607 + pax_open_kernel();
91608 sort(start, count, sizeof(*start),
91609 ftrace_cmp_ips, ftrace_swap_ips);
91610 + pax_close_kernel();
91611
91612 start_pg = ftrace_allocate_pages(count);
91613 if (!start_pg)
91614 @@ -4908,8 +4915,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
91615 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
91616
91617 static int ftrace_graph_active;
91618 -static struct notifier_block ftrace_suspend_notifier;
91619 -
91620 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
91621 {
91622 return 0;
91623 @@ -5085,6 +5090,10 @@ static void update_function_graph_func(void)
91624 ftrace_graph_entry = ftrace_graph_entry_test;
91625 }
91626
91627 +static struct notifier_block ftrace_suspend_notifier = {
91628 + .notifier_call = ftrace_suspend_notifier_call
91629 +};
91630 +
91631 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
91632 trace_func_graph_ent_t entryfunc)
91633 {
91634 @@ -5098,7 +5107,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
91635 goto out;
91636 }
91637
91638 - ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
91639 register_pm_notifier(&ftrace_suspend_notifier);
91640
91641 ftrace_graph_active++;
91642 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
91643 index ff70271..e1e8cf1 100644
91644 --- a/kernel/trace/ring_buffer.c
91645 +++ b/kernel/trace/ring_buffer.c
91646 @@ -352,9 +352,9 @@ struct buffer_data_page {
91647 */
91648 struct buffer_page {
91649 struct list_head list; /* list of buffer pages */
91650 - local_t write; /* index for next write */
91651 + local_unchecked_t write; /* index for next write */
91652 unsigned read; /* index for next read */
91653 - local_t entries; /* entries on this page */
91654 + local_unchecked_t entries; /* entries on this page */
91655 unsigned long real_end; /* real end of data */
91656 struct buffer_data_page *page; /* Actual data page */
91657 };
91658 @@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
91659 unsigned long last_overrun;
91660 local_t entries_bytes;
91661 local_t entries;
91662 - local_t overrun;
91663 - local_t commit_overrun;
91664 + local_unchecked_t overrun;
91665 + local_unchecked_t commit_overrun;
91666 local_t dropped_events;
91667 local_t committing;
91668 local_t commits;
91669 @@ -991,8 +991,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
91670 *
91671 * We add a counter to the write field to denote this.
91672 */
91673 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
91674 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
91675 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
91676 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
91677
91678 /*
91679 * Just make sure we have seen our old_write and synchronize
91680 @@ -1020,8 +1020,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
91681 * cmpxchg to only update if an interrupt did not already
91682 * do it for us. If the cmpxchg fails, we don't care.
91683 */
91684 - (void)local_cmpxchg(&next_page->write, old_write, val);
91685 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
91686 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
91687 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
91688
91689 /*
91690 * No need to worry about races with clearing out the commit.
91691 @@ -1388,12 +1388,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
91692
91693 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
91694 {
91695 - return local_read(&bpage->entries) & RB_WRITE_MASK;
91696 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
91697 }
91698
91699 static inline unsigned long rb_page_write(struct buffer_page *bpage)
91700 {
91701 - return local_read(&bpage->write) & RB_WRITE_MASK;
91702 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
91703 }
91704
91705 static int
91706 @@ -1488,7 +1488,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
91707 * bytes consumed in ring buffer from here.
91708 * Increment overrun to account for the lost events.
91709 */
91710 - local_add(page_entries, &cpu_buffer->overrun);
91711 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
91712 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
91713 }
91714
91715 @@ -2066,7 +2066,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
91716 * it is our responsibility to update
91717 * the counters.
91718 */
91719 - local_add(entries, &cpu_buffer->overrun);
91720 + local_add_unchecked(entries, &cpu_buffer->overrun);
91721 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
91722
91723 /*
91724 @@ -2216,7 +2216,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
91725 if (tail == BUF_PAGE_SIZE)
91726 tail_page->real_end = 0;
91727
91728 - local_sub(length, &tail_page->write);
91729 + local_sub_unchecked(length, &tail_page->write);
91730 return;
91731 }
91732
91733 @@ -2251,7 +2251,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
91734 rb_event_set_padding(event);
91735
91736 /* Set the write back to the previous setting */
91737 - local_sub(length, &tail_page->write);
91738 + local_sub_unchecked(length, &tail_page->write);
91739 return;
91740 }
91741
91742 @@ -2263,7 +2263,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
91743
91744 /* Set write to end of buffer */
91745 length = (tail + length) - BUF_PAGE_SIZE;
91746 - local_sub(length, &tail_page->write);
91747 + local_sub_unchecked(length, &tail_page->write);
91748 }
91749
91750 /*
91751 @@ -2289,7 +2289,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
91752 * about it.
91753 */
91754 if (unlikely(next_page == commit_page)) {
91755 - local_inc(&cpu_buffer->commit_overrun);
91756 + local_inc_unchecked(&cpu_buffer->commit_overrun);
91757 goto out_reset;
91758 }
91759
91760 @@ -2345,7 +2345,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
91761 cpu_buffer->tail_page) &&
91762 (cpu_buffer->commit_page ==
91763 cpu_buffer->reader_page))) {
91764 - local_inc(&cpu_buffer->commit_overrun);
91765 + local_inc_unchecked(&cpu_buffer->commit_overrun);
91766 goto out_reset;
91767 }
91768 }
91769 @@ -2393,7 +2393,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
91770 length += RB_LEN_TIME_EXTEND;
91771
91772 tail_page = cpu_buffer->tail_page;
91773 - write = local_add_return(length, &tail_page->write);
91774 + write = local_add_return_unchecked(length, &tail_page->write);
91775
91776 /* set write to only the index of the write */
91777 write &= RB_WRITE_MASK;
91778 @@ -2417,7 +2417,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
91779 kmemcheck_annotate_bitfield(event, bitfield);
91780 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
91781
91782 - local_inc(&tail_page->entries);
91783 + local_inc_unchecked(&tail_page->entries);
91784
91785 /*
91786 * If this is the first commit on the page, then update
91787 @@ -2450,7 +2450,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
91788
91789 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
91790 unsigned long write_mask =
91791 - local_read(&bpage->write) & ~RB_WRITE_MASK;
91792 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
91793 unsigned long event_length = rb_event_length(event);
91794 /*
91795 * This is on the tail page. It is possible that
91796 @@ -2460,7 +2460,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
91797 */
91798 old_index += write_mask;
91799 new_index += write_mask;
91800 - index = local_cmpxchg(&bpage->write, old_index, new_index);
91801 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
91802 if (index == old_index) {
91803 /* update counters */
91804 local_sub(event_length, &cpu_buffer->entries_bytes);
91805 @@ -2852,7 +2852,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
91806
91807 /* Do the likely case first */
91808 if (likely(bpage->page == (void *)addr)) {
91809 - local_dec(&bpage->entries);
91810 + local_dec_unchecked(&bpage->entries);
91811 return;
91812 }
91813
91814 @@ -2864,7 +2864,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
91815 start = bpage;
91816 do {
91817 if (bpage->page == (void *)addr) {
91818 - local_dec(&bpage->entries);
91819 + local_dec_unchecked(&bpage->entries);
91820 return;
91821 }
91822 rb_inc_page(cpu_buffer, &bpage);
91823 @@ -3148,7 +3148,7 @@ static inline unsigned long
91824 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
91825 {
91826 return local_read(&cpu_buffer->entries) -
91827 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
91828 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
91829 }
91830
91831 /**
91832 @@ -3237,7 +3237,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
91833 return 0;
91834
91835 cpu_buffer = buffer->buffers[cpu];
91836 - ret = local_read(&cpu_buffer->overrun);
91837 + ret = local_read_unchecked(&cpu_buffer->overrun);
91838
91839 return ret;
91840 }
91841 @@ -3260,7 +3260,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
91842 return 0;
91843
91844 cpu_buffer = buffer->buffers[cpu];
91845 - ret = local_read(&cpu_buffer->commit_overrun);
91846 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
91847
91848 return ret;
91849 }
91850 @@ -3345,7 +3345,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
91851 /* if you care about this being correct, lock the buffer */
91852 for_each_buffer_cpu(buffer, cpu) {
91853 cpu_buffer = buffer->buffers[cpu];
91854 - overruns += local_read(&cpu_buffer->overrun);
91855 + overruns += local_read_unchecked(&cpu_buffer->overrun);
91856 }
91857
91858 return overruns;
91859 @@ -3521,8 +3521,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
91860 /*
91861 * Reset the reader page to size zero.
91862 */
91863 - local_set(&cpu_buffer->reader_page->write, 0);
91864 - local_set(&cpu_buffer->reader_page->entries, 0);
91865 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
91866 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
91867 local_set(&cpu_buffer->reader_page->page->commit, 0);
91868 cpu_buffer->reader_page->real_end = 0;
91869
91870 @@ -3556,7 +3556,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
91871 * want to compare with the last_overrun.
91872 */
91873 smp_mb();
91874 - overwrite = local_read(&(cpu_buffer->overrun));
91875 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
91876
91877 /*
91878 * Here's the tricky part.
91879 @@ -4126,8 +4126,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
91880
91881 cpu_buffer->head_page
91882 = list_entry(cpu_buffer->pages, struct buffer_page, list);
91883 - local_set(&cpu_buffer->head_page->write, 0);
91884 - local_set(&cpu_buffer->head_page->entries, 0);
91885 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
91886 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
91887 local_set(&cpu_buffer->head_page->page->commit, 0);
91888
91889 cpu_buffer->head_page->read = 0;
91890 @@ -4137,14 +4137,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
91891
91892 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
91893 INIT_LIST_HEAD(&cpu_buffer->new_pages);
91894 - local_set(&cpu_buffer->reader_page->write, 0);
91895 - local_set(&cpu_buffer->reader_page->entries, 0);
91896 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
91897 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
91898 local_set(&cpu_buffer->reader_page->page->commit, 0);
91899 cpu_buffer->reader_page->read = 0;
91900
91901 local_set(&cpu_buffer->entries_bytes, 0);
91902 - local_set(&cpu_buffer->overrun, 0);
91903 - local_set(&cpu_buffer->commit_overrun, 0);
91904 + local_set_unchecked(&cpu_buffer->overrun, 0);
91905 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
91906 local_set(&cpu_buffer->dropped_events, 0);
91907 local_set(&cpu_buffer->entries, 0);
91908 local_set(&cpu_buffer->committing, 0);
91909 @@ -4549,8 +4549,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
91910 rb_init_page(bpage);
91911 bpage = reader->page;
91912 reader->page = *data_page;
91913 - local_set(&reader->write, 0);
91914 - local_set(&reader->entries, 0);
91915 + local_set_unchecked(&reader->write, 0);
91916 + local_set_unchecked(&reader->entries, 0);
91917 reader->read = 0;
91918 *data_page = bpage;
91919
91920 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
91921 index e1baa92f..7b2e345 100644
91922 --- a/kernel/trace/trace.c
91923 +++ b/kernel/trace/trace.c
91924 @@ -3461,7 +3461,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
91925 return 0;
91926 }
91927
91928 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
91929 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
91930 {
91931 /* do nothing if flag is already set */
91932 if (!!(trace_flags & mask) == !!enabled)
91933 diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
91934 index 99676cd..670b9e8 100644
91935 --- a/kernel/trace/trace.h
91936 +++ b/kernel/trace/trace.h
91937 @@ -1264,7 +1264,7 @@ extern const char *__stop___tracepoint_str[];
91938 void trace_printk_init_buffers(void);
91939 void trace_printk_start_comm(void);
91940 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
91941 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
91942 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
91943
91944 /*
91945 * Normal trace_printk() and friends allocates special buffers
91946 diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
91947 index 57b67b1..66082a9 100644
91948 --- a/kernel/trace/trace_clock.c
91949 +++ b/kernel/trace/trace_clock.c
91950 @@ -124,7 +124,7 @@ u64 notrace trace_clock_global(void)
91951 return now;
91952 }
91953
91954 -static atomic64_t trace_counter;
91955 +static atomic64_unchecked_t trace_counter;
91956
91957 /*
91958 * trace_clock_counter(): simply an atomic counter.
91959 @@ -133,5 +133,5 @@ static atomic64_t trace_counter;
91960 */
91961 u64 notrace trace_clock_counter(void)
91962 {
91963 - return atomic64_add_return(1, &trace_counter);
91964 + return atomic64_inc_return_unchecked(&trace_counter);
91965 }
91966 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
91967 index aec1dac..6ca72ee 100644
91968 --- a/kernel/trace/trace_events.c
91969 +++ b/kernel/trace/trace_events.c
91970 @@ -1719,7 +1719,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
91971 return 0;
91972 }
91973
91974 -struct ftrace_module_file_ops;
91975 static void __add_event_to_tracers(struct ftrace_event_call *call);
91976
91977 /* Add an additional event_call dynamically */
91978 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
91979 index 0abd9b8..6a663a2 100644
91980 --- a/kernel/trace/trace_mmiotrace.c
91981 +++ b/kernel/trace/trace_mmiotrace.c
91982 @@ -24,7 +24,7 @@ struct header_iter {
91983 static struct trace_array *mmio_trace_array;
91984 static bool overrun_detected;
91985 static unsigned long prev_overruns;
91986 -static atomic_t dropped_count;
91987 +static atomic_unchecked_t dropped_count;
91988
91989 static void mmio_reset_data(struct trace_array *tr)
91990 {
91991 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
91992
91993 static unsigned long count_overruns(struct trace_iterator *iter)
91994 {
91995 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
91996 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
91997 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
91998
91999 if (over > prev_overruns)
92000 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
92001 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
92002 sizeof(*entry), 0, pc);
92003 if (!event) {
92004 - atomic_inc(&dropped_count);
92005 + atomic_inc_unchecked(&dropped_count);
92006 return;
92007 }
92008 entry = ring_buffer_event_data(event);
92009 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
92010 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
92011 sizeof(*entry), 0, pc);
92012 if (!event) {
92013 - atomic_inc(&dropped_count);
92014 + atomic_inc_unchecked(&dropped_count);
92015 return;
92016 }
92017 entry = ring_buffer_event_data(event);
92018 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
92019 index a436de1..f64dde2 100644
92020 --- a/kernel/trace/trace_output.c
92021 +++ b/kernel/trace/trace_output.c
92022 @@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
92023
92024 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
92025 if (!IS_ERR(p)) {
92026 - p = mangle_path(s->buffer + s->len, p, "\n");
92027 + p = mangle_path(s->buffer + s->len, p, "\n\\");
92028 if (p) {
92029 s->len = p - s->buffer;
92030 return 1;
92031 @@ -939,14 +939,16 @@ int register_ftrace_event(struct trace_event *event)
92032 goto out;
92033 }
92034
92035 + pax_open_kernel();
92036 if (event->funcs->trace == NULL)
92037 - event->funcs->trace = trace_nop_print;
92038 + *(void **)&event->funcs->trace = trace_nop_print;
92039 if (event->funcs->raw == NULL)
92040 - event->funcs->raw = trace_nop_print;
92041 + *(void **)&event->funcs->raw = trace_nop_print;
92042 if (event->funcs->hex == NULL)
92043 - event->funcs->hex = trace_nop_print;
92044 + *(void **)&event->funcs->hex = trace_nop_print;
92045 if (event->funcs->binary == NULL)
92046 - event->funcs->binary = trace_nop_print;
92047 + *(void **)&event->funcs->binary = trace_nop_print;
92048 + pax_close_kernel();
92049
92050 key = event->type & (EVENT_HASHSIZE - 1);
92051
92052 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
92053 index 21b320e..40607bc 100644
92054 --- a/kernel/trace/trace_stack.c
92055 +++ b/kernel/trace/trace_stack.c
92056 @@ -69,7 +69,7 @@ check_stack(unsigned long ip, unsigned long *stack)
92057 return;
92058
92059 /* we do not handle interrupt stacks yet */
92060 - if (!object_is_on_stack(stack))
92061 + if (!object_starts_on_stack(stack))
92062 return;
92063
92064 local_irq_save(flags);
92065 diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
92066 index bf71b4b..04dee68 100644
92067 --- a/kernel/user_namespace.c
92068 +++ b/kernel/user_namespace.c
92069 @@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
92070 !kgid_has_mapping(parent_ns, group))
92071 return -EPERM;
92072
92073 +#ifdef CONFIG_GRKERNSEC
92074 + /*
92075 + * This doesn't really inspire confidence:
92076 + * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
92077 + * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
92078 + * Increases kernel attack surface in areas developers
92079 + * previously cared little about ("low importance due
92080 + * to requiring "root" capability")
92081 + * To be removed when this code receives *proper* review
92082 + */
92083 + if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
92084 + !capable(CAP_SETGID))
92085 + return -EPERM;
92086 +#endif
92087 +
92088 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
92089 if (!ns)
92090 return -ENOMEM;
92091 @@ -865,7 +880,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
92092 if (atomic_read(&current->mm->mm_users) > 1)
92093 return -EINVAL;
92094
92095 - if (current->fs->users != 1)
92096 + if (atomic_read(&current->fs->users) != 1)
92097 return -EINVAL;
92098
92099 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
92100 diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
92101 index 4f69f9a..7c6f8f8 100644
92102 --- a/kernel/utsname_sysctl.c
92103 +++ b/kernel/utsname_sysctl.c
92104 @@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
92105 static int proc_do_uts_string(ctl_table *table, int write,
92106 void __user *buffer, size_t *lenp, loff_t *ppos)
92107 {
92108 - struct ctl_table uts_table;
92109 + ctl_table_no_const uts_table;
92110 int r;
92111 memcpy(&uts_table, table, sizeof(uts_table));
92112 uts_table.data = get_uts(table, write);
92113 diff --git a/kernel/watchdog.c b/kernel/watchdog.c
92114 index 30e4822..dd2b854 100644
92115 --- a/kernel/watchdog.c
92116 +++ b/kernel/watchdog.c
92117 @@ -479,7 +479,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
92118 static void watchdog_nmi_disable(unsigned int cpu) { return; }
92119 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
92120
92121 -static struct smp_hotplug_thread watchdog_threads = {
92122 +static struct smp_hotplug_thread watchdog_threads __read_only = {
92123 .store = &softlockup_watchdog,
92124 .thread_should_run = watchdog_should_run,
92125 .thread_fn = watchdog,
92126 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
92127 index 7ba5897..c8ed1f2 100644
92128 --- a/kernel/workqueue.c
92129 +++ b/kernel/workqueue.c
92130 @@ -4710,7 +4710,7 @@ static void rebind_workers(struct worker_pool *pool)
92131 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
92132 worker_flags |= WORKER_REBOUND;
92133 worker_flags &= ~WORKER_UNBOUND;
92134 - ACCESS_ONCE(worker->flags) = worker_flags;
92135 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
92136 }
92137
92138 spin_unlock_irq(&pool->lock);
92139 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
92140 index 819ac51..1c8a65e 100644
92141 --- a/lib/Kconfig.debug
92142 +++ b/lib/Kconfig.debug
92143 @@ -853,7 +853,7 @@ config DEBUG_MUTEXES
92144
92145 config DEBUG_WW_MUTEX_SLOWPATH
92146 bool "Wait/wound mutex debugging: Slowpath testing"
92147 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
92148 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
92149 select DEBUG_LOCK_ALLOC
92150 select DEBUG_SPINLOCK
92151 select DEBUG_MUTEXES
92152 @@ -866,7 +866,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
92153
92154 config DEBUG_LOCK_ALLOC
92155 bool "Lock debugging: detect incorrect freeing of live locks"
92156 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
92157 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
92158 select DEBUG_SPINLOCK
92159 select DEBUG_MUTEXES
92160 select LOCKDEP
92161 @@ -880,7 +880,7 @@ config DEBUG_LOCK_ALLOC
92162
92163 config PROVE_LOCKING
92164 bool "Lock debugging: prove locking correctness"
92165 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
92166 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
92167 select LOCKDEP
92168 select DEBUG_SPINLOCK
92169 select DEBUG_MUTEXES
92170 @@ -931,7 +931,7 @@ config LOCKDEP
92171
92172 config LOCK_STAT
92173 bool "Lock usage statistics"
92174 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
92175 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
92176 select LOCKDEP
92177 select DEBUG_SPINLOCK
92178 select DEBUG_MUTEXES
92179 @@ -1403,6 +1403,7 @@ config LATENCYTOP
92180 depends on DEBUG_KERNEL
92181 depends on STACKTRACE_SUPPORT
92182 depends on PROC_FS
92183 + depends on !GRKERNSEC_HIDESYM
92184 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
92185 select KALLSYMS
92186 select KALLSYMS_ALL
92187 @@ -1419,7 +1420,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
92188 config DEBUG_STRICT_USER_COPY_CHECKS
92189 bool "Strict user copy size checks"
92190 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
92191 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
92192 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
92193 help
92194 Enabling this option turns a certain set of sanity checks for user
92195 copy operations into compile time failures.
92196 @@ -1538,7 +1539,7 @@ endmenu # runtime tests
92197
92198 config PROVIDE_OHCI1394_DMA_INIT
92199 bool "Remote debugging over FireWire early on boot"
92200 - depends on PCI && X86
92201 + depends on PCI && X86 && !GRKERNSEC
92202 help
92203 If you want to debug problems which hang or crash the kernel early
92204 on boot and the crashing machine has a FireWire port, you can use
92205 diff --git a/lib/Makefile b/lib/Makefile
92206 index 0cd7b68..e149e37 100644
92207 --- a/lib/Makefile
92208 +++ b/lib/Makefile
92209 @@ -52,7 +52,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
92210 obj-$(CONFIG_BTREE) += btree.o
92211 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
92212 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
92213 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
92214 +obj-y += list_debug.o
92215 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
92216
92217 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
92218 diff --git a/lib/average.c b/lib/average.c
92219 index 114d1be..ab0350c 100644
92220 --- a/lib/average.c
92221 +++ b/lib/average.c
92222 @@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
92223 {
92224 unsigned long internal = ACCESS_ONCE(avg->internal);
92225
92226 - ACCESS_ONCE(avg->internal) = internal ?
92227 + ACCESS_ONCE_RW(avg->internal) = internal ?
92228 (((internal << avg->weight) - internal) +
92229 (val << avg->factor)) >> avg->weight :
92230 (val << avg->factor);
92231 diff --git a/lib/bitmap.c b/lib/bitmap.c
92232 index 06f7e4f..f3cf2b0 100644
92233 --- a/lib/bitmap.c
92234 +++ b/lib/bitmap.c
92235 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
92236 {
92237 int c, old_c, totaldigits, ndigits, nchunks, nbits;
92238 u32 chunk;
92239 - const char __user __force *ubuf = (const char __user __force *)buf;
92240 + const char __user *ubuf = (const char __force_user *)buf;
92241
92242 bitmap_zero(maskp, nmaskbits);
92243
92244 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
92245 {
92246 if (!access_ok(VERIFY_READ, ubuf, ulen))
92247 return -EFAULT;
92248 - return __bitmap_parse((const char __force *)ubuf,
92249 + return __bitmap_parse((const char __force_kernel *)ubuf,
92250 ulen, 1, maskp, nmaskbits);
92251
92252 }
92253 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
92254 {
92255 unsigned a, b;
92256 int c, old_c, totaldigits;
92257 - const char __user __force *ubuf = (const char __user __force *)buf;
92258 + const char __user *ubuf = (const char __force_user *)buf;
92259 int exp_digit, in_range;
92260
92261 totaldigits = c = 0;
92262 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
92263 {
92264 if (!access_ok(VERIFY_READ, ubuf, ulen))
92265 return -EFAULT;
92266 - return __bitmap_parselist((const char __force *)ubuf,
92267 + return __bitmap_parselist((const char __force_kernel *)ubuf,
92268 ulen, 1, maskp, nmaskbits);
92269 }
92270 EXPORT_SYMBOL(bitmap_parselist_user);
92271 diff --git a/lib/bug.c b/lib/bug.c
92272 index 1686034..a9c00c8 100644
92273 --- a/lib/bug.c
92274 +++ b/lib/bug.c
92275 @@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
92276 return BUG_TRAP_TYPE_NONE;
92277
92278 bug = find_bug(bugaddr);
92279 + if (!bug)
92280 + return BUG_TRAP_TYPE_NONE;
92281
92282 file = NULL;
92283 line = 0;
92284 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
92285 index e0731c3..ad66444 100644
92286 --- a/lib/debugobjects.c
92287 +++ b/lib/debugobjects.c
92288 @@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
92289 if (limit > 4)
92290 return;
92291
92292 - is_on_stack = object_is_on_stack(addr);
92293 + is_on_stack = object_starts_on_stack(addr);
92294 if (is_on_stack == onstack)
92295 return;
92296
92297 diff --git a/lib/div64.c b/lib/div64.c
92298 index 4382ad7..08aa558 100644
92299 --- a/lib/div64.c
92300 +++ b/lib/div64.c
92301 @@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
92302 EXPORT_SYMBOL(__div64_32);
92303
92304 #ifndef div_s64_rem
92305 -s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
92306 +s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
92307 {
92308 u64 quotient;
92309
92310 @@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
92311 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
92312 */
92313 #ifndef div64_u64
92314 -u64 div64_u64(u64 dividend, u64 divisor)
92315 +u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
92316 {
92317 u32 high = divisor >> 32;
92318 u64 quot;
92319 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
92320 index 98f2d7e..899da5c 100644
92321 --- a/lib/dma-debug.c
92322 +++ b/lib/dma-debug.c
92323 @@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
92324
92325 void dma_debug_add_bus(struct bus_type *bus)
92326 {
92327 - struct notifier_block *nb;
92328 + notifier_block_no_const *nb;
92329
92330 if (global_disable)
92331 return;
92332 @@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
92333
92334 static void check_for_stack(struct device *dev, void *addr)
92335 {
92336 - if (object_is_on_stack(addr))
92337 + if (object_starts_on_stack(addr))
92338 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
92339 "stack [addr=%p]\n", addr);
92340 }
92341 diff --git a/lib/hash.c b/lib/hash.c
92342 index fea973f..386626f 100644
92343 --- a/lib/hash.c
92344 +++ b/lib/hash.c
92345 @@ -14,7 +14,7 @@
92346 #include <linux/hash.h>
92347 #include <linux/cache.h>
92348
92349 -static struct fast_hash_ops arch_hash_ops __read_mostly = {
92350 +static struct fast_hash_ops arch_hash_ops __read_only = {
92351 .hash = jhash,
92352 .hash2 = jhash2,
92353 };
92354 diff --git a/lib/inflate.c b/lib/inflate.c
92355 index 013a761..c28f3fc 100644
92356 --- a/lib/inflate.c
92357 +++ b/lib/inflate.c
92358 @@ -269,7 +269,7 @@ static void free(void *where)
92359 malloc_ptr = free_mem_ptr;
92360 }
92361 #else
92362 -#define malloc(a) kmalloc(a, GFP_KERNEL)
92363 +#define malloc(a) kmalloc((a), GFP_KERNEL)
92364 #define free(a) kfree(a)
92365 #endif
92366
92367 diff --git a/lib/ioremap.c b/lib/ioremap.c
92368 index 0c9216c..863bd89 100644
92369 --- a/lib/ioremap.c
92370 +++ b/lib/ioremap.c
92371 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
92372 unsigned long next;
92373
92374 phys_addr -= addr;
92375 - pmd = pmd_alloc(&init_mm, pud, addr);
92376 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
92377 if (!pmd)
92378 return -ENOMEM;
92379 do {
92380 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
92381 unsigned long next;
92382
92383 phys_addr -= addr;
92384 - pud = pud_alloc(&init_mm, pgd, addr);
92385 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
92386 if (!pud)
92387 return -ENOMEM;
92388 do {
92389 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
92390 index bd2bea9..6b3c95e 100644
92391 --- a/lib/is_single_threaded.c
92392 +++ b/lib/is_single_threaded.c
92393 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
92394 struct task_struct *p, *t;
92395 bool ret;
92396
92397 + if (!mm)
92398 + return true;
92399 +
92400 if (atomic_read(&task->signal->live) != 1)
92401 return false;
92402
92403 diff --git a/lib/kobject.c b/lib/kobject.c
92404 index 58751bb..93a1853 100644
92405 --- a/lib/kobject.c
92406 +++ b/lib/kobject.c
92407 @@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
92408
92409
92410 static DEFINE_SPINLOCK(kobj_ns_type_lock);
92411 -static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
92412 +static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
92413
92414 -int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
92415 +int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
92416 {
92417 enum kobj_ns_type type = ops->type;
92418 int error;
92419 diff --git a/lib/list_debug.c b/lib/list_debug.c
92420 index c24c2f7..f0296f4 100644
92421 --- a/lib/list_debug.c
92422 +++ b/lib/list_debug.c
92423 @@ -11,7 +11,9 @@
92424 #include <linux/bug.h>
92425 #include <linux/kernel.h>
92426 #include <linux/rculist.h>
92427 +#include <linux/mm.h>
92428
92429 +#ifdef CONFIG_DEBUG_LIST
92430 /*
92431 * Insert a new entry between two known consecutive entries.
92432 *
92433 @@ -19,21 +21,40 @@
92434 * the prev/next entries already!
92435 */
92436
92437 +static bool __list_add_debug(struct list_head *new,
92438 + struct list_head *prev,
92439 + struct list_head *next)
92440 +{
92441 + if (unlikely(next->prev != prev)) {
92442 + printk(KERN_ERR "list_add corruption. next->prev should be "
92443 + "prev (%p), but was %p. (next=%p).\n",
92444 + prev, next->prev, next);
92445 + BUG();
92446 + return false;
92447 + }
92448 + if (unlikely(prev->next != next)) {
92449 + printk(KERN_ERR "list_add corruption. prev->next should be "
92450 + "next (%p), but was %p. (prev=%p).\n",
92451 + next, prev->next, prev);
92452 + BUG();
92453 + return false;
92454 + }
92455 + if (unlikely(new == prev || new == next)) {
92456 + printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
92457 + new, prev, next);
92458 + BUG();
92459 + return false;
92460 + }
92461 + return true;
92462 +}
92463 +
92464 void __list_add(struct list_head *new,
92465 - struct list_head *prev,
92466 - struct list_head *next)
92467 + struct list_head *prev,
92468 + struct list_head *next)
92469 {
92470 - WARN(next->prev != prev,
92471 - "list_add corruption. next->prev should be "
92472 - "prev (%p), but was %p. (next=%p).\n",
92473 - prev, next->prev, next);
92474 - WARN(prev->next != next,
92475 - "list_add corruption. prev->next should be "
92476 - "next (%p), but was %p. (prev=%p).\n",
92477 - next, prev->next, prev);
92478 - WARN(new == prev || new == next,
92479 - "list_add double add: new=%p, prev=%p, next=%p.\n",
92480 - new, prev, next);
92481 + if (!__list_add_debug(new, prev, next))
92482 + return;
92483 +
92484 next->prev = new;
92485 new->next = next;
92486 new->prev = prev;
92487 @@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
92488 }
92489 EXPORT_SYMBOL(__list_add);
92490
92491 -void __list_del_entry(struct list_head *entry)
92492 +static bool __list_del_entry_debug(struct list_head *entry)
92493 {
92494 struct list_head *prev, *next;
92495
92496 prev = entry->prev;
92497 next = entry->next;
92498
92499 - if (WARN(next == LIST_POISON1,
92500 - "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
92501 - entry, LIST_POISON1) ||
92502 - WARN(prev == LIST_POISON2,
92503 - "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
92504 - entry, LIST_POISON2) ||
92505 - WARN(prev->next != entry,
92506 - "list_del corruption. prev->next should be %p, "
92507 - "but was %p\n", entry, prev->next) ||
92508 - WARN(next->prev != entry,
92509 - "list_del corruption. next->prev should be %p, "
92510 - "but was %p\n", entry, next->prev))
92511 + if (unlikely(next == LIST_POISON1)) {
92512 + printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
92513 + entry, LIST_POISON1);
92514 + BUG();
92515 + return false;
92516 + }
92517 + if (unlikely(prev == LIST_POISON2)) {
92518 + printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
92519 + entry, LIST_POISON2);
92520 + BUG();
92521 + return false;
92522 + }
92523 + if (unlikely(entry->prev->next != entry)) {
92524 + printk(KERN_ERR "list_del corruption. prev->next should be %p, "
92525 + "but was %p\n", entry, prev->next);
92526 + BUG();
92527 + return false;
92528 + }
92529 + if (unlikely(entry->next->prev != entry)) {
92530 + printk(KERN_ERR "list_del corruption. next->prev should be %p, "
92531 + "but was %p\n", entry, next->prev);
92532 + BUG();
92533 + return false;
92534 + }
92535 + return true;
92536 +}
92537 +
92538 +void __list_del_entry(struct list_head *entry)
92539 +{
92540 + if (!__list_del_entry_debug(entry))
92541 return;
92542
92543 - __list_del(prev, next);
92544 + __list_del(entry->prev, entry->next);
92545 }
92546 EXPORT_SYMBOL(__list_del_entry);
92547
92548 @@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
92549 void __list_add_rcu(struct list_head *new,
92550 struct list_head *prev, struct list_head *next)
92551 {
92552 - WARN(next->prev != prev,
92553 - "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
92554 - prev, next->prev, next);
92555 - WARN(prev->next != next,
92556 - "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
92557 - next, prev->next, prev);
92558 + if (!__list_add_debug(new, prev, next))
92559 + return;
92560 +
92561 new->next = next;
92562 new->prev = prev;
92563 rcu_assign_pointer(list_next_rcu(prev), new);
92564 next->prev = new;
92565 }
92566 EXPORT_SYMBOL(__list_add_rcu);
92567 +#endif
92568 +
92569 +void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
92570 +{
92571 +#ifdef CONFIG_DEBUG_LIST
92572 + if (!__list_add_debug(new, prev, next))
92573 + return;
92574 +#endif
92575 +
92576 + pax_open_kernel();
92577 + next->prev = new;
92578 + new->next = next;
92579 + new->prev = prev;
92580 + prev->next = new;
92581 + pax_close_kernel();
92582 +}
92583 +EXPORT_SYMBOL(__pax_list_add);
92584 +
92585 +void pax_list_del(struct list_head *entry)
92586 +{
92587 +#ifdef CONFIG_DEBUG_LIST
92588 + if (!__list_del_entry_debug(entry))
92589 + return;
92590 +#endif
92591 +
92592 + pax_open_kernel();
92593 + __list_del(entry->prev, entry->next);
92594 + entry->next = LIST_POISON1;
92595 + entry->prev = LIST_POISON2;
92596 + pax_close_kernel();
92597 +}
92598 +EXPORT_SYMBOL(pax_list_del);
92599 +
92600 +void pax_list_del_init(struct list_head *entry)
92601 +{
92602 + pax_open_kernel();
92603 + __list_del(entry->prev, entry->next);
92604 + INIT_LIST_HEAD(entry);
92605 + pax_close_kernel();
92606 +}
92607 +EXPORT_SYMBOL(pax_list_del_init);
92608 +
92609 +void __pax_list_add_rcu(struct list_head *new,
92610 + struct list_head *prev, struct list_head *next)
92611 +{
92612 +#ifdef CONFIG_DEBUG_LIST
92613 + if (!__list_add_debug(new, prev, next))
92614 + return;
92615 +#endif
92616 +
92617 + pax_open_kernel();
92618 + new->next = next;
92619 + new->prev = prev;
92620 + rcu_assign_pointer(list_next_rcu(prev), new);
92621 + next->prev = new;
92622 + pax_close_kernel();
92623 +}
92624 +EXPORT_SYMBOL(__pax_list_add_rcu);
92625 +
92626 +void pax_list_del_rcu(struct list_head *entry)
92627 +{
92628 +#ifdef CONFIG_DEBUG_LIST
92629 + if (!__list_del_entry_debug(entry))
92630 + return;
92631 +#endif
92632 +
92633 + pax_open_kernel();
92634 + __list_del(entry->prev, entry->next);
92635 + entry->next = LIST_POISON1;
92636 + entry->prev = LIST_POISON2;
92637 + pax_close_kernel();
92638 +}
92639 +EXPORT_SYMBOL(pax_list_del_rcu);
92640 diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
92641 index 963b703..438bc51 100644
92642 --- a/lib/percpu-refcount.c
92643 +++ b/lib/percpu-refcount.c
92644 @@ -29,7 +29,7 @@
92645 * can't hit 0 before we've added up all the percpu refs.
92646 */
92647
92648 -#define PCPU_COUNT_BIAS (1U << 31)
92649 +#define PCPU_COUNT_BIAS (1U << 30)
92650
92651 /**
92652 * percpu_ref_init - initialize a percpu refcount
92653 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
92654 index 9599aa7..9cf6c72 100644
92655 --- a/lib/radix-tree.c
92656 +++ b/lib/radix-tree.c
92657 @@ -66,7 +66,7 @@ struct radix_tree_preload {
92658 int nr;
92659 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
92660 };
92661 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
92662 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
92663
92664 static inline void *ptr_to_indirect(void *ptr)
92665 {
92666 diff --git a/lib/random32.c b/lib/random32.c
92667 index fa5da61..35fe9af 100644
92668 --- a/lib/random32.c
92669 +++ b/lib/random32.c
92670 @@ -42,7 +42,7 @@
92671 static void __init prandom_state_selftest(void);
92672 #endif
92673
92674 -static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
92675 +static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
92676
92677 /**
92678 * prandom_u32_state - seeded pseudo-random number generator.
92679 diff --git a/lib/rbtree.c b/lib/rbtree.c
92680 index 65f4eff..2cfa167 100644
92681 --- a/lib/rbtree.c
92682 +++ b/lib/rbtree.c
92683 @@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
92684 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
92685
92686 static const struct rb_augment_callbacks dummy_callbacks = {
92687 - dummy_propagate, dummy_copy, dummy_rotate
92688 + .propagate = dummy_propagate,
92689 + .copy = dummy_copy,
92690 + .rotate = dummy_rotate
92691 };
92692
92693 void rb_insert_color(struct rb_node *node, struct rb_root *root)
92694 diff --git a/lib/show_mem.c b/lib/show_mem.c
92695 index 0922579..9d7adb9 100644
92696 --- a/lib/show_mem.c
92697 +++ b/lib/show_mem.c
92698 @@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
92699 quicklist_total_size());
92700 #endif
92701 #ifdef CONFIG_MEMORY_FAILURE
92702 - printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
92703 + printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
92704 #endif
92705 }
92706 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
92707 index bb2b201..46abaf9 100644
92708 --- a/lib/strncpy_from_user.c
92709 +++ b/lib/strncpy_from_user.c
92710 @@ -21,7 +21,7 @@
92711 */
92712 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
92713 {
92714 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92715 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92716 long res = 0;
92717
92718 /*
92719 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
92720 index a28df52..3d55877 100644
92721 --- a/lib/strnlen_user.c
92722 +++ b/lib/strnlen_user.c
92723 @@ -26,7 +26,7 @@
92724 */
92725 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
92726 {
92727 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92728 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92729 long align, res = 0;
92730 unsigned long c;
92731
92732 diff --git a/lib/swiotlb.c b/lib/swiotlb.c
92733 index b604b83..c0547f6 100644
92734 --- a/lib/swiotlb.c
92735 +++ b/lib/swiotlb.c
92736 @@ -674,7 +674,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
92737
92738 void
92739 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
92740 - dma_addr_t dev_addr)
92741 + dma_addr_t dev_addr, struct dma_attrs *attrs)
92742 {
92743 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
92744
92745 diff --git a/lib/usercopy.c b/lib/usercopy.c
92746 index 4f5b1dd..7cab418 100644
92747 --- a/lib/usercopy.c
92748 +++ b/lib/usercopy.c
92749 @@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
92750 WARN(1, "Buffer overflow detected!\n");
92751 }
92752 EXPORT_SYMBOL(copy_from_user_overflow);
92753 +
92754 +void copy_to_user_overflow(void)
92755 +{
92756 + WARN(1, "Buffer overflow detected!\n");
92757 +}
92758 +EXPORT_SYMBOL(copy_to_user_overflow);
92759 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
92760 index 0648291..42bf42b 100644
92761 --- a/lib/vsprintf.c
92762 +++ b/lib/vsprintf.c
92763 @@ -16,6 +16,9 @@
92764 * - scnprintf and vscnprintf
92765 */
92766
92767 +#ifdef CONFIG_GRKERNSEC_HIDESYM
92768 +#define __INCLUDED_BY_HIDESYM 1
92769 +#endif
92770 #include <stdarg.h>
92771 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
92772 #include <linux/types.h>
92773 @@ -1183,7 +1186,11 @@ char *address_val(char *buf, char *end, const void *addr,
92774 return number(buf, end, num, spec);
92775 }
92776
92777 +#ifdef CONFIG_GRKERNSEC_HIDESYM
92778 +int kptr_restrict __read_mostly = 2;
92779 +#else
92780 int kptr_restrict __read_mostly;
92781 +#endif
92782
92783 /*
92784 * Show a '%p' thing. A kernel extension is that the '%p' is followed
92785 @@ -1196,6 +1203,7 @@ int kptr_restrict __read_mostly;
92786 * - 'f' For simple symbolic function names without offset
92787 * - 'S' For symbolic direct pointers with offset
92788 * - 's' For symbolic direct pointers without offset
92789 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
92790 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
92791 * - 'B' For backtraced symbolic direct pointers with offset
92792 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
92793 @@ -1263,12 +1271,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92794
92795 if (!ptr && *fmt != 'K') {
92796 /*
92797 - * Print (null) with the same width as a pointer so it makes
92798 + * Print (nil) with the same width as a pointer so it makes
92799 * tabular output look nice.
92800 */
92801 if (spec.field_width == -1)
92802 spec.field_width = default_width;
92803 - return string(buf, end, "(null)", spec);
92804 + return string(buf, end, "(nil)", spec);
92805 }
92806
92807 switch (*fmt) {
92808 @@ -1278,6 +1286,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92809 /* Fallthrough */
92810 case 'S':
92811 case 's':
92812 +#ifdef CONFIG_GRKERNSEC_HIDESYM
92813 + break;
92814 +#else
92815 + return symbol_string(buf, end, ptr, spec, fmt);
92816 +#endif
92817 + case 'A':
92818 case 'B':
92819 return symbol_string(buf, end, ptr, spec, fmt);
92820 case 'R':
92821 @@ -1333,6 +1347,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92822 va_end(va);
92823 return buf;
92824 }
92825 + case 'P':
92826 + break;
92827 case 'K':
92828 /*
92829 * %pK cannot be used in IRQ context because its test
92830 @@ -1390,6 +1406,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92831 ((const struct file *)ptr)->f_path.dentry,
92832 spec, fmt);
92833 }
92834 +
92835 +#ifdef CONFIG_GRKERNSEC_HIDESYM
92836 + /* 'P' = approved pointers to copy to userland,
92837 + as in the /proc/kallsyms case, as we make it display nothing
92838 + for non-root users, and the real contents for root users
92839 + Also ignore 'K' pointers, since we force their NULLing for non-root users
92840 + above
92841 + */
92842 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
92843 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
92844 + dump_stack();
92845 + ptr = NULL;
92846 + }
92847 +#endif
92848 +
92849 spec.flags |= SMALL;
92850 if (spec.field_width == -1) {
92851 spec.field_width = default_width;
92852 @@ -2089,11 +2120,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
92853 typeof(type) value; \
92854 if (sizeof(type) == 8) { \
92855 args = PTR_ALIGN(args, sizeof(u32)); \
92856 - *(u32 *)&value = *(u32 *)args; \
92857 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
92858 + *(u32 *)&value = *(const u32 *)args; \
92859 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
92860 } else { \
92861 args = PTR_ALIGN(args, sizeof(type)); \
92862 - value = *(typeof(type) *)args; \
92863 + value = *(const typeof(type) *)args; \
92864 } \
92865 args += sizeof(type); \
92866 value; \
92867 @@ -2156,7 +2187,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
92868 case FORMAT_TYPE_STR: {
92869 const char *str_arg = args;
92870 args += strlen(str_arg) + 1;
92871 - str = string(str, end, (char *)str_arg, spec);
92872 + str = string(str, end, str_arg, spec);
92873 break;
92874 }
92875
92876 diff --git a/localversion-grsec b/localversion-grsec
92877 new file mode 100644
92878 index 0000000..7cd6065
92879 --- /dev/null
92880 +++ b/localversion-grsec
92881 @@ -0,0 +1 @@
92882 +-grsec
92883 diff --git a/mm/Kconfig b/mm/Kconfig
92884 index 2f42b9c..6095e14 100644
92885 --- a/mm/Kconfig
92886 +++ b/mm/Kconfig
92887 @@ -330,10 +330,11 @@ config KSM
92888 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
92889
92890 config DEFAULT_MMAP_MIN_ADDR
92891 - int "Low address space to protect from user allocation"
92892 + int "Low address space to protect from user allocation"
92893 depends on MMU
92894 - default 4096
92895 - help
92896 + default 32768 if ALPHA || ARM || PARISC || SPARC32
92897 + default 65536
92898 + help
92899 This is the portion of low virtual memory which should be protected
92900 from userspace allocation. Keeping a user from writing to low pages
92901 can help reduce the impact of kernel NULL pointer bugs.
92902 @@ -364,7 +365,7 @@ config MEMORY_FAILURE
92903
92904 config HWPOISON_INJECT
92905 tristate "HWPoison pages injector"
92906 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
92907 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
92908 select PROC_PAGE_MONITOR
92909
92910 config NOMMU_INITIAL_TRIM_EXCESS
92911 diff --git a/mm/backing-dev.c b/mm/backing-dev.c
92912 index 09d9591..165bb75 100644
92913 --- a/mm/backing-dev.c
92914 +++ b/mm/backing-dev.c
92915 @@ -12,7 +12,7 @@
92916 #include <linux/device.h>
92917 #include <trace/events/writeback.h>
92918
92919 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
92920 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
92921
92922 struct backing_dev_info default_backing_dev_info = {
92923 .name = "default",
92924 @@ -533,7 +533,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
92925 return err;
92926
92927 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
92928 - atomic_long_inc_return(&bdi_seq));
92929 + atomic_long_inc_return_unchecked(&bdi_seq));
92930 if (err) {
92931 bdi_destroy(bdi);
92932 return err;
92933 diff --git a/mm/filemap.c b/mm/filemap.c
92934 index 088358c..bb415bf 100644
92935 --- a/mm/filemap.c
92936 +++ b/mm/filemap.c
92937 @@ -2125,7 +2125,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
92938 struct address_space *mapping = file->f_mapping;
92939
92940 if (!mapping->a_ops->readpage)
92941 - return -ENOEXEC;
92942 + return -ENODEV;
92943 file_accessed(file);
92944 vma->vm_ops = &generic_file_vm_ops;
92945 return 0;
92946 @@ -2303,6 +2303,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
92947 *pos = i_size_read(inode);
92948
92949 if (limit != RLIM_INFINITY) {
92950 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
92951 if (*pos >= limit) {
92952 send_sig(SIGXFSZ, current, 0);
92953 return -EFBIG;
92954 diff --git a/mm/fremap.c b/mm/fremap.c
92955 index 34feba6..315fe78 100644
92956 --- a/mm/fremap.c
92957 +++ b/mm/fremap.c
92958 @@ -179,6 +179,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
92959 retry:
92960 vma = find_vma(mm, start);
92961
92962 +#ifdef CONFIG_PAX_SEGMEXEC
92963 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
92964 + goto out;
92965 +#endif
92966 +
92967 /*
92968 * Make sure the vma is shared, that it supports prefaulting,
92969 * and that the remapped range is valid and fully within
92970 diff --git a/mm/highmem.c b/mm/highmem.c
92971 index b32b70c..e512eb0 100644
92972 --- a/mm/highmem.c
92973 +++ b/mm/highmem.c
92974 @@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
92975 * So no dangers, even with speculative execution.
92976 */
92977 page = pte_page(pkmap_page_table[i]);
92978 + pax_open_kernel();
92979 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
92980 -
92981 + pax_close_kernel();
92982 set_page_address(page, NULL);
92983 need_flush = 1;
92984 }
92985 @@ -198,9 +199,11 @@ start:
92986 }
92987 }
92988 vaddr = PKMAP_ADDR(last_pkmap_nr);
92989 +
92990 + pax_open_kernel();
92991 set_pte_at(&init_mm, vaddr,
92992 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
92993 -
92994 + pax_close_kernel();
92995 pkmap_count[last_pkmap_nr] = 1;
92996 set_page_address(page, (void *)vaddr);
92997
92998 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
92999 index 002f08e..68f11e8 100644
93000 --- a/mm/hugetlb.c
93001 +++ b/mm/hugetlb.c
93002 @@ -2107,6 +2107,7 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
93003 struct hstate *h = &default_hstate;
93004 unsigned long tmp;
93005 int ret;
93006 + ctl_table_no_const hugetlb_table;
93007
93008 if (!hugepages_supported())
93009 return -ENOTSUPP;
93010 @@ -2116,9 +2117,10 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
93011 if (write && h->order >= MAX_ORDER)
93012 return -EINVAL;
93013
93014 - table->data = &tmp;
93015 - table->maxlen = sizeof(unsigned long);
93016 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
93017 + hugetlb_table = *table;
93018 + hugetlb_table.data = &tmp;
93019 + hugetlb_table.maxlen = sizeof(unsigned long);
93020 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
93021 if (ret)
93022 goto out;
93023
93024 @@ -2163,6 +2165,7 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
93025 struct hstate *h = &default_hstate;
93026 unsigned long tmp;
93027 int ret;
93028 + ctl_table_no_const hugetlb_table;
93029
93030 if (!hugepages_supported())
93031 return -ENOTSUPP;
93032 @@ -2172,9 +2175,10 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
93033 if (write && h->order >= MAX_ORDER)
93034 return -EINVAL;
93035
93036 - table->data = &tmp;
93037 - table->maxlen = sizeof(unsigned long);
93038 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
93039 + hugetlb_table = *table;
93040 + hugetlb_table.data = &tmp;
93041 + hugetlb_table.maxlen = sizeof(unsigned long);
93042 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
93043 if (ret)
93044 goto out;
93045
93046 @@ -2655,6 +2659,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
93047 return 1;
93048 }
93049
93050 +#ifdef CONFIG_PAX_SEGMEXEC
93051 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
93052 +{
93053 + struct mm_struct *mm = vma->vm_mm;
93054 + struct vm_area_struct *vma_m;
93055 + unsigned long address_m;
93056 + pte_t *ptep_m;
93057 +
93058 + vma_m = pax_find_mirror_vma(vma);
93059 + if (!vma_m)
93060 + return;
93061 +
93062 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
93063 + address_m = address + SEGMEXEC_TASK_SIZE;
93064 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
93065 + get_page(page_m);
93066 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
93067 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
93068 +}
93069 +#endif
93070 +
93071 /*
93072 * Hugetlb_cow() should be called with page lock of the original hugepage held.
93073 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
93074 @@ -2772,6 +2797,11 @@ retry_avoidcopy:
93075 make_huge_pte(vma, new_page, 1));
93076 page_remove_rmap(old_page);
93077 hugepage_add_new_anon_rmap(new_page, vma, address);
93078 +
93079 +#ifdef CONFIG_PAX_SEGMEXEC
93080 + pax_mirror_huge_pte(vma, address, new_page);
93081 +#endif
93082 +
93083 /* Make the old page be freed below */
93084 new_page = old_page;
93085 }
93086 @@ -2931,6 +2961,10 @@ retry:
93087 && (vma->vm_flags & VM_SHARED)));
93088 set_huge_pte_at(mm, address, ptep, new_pte);
93089
93090 +#ifdef CONFIG_PAX_SEGMEXEC
93091 + pax_mirror_huge_pte(vma, address, page);
93092 +#endif
93093 +
93094 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
93095 /* Optimization, do the COW without a second fault */
93096 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
93097 @@ -2997,6 +3031,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93098 struct hstate *h = hstate_vma(vma);
93099 struct address_space *mapping;
93100
93101 +#ifdef CONFIG_PAX_SEGMEXEC
93102 + struct vm_area_struct *vma_m;
93103 +#endif
93104 +
93105 address &= huge_page_mask(h);
93106
93107 ptep = huge_pte_offset(mm, address);
93108 @@ -3010,6 +3048,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93109 VM_FAULT_SET_HINDEX(hstate_index(h));
93110 }
93111
93112 +#ifdef CONFIG_PAX_SEGMEXEC
93113 + vma_m = pax_find_mirror_vma(vma);
93114 + if (vma_m) {
93115 + unsigned long address_m;
93116 +
93117 + if (vma->vm_start > vma_m->vm_start) {
93118 + address_m = address;
93119 + address -= SEGMEXEC_TASK_SIZE;
93120 + vma = vma_m;
93121 + h = hstate_vma(vma);
93122 + } else
93123 + address_m = address + SEGMEXEC_TASK_SIZE;
93124 +
93125 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
93126 + return VM_FAULT_OOM;
93127 + address_m &= HPAGE_MASK;
93128 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
93129 + }
93130 +#endif
93131 +
93132 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
93133 if (!ptep)
93134 return VM_FAULT_OOM;
93135 diff --git a/mm/internal.h b/mm/internal.h
93136 index 07b6736..ae8da20 100644
93137 --- a/mm/internal.h
93138 +++ b/mm/internal.h
93139 @@ -109,6 +109,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
93140 * in mm/page_alloc.c
93141 */
93142 extern void __free_pages_bootmem(struct page *page, unsigned int order);
93143 +extern void free_compound_page(struct page *page);
93144 extern void prep_compound_page(struct page *page, unsigned long order);
93145 #ifdef CONFIG_MEMORY_FAILURE
93146 extern bool is_free_buddy_page(struct page *page);
93147 @@ -367,7 +368,7 @@ extern u32 hwpoison_filter_enable;
93148
93149 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
93150 unsigned long, unsigned long,
93151 - unsigned long, unsigned long);
93152 + unsigned long, unsigned long) __intentional_overflow(-1);
93153
93154 extern void set_pageblock_order(void);
93155 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
93156 diff --git a/mm/iov_iter.c b/mm/iov_iter.c
93157 index 10e46cd..e3052f6 100644
93158 --- a/mm/iov_iter.c
93159 +++ b/mm/iov_iter.c
93160 @@ -87,7 +87,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
93161
93162 while (bytes) {
93163 char __user *buf = iov->iov_base + base;
93164 - int copy = min(bytes, iov->iov_len - base);
93165 + size_t copy = min(bytes, iov->iov_len - base);
93166
93167 base = 0;
93168 left = __copy_from_user_inatomic(vaddr, buf, copy);
93169 @@ -115,7 +115,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
93170
93171 kaddr = kmap_atomic(page);
93172 if (likely(i->nr_segs == 1)) {
93173 - int left;
93174 + size_t left;
93175 char __user *buf = i->iov->iov_base + i->iov_offset;
93176 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
93177 copied = bytes - left;
93178 @@ -143,7 +143,7 @@ size_t iov_iter_copy_from_user(struct page *page,
93179
93180 kaddr = kmap(page);
93181 if (likely(i->nr_segs == 1)) {
93182 - int left;
93183 + size_t left;
93184 char __user *buf = i->iov->iov_base + i->iov_offset;
93185 left = __copy_from_user(kaddr + offset, buf, bytes);
93186 copied = bytes - left;
93187 @@ -173,7 +173,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
93188 * zero-length segments (without overruning the iovec).
93189 */
93190 while (bytes || unlikely(i->count && !iov->iov_len)) {
93191 - int copy;
93192 + size_t copy;
93193
93194 copy = min(bytes, iov->iov_len - base);
93195 BUG_ON(!i->count || i->count < copy);
93196 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
93197 index 8d2fcdf..6dd9f1a 100644
93198 --- a/mm/kmemleak.c
93199 +++ b/mm/kmemleak.c
93200 @@ -364,7 +364,7 @@ static void print_unreferenced(struct seq_file *seq,
93201
93202 for (i = 0; i < object->trace_len; i++) {
93203 void *ptr = (void *)object->trace[i];
93204 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
93205 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
93206 }
93207 }
93208
93209 @@ -1871,7 +1871,7 @@ static int __init kmemleak_late_init(void)
93210 return -ENOMEM;
93211 }
93212
93213 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
93214 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
93215 &kmemleak_fops);
93216 if (!dentry)
93217 pr_warning("Failed to create the debugfs kmemleak file\n");
93218 diff --git a/mm/maccess.c b/mm/maccess.c
93219 index d53adf9..03a24bf 100644
93220 --- a/mm/maccess.c
93221 +++ b/mm/maccess.c
93222 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
93223 set_fs(KERNEL_DS);
93224 pagefault_disable();
93225 ret = __copy_from_user_inatomic(dst,
93226 - (__force const void __user *)src, size);
93227 + (const void __force_user *)src, size);
93228 pagefault_enable();
93229 set_fs(old_fs);
93230
93231 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
93232
93233 set_fs(KERNEL_DS);
93234 pagefault_disable();
93235 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
93236 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
93237 pagefault_enable();
93238 set_fs(old_fs);
93239
93240 diff --git a/mm/madvise.c b/mm/madvise.c
93241 index a402f8f..f5e5daa 100644
93242 --- a/mm/madvise.c
93243 +++ b/mm/madvise.c
93244 @@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
93245 pgoff_t pgoff;
93246 unsigned long new_flags = vma->vm_flags;
93247
93248 +#ifdef CONFIG_PAX_SEGMEXEC
93249 + struct vm_area_struct *vma_m;
93250 +#endif
93251 +
93252 switch (behavior) {
93253 case MADV_NORMAL:
93254 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
93255 @@ -126,6 +130,13 @@ success:
93256 /*
93257 * vm_flags is protected by the mmap_sem held in write mode.
93258 */
93259 +
93260 +#ifdef CONFIG_PAX_SEGMEXEC
93261 + vma_m = pax_find_mirror_vma(vma);
93262 + if (vma_m)
93263 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
93264 +#endif
93265 +
93266 vma->vm_flags = new_flags;
93267
93268 out:
93269 @@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
93270 struct vm_area_struct **prev,
93271 unsigned long start, unsigned long end)
93272 {
93273 +
93274 +#ifdef CONFIG_PAX_SEGMEXEC
93275 + struct vm_area_struct *vma_m;
93276 +#endif
93277 +
93278 *prev = vma;
93279 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
93280 return -EINVAL;
93281 @@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
93282 zap_page_range(vma, start, end - start, &details);
93283 } else
93284 zap_page_range(vma, start, end - start, NULL);
93285 +
93286 +#ifdef CONFIG_PAX_SEGMEXEC
93287 + vma_m = pax_find_mirror_vma(vma);
93288 + if (vma_m) {
93289 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
93290 + struct zap_details details = {
93291 + .nonlinear_vma = vma_m,
93292 + .last_index = ULONG_MAX,
93293 + };
93294 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
93295 + } else
93296 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
93297 + }
93298 +#endif
93299 +
93300 return 0;
93301 }
93302
93303 @@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
93304 if (end < start)
93305 return error;
93306
93307 +#ifdef CONFIG_PAX_SEGMEXEC
93308 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
93309 + if (end > SEGMEXEC_TASK_SIZE)
93310 + return error;
93311 + } else
93312 +#endif
93313 +
93314 + if (end > TASK_SIZE)
93315 + return error;
93316 +
93317 error = 0;
93318 if (end == start)
93319 return error;
93320 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
93321 index eb8fb72..ae36cf3 100644
93322 --- a/mm/memory-failure.c
93323 +++ b/mm/memory-failure.c
93324 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
93325
93326 int sysctl_memory_failure_recovery __read_mostly = 1;
93327
93328 -atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
93329 +atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
93330
93331 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
93332
93333 @@ -198,7 +198,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
93334 pfn, t->comm, t->pid);
93335 si.si_signo = SIGBUS;
93336 si.si_errno = 0;
93337 - si.si_addr = (void *)addr;
93338 + si.si_addr = (void __user *)addr;
93339 #ifdef __ARCH_SI_TRAPNO
93340 si.si_trapno = trapno;
93341 #endif
93342 @@ -791,7 +791,7 @@ static struct page_state {
93343 unsigned long res;
93344 char *msg;
93345 int (*action)(struct page *p, unsigned long pfn);
93346 -} error_states[] = {
93347 +} __do_const error_states[] = {
93348 { reserved, reserved, "reserved kernel", me_kernel },
93349 /*
93350 * free pages are specially detected outside this table:
93351 @@ -1091,7 +1091,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
93352 nr_pages = 1 << compound_order(hpage);
93353 else /* normal page or thp */
93354 nr_pages = 1;
93355 - atomic_long_add(nr_pages, &num_poisoned_pages);
93356 + atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
93357
93358 /*
93359 * We need/can do nothing about count=0 pages.
93360 @@ -1120,7 +1120,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
93361 if (PageHWPoison(hpage)) {
93362 if ((hwpoison_filter(p) && TestClearPageHWPoison(p))
93363 || (p != hpage && TestSetPageHWPoison(hpage))) {
93364 - atomic_long_sub(nr_pages, &num_poisoned_pages);
93365 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
93366 unlock_page(hpage);
93367 return 0;
93368 }
93369 @@ -1186,14 +1186,14 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
93370 */
93371 if (!PageHWPoison(p)) {
93372 printk(KERN_ERR "MCE %#lx: just unpoisoned\n", pfn);
93373 - atomic_long_sub(nr_pages, &num_poisoned_pages);
93374 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
93375 put_page(hpage);
93376 res = 0;
93377 goto out;
93378 }
93379 if (hwpoison_filter(p)) {
93380 if (TestClearPageHWPoison(p))
93381 - atomic_long_sub(nr_pages, &num_poisoned_pages);
93382 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
93383 unlock_page(hpage);
93384 put_page(hpage);
93385 return 0;
93386 @@ -1415,7 +1415,7 @@ int unpoison_memory(unsigned long pfn)
93387 return 0;
93388 }
93389 if (TestClearPageHWPoison(p))
93390 - atomic_long_dec(&num_poisoned_pages);
93391 + atomic_long_dec_unchecked(&num_poisoned_pages);
93392 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
93393 return 0;
93394 }
93395 @@ -1429,7 +1429,7 @@ int unpoison_memory(unsigned long pfn)
93396 */
93397 if (TestClearPageHWPoison(page)) {
93398 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
93399 - atomic_long_sub(nr_pages, &num_poisoned_pages);
93400 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
93401 freeit = 1;
93402 if (PageHuge(page))
93403 clear_page_hwpoison_huge_page(page);
93404 @@ -1554,11 +1554,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
93405 if (PageHuge(page)) {
93406 set_page_hwpoison_huge_page(hpage);
93407 dequeue_hwpoisoned_huge_page(hpage);
93408 - atomic_long_add(1 << compound_order(hpage),
93409 + atomic_long_add_unchecked(1 << compound_order(hpage),
93410 &num_poisoned_pages);
93411 } else {
93412 SetPageHWPoison(page);
93413 - atomic_long_inc(&num_poisoned_pages);
93414 + atomic_long_inc_unchecked(&num_poisoned_pages);
93415 }
93416 }
93417 return ret;
93418 @@ -1597,7 +1597,7 @@ static int __soft_offline_page(struct page *page, int flags)
93419 put_page(page);
93420 pr_info("soft_offline: %#lx: invalidated\n", pfn);
93421 SetPageHWPoison(page);
93422 - atomic_long_inc(&num_poisoned_pages);
93423 + atomic_long_inc_unchecked(&num_poisoned_pages);
93424 return 0;
93425 }
93426
93427 @@ -1648,7 +1648,7 @@ static int __soft_offline_page(struct page *page, int flags)
93428 if (!is_free_buddy_page(page))
93429 pr_info("soft offline: %#lx: page leaked\n",
93430 pfn);
93431 - atomic_long_inc(&num_poisoned_pages);
93432 + atomic_long_inc_unchecked(&num_poisoned_pages);
93433 }
93434 } else {
93435 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
93436 @@ -1722,11 +1722,11 @@ int soft_offline_page(struct page *page, int flags)
93437 if (PageHuge(page)) {
93438 set_page_hwpoison_huge_page(hpage);
93439 dequeue_hwpoisoned_huge_page(hpage);
93440 - atomic_long_add(1 << compound_order(hpage),
93441 + atomic_long_add_unchecked(1 << compound_order(hpage),
93442 &num_poisoned_pages);
93443 } else {
93444 SetPageHWPoison(page);
93445 - atomic_long_inc(&num_poisoned_pages);
93446 + atomic_long_inc_unchecked(&num_poisoned_pages);
93447 }
93448 }
93449 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
93450 diff --git a/mm/memory.c b/mm/memory.c
93451 index 4f9e530..779c7ce 100644
93452 --- a/mm/memory.c
93453 +++ b/mm/memory.c
93454 @@ -413,6 +413,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
93455 free_pte_range(tlb, pmd, addr);
93456 } while (pmd++, addr = next, addr != end);
93457
93458 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
93459 start &= PUD_MASK;
93460 if (start < floor)
93461 return;
93462 @@ -427,6 +428,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
93463 pmd = pmd_offset(pud, start);
93464 pud_clear(pud);
93465 pmd_free_tlb(tlb, pmd, start);
93466 +#endif
93467 +
93468 }
93469
93470 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
93471 @@ -446,6 +449,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
93472 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
93473 } while (pud++, addr = next, addr != end);
93474
93475 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
93476 start &= PGDIR_MASK;
93477 if (start < floor)
93478 return;
93479 @@ -460,6 +464,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
93480 pud = pud_offset(pgd, start);
93481 pgd_clear(pgd);
93482 pud_free_tlb(tlb, pud, start);
93483 +#endif
93484 +
93485 }
93486
93487 /*
93488 @@ -1652,12 +1658,6 @@ no_page_table:
93489 return page;
93490 }
93491
93492 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
93493 -{
93494 - return stack_guard_page_start(vma, addr) ||
93495 - stack_guard_page_end(vma, addr+PAGE_SIZE);
93496 -}
93497 -
93498 /**
93499 * __get_user_pages() - pin user pages in memory
93500 * @tsk: task_struct of target task
93501 @@ -1735,10 +1735,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
93502
93503 i = 0;
93504
93505 - do {
93506 + while (nr_pages) {
93507 struct vm_area_struct *vma;
93508
93509 - vma = find_extend_vma(mm, start);
93510 + vma = find_vma(mm, start);
93511 if (!vma && in_gate_area(mm, start)) {
93512 unsigned long pg = start & PAGE_MASK;
93513 pgd_t *pgd;
93514 @@ -1787,7 +1787,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
93515 goto next_page;
93516 }
93517
93518 - if (!vma)
93519 + if (!vma || start < vma->vm_start)
93520 goto efault;
93521 vm_flags = vma->vm_flags;
93522 if (vm_flags & (VM_IO | VM_PFNMAP))
93523 @@ -1848,11 +1848,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
93524 int ret;
93525 unsigned int fault_flags = 0;
93526
93527 - /* For mlock, just skip the stack guard page. */
93528 - if (foll_flags & FOLL_MLOCK) {
93529 - if (stack_guard_page(vma, start))
93530 - goto next_page;
93531 - }
93532 if (foll_flags & FOLL_WRITE)
93533 fault_flags |= FAULT_FLAG_WRITE;
93534 if (nonblocking)
93535 @@ -1932,7 +1927,7 @@ next_page:
93536 start += page_increm * PAGE_SIZE;
93537 nr_pages -= page_increm;
93538 } while (nr_pages && start < vma->vm_end);
93539 - } while (nr_pages);
93540 + }
93541 return i;
93542 efault:
93543 return i ? : -EFAULT;
93544 @@ -2145,6 +2140,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
93545 page_add_file_rmap(page);
93546 set_pte_at(mm, addr, pte, mk_pte(page, prot));
93547
93548 +#ifdef CONFIG_PAX_SEGMEXEC
93549 + pax_mirror_file_pte(vma, addr, page, ptl);
93550 +#endif
93551 +
93552 retval = 0;
93553 pte_unmap_unlock(pte, ptl);
93554 return retval;
93555 @@ -2189,9 +2188,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
93556 if (!page_count(page))
93557 return -EINVAL;
93558 if (!(vma->vm_flags & VM_MIXEDMAP)) {
93559 +
93560 +#ifdef CONFIG_PAX_SEGMEXEC
93561 + struct vm_area_struct *vma_m;
93562 +#endif
93563 +
93564 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
93565 BUG_ON(vma->vm_flags & VM_PFNMAP);
93566 vma->vm_flags |= VM_MIXEDMAP;
93567 +
93568 +#ifdef CONFIG_PAX_SEGMEXEC
93569 + vma_m = pax_find_mirror_vma(vma);
93570 + if (vma_m)
93571 + vma_m->vm_flags |= VM_MIXEDMAP;
93572 +#endif
93573 +
93574 }
93575 return insert_page(vma, addr, page, vma->vm_page_prot);
93576 }
93577 @@ -2274,6 +2285,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
93578 unsigned long pfn)
93579 {
93580 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
93581 + BUG_ON(vma->vm_mirror);
93582
93583 if (addr < vma->vm_start || addr >= vma->vm_end)
93584 return -EFAULT;
93585 @@ -2521,7 +2533,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
93586
93587 BUG_ON(pud_huge(*pud));
93588
93589 - pmd = pmd_alloc(mm, pud, addr);
93590 + pmd = (mm == &init_mm) ?
93591 + pmd_alloc_kernel(mm, pud, addr) :
93592 + pmd_alloc(mm, pud, addr);
93593 if (!pmd)
93594 return -ENOMEM;
93595 do {
93596 @@ -2541,7 +2555,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
93597 unsigned long next;
93598 int err;
93599
93600 - pud = pud_alloc(mm, pgd, addr);
93601 + pud = (mm == &init_mm) ?
93602 + pud_alloc_kernel(mm, pgd, addr) :
93603 + pud_alloc(mm, pgd, addr);
93604 if (!pud)
93605 return -ENOMEM;
93606 do {
93607 @@ -2663,6 +2679,186 @@ static int do_page_mkwrite(struct vm_area_struct *vma, struct page *page,
93608 return ret;
93609 }
93610
93611 +#ifdef CONFIG_PAX_SEGMEXEC
93612 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
93613 +{
93614 + struct mm_struct *mm = vma->vm_mm;
93615 + spinlock_t *ptl;
93616 + pte_t *pte, entry;
93617 +
93618 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
93619 + entry = *pte;
93620 + if (!pte_present(entry)) {
93621 + if (!pte_none(entry)) {
93622 + BUG_ON(pte_file(entry));
93623 + free_swap_and_cache(pte_to_swp_entry(entry));
93624 + pte_clear_not_present_full(mm, address, pte, 0);
93625 + }
93626 + } else {
93627 + struct page *page;
93628 +
93629 + flush_cache_page(vma, address, pte_pfn(entry));
93630 + entry = ptep_clear_flush(vma, address, pte);
93631 + BUG_ON(pte_dirty(entry));
93632 + page = vm_normal_page(vma, address, entry);
93633 + if (page) {
93634 + update_hiwater_rss(mm);
93635 + if (PageAnon(page))
93636 + dec_mm_counter_fast(mm, MM_ANONPAGES);
93637 + else
93638 + dec_mm_counter_fast(mm, MM_FILEPAGES);
93639 + page_remove_rmap(page);
93640 + page_cache_release(page);
93641 + }
93642 + }
93643 + pte_unmap_unlock(pte, ptl);
93644 +}
93645 +
93646 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
93647 + *
93648 + * the ptl of the lower mapped page is held on entry and is not released on exit
93649 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
93650 + */
93651 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
93652 +{
93653 + struct mm_struct *mm = vma->vm_mm;
93654 + unsigned long address_m;
93655 + spinlock_t *ptl_m;
93656 + struct vm_area_struct *vma_m;
93657 + pmd_t *pmd_m;
93658 + pte_t *pte_m, entry_m;
93659 +
93660 + BUG_ON(!page_m || !PageAnon(page_m));
93661 +
93662 + vma_m = pax_find_mirror_vma(vma);
93663 + if (!vma_m)
93664 + return;
93665 +
93666 + BUG_ON(!PageLocked(page_m));
93667 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
93668 + address_m = address + SEGMEXEC_TASK_SIZE;
93669 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
93670 + pte_m = pte_offset_map(pmd_m, address_m);
93671 + ptl_m = pte_lockptr(mm, pmd_m);
93672 + if (ptl != ptl_m) {
93673 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
93674 + if (!pte_none(*pte_m))
93675 + goto out;
93676 + }
93677 +
93678 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
93679 + page_cache_get(page_m);
93680 + page_add_anon_rmap(page_m, vma_m, address_m);
93681 + inc_mm_counter_fast(mm, MM_ANONPAGES);
93682 + set_pte_at(mm, address_m, pte_m, entry_m);
93683 + update_mmu_cache(vma_m, address_m, pte_m);
93684 +out:
93685 + if (ptl != ptl_m)
93686 + spin_unlock(ptl_m);
93687 + pte_unmap(pte_m);
93688 + unlock_page(page_m);
93689 +}
93690 +
93691 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
93692 +{
93693 + struct mm_struct *mm = vma->vm_mm;
93694 + unsigned long address_m;
93695 + spinlock_t *ptl_m;
93696 + struct vm_area_struct *vma_m;
93697 + pmd_t *pmd_m;
93698 + pte_t *pte_m, entry_m;
93699 +
93700 + BUG_ON(!page_m || PageAnon(page_m));
93701 +
93702 + vma_m = pax_find_mirror_vma(vma);
93703 + if (!vma_m)
93704 + return;
93705 +
93706 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
93707 + address_m = address + SEGMEXEC_TASK_SIZE;
93708 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
93709 + pte_m = pte_offset_map(pmd_m, address_m);
93710 + ptl_m = pte_lockptr(mm, pmd_m);
93711 + if (ptl != ptl_m) {
93712 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
93713 + if (!pte_none(*pte_m))
93714 + goto out;
93715 + }
93716 +
93717 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
93718 + page_cache_get(page_m);
93719 + page_add_file_rmap(page_m);
93720 + inc_mm_counter_fast(mm, MM_FILEPAGES);
93721 + set_pte_at(mm, address_m, pte_m, entry_m);
93722 + update_mmu_cache(vma_m, address_m, pte_m);
93723 +out:
93724 + if (ptl != ptl_m)
93725 + spin_unlock(ptl_m);
93726 + pte_unmap(pte_m);
93727 +}
93728 +
93729 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
93730 +{
93731 + struct mm_struct *mm = vma->vm_mm;
93732 + unsigned long address_m;
93733 + spinlock_t *ptl_m;
93734 + struct vm_area_struct *vma_m;
93735 + pmd_t *pmd_m;
93736 + pte_t *pte_m, entry_m;
93737 +
93738 + vma_m = pax_find_mirror_vma(vma);
93739 + if (!vma_m)
93740 + return;
93741 +
93742 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
93743 + address_m = address + SEGMEXEC_TASK_SIZE;
93744 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
93745 + pte_m = pte_offset_map(pmd_m, address_m);
93746 + ptl_m = pte_lockptr(mm, pmd_m);
93747 + if (ptl != ptl_m) {
93748 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
93749 + if (!pte_none(*pte_m))
93750 + goto out;
93751 + }
93752 +
93753 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
93754 + set_pte_at(mm, address_m, pte_m, entry_m);
93755 +out:
93756 + if (ptl != ptl_m)
93757 + spin_unlock(ptl_m);
93758 + pte_unmap(pte_m);
93759 +}
93760 +
93761 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
93762 +{
93763 + struct page *page_m;
93764 + pte_t entry;
93765 +
93766 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
93767 + goto out;
93768 +
93769 + entry = *pte;
93770 + page_m = vm_normal_page(vma, address, entry);
93771 + if (!page_m)
93772 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
93773 + else if (PageAnon(page_m)) {
93774 + if (pax_find_mirror_vma(vma)) {
93775 + pte_unmap_unlock(pte, ptl);
93776 + lock_page(page_m);
93777 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
93778 + if (pte_same(entry, *pte))
93779 + pax_mirror_anon_pte(vma, address, page_m, ptl);
93780 + else
93781 + unlock_page(page_m);
93782 + }
93783 + } else
93784 + pax_mirror_file_pte(vma, address, page_m, ptl);
93785 +
93786 +out:
93787 + pte_unmap_unlock(pte, ptl);
93788 +}
93789 +#endif
93790 +
93791 /*
93792 * This routine handles present pages, when users try to write
93793 * to a shared page. It is done by copying the page to a new address
93794 @@ -2860,6 +3056,12 @@ gotten:
93795 */
93796 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
93797 if (likely(pte_same(*page_table, orig_pte))) {
93798 +
93799 +#ifdef CONFIG_PAX_SEGMEXEC
93800 + if (pax_find_mirror_vma(vma))
93801 + BUG_ON(!trylock_page(new_page));
93802 +#endif
93803 +
93804 if (old_page) {
93805 if (!PageAnon(old_page)) {
93806 dec_mm_counter_fast(mm, MM_FILEPAGES);
93807 @@ -2911,6 +3113,10 @@ gotten:
93808 page_remove_rmap(old_page);
93809 }
93810
93811 +#ifdef CONFIG_PAX_SEGMEXEC
93812 + pax_mirror_anon_pte(vma, address, new_page, ptl);
93813 +#endif
93814 +
93815 /* Free the old page.. */
93816 new_page = old_page;
93817 ret |= VM_FAULT_WRITE;
93818 @@ -3184,6 +3390,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
93819 swap_free(entry);
93820 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
93821 try_to_free_swap(page);
93822 +
93823 +#ifdef CONFIG_PAX_SEGMEXEC
93824 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
93825 +#endif
93826 +
93827 unlock_page(page);
93828 if (page != swapcache) {
93829 /*
93830 @@ -3207,6 +3418,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
93831
93832 /* No need to invalidate - it was non-present before */
93833 update_mmu_cache(vma, address, page_table);
93834 +
93835 +#ifdef CONFIG_PAX_SEGMEXEC
93836 + pax_mirror_anon_pte(vma, address, page, ptl);
93837 +#endif
93838 +
93839 unlock:
93840 pte_unmap_unlock(page_table, ptl);
93841 out:
93842 @@ -3226,40 +3442,6 @@ out_release:
93843 }
93844
93845 /*
93846 - * This is like a special single-page "expand_{down|up}wards()",
93847 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
93848 - * doesn't hit another vma.
93849 - */
93850 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
93851 -{
93852 - address &= PAGE_MASK;
93853 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
93854 - struct vm_area_struct *prev = vma->vm_prev;
93855 -
93856 - /*
93857 - * Is there a mapping abutting this one below?
93858 - *
93859 - * That's only ok if it's the same stack mapping
93860 - * that has gotten split..
93861 - */
93862 - if (prev && prev->vm_end == address)
93863 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
93864 -
93865 - expand_downwards(vma, address - PAGE_SIZE);
93866 - }
93867 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
93868 - struct vm_area_struct *next = vma->vm_next;
93869 -
93870 - /* As VM_GROWSDOWN but s/below/above/ */
93871 - if (next && next->vm_start == address + PAGE_SIZE)
93872 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
93873 -
93874 - expand_upwards(vma, address + PAGE_SIZE);
93875 - }
93876 - return 0;
93877 -}
93878 -
93879 -/*
93880 * We enter with non-exclusive mmap_sem (to exclude vma changes,
93881 * but allow concurrent faults), and pte mapped but not yet locked.
93882 * We return with mmap_sem still held, but pte unmapped and unlocked.
93883 @@ -3268,27 +3450,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
93884 unsigned long address, pte_t *page_table, pmd_t *pmd,
93885 unsigned int flags)
93886 {
93887 - struct page *page;
93888 + struct page *page = NULL;
93889 spinlock_t *ptl;
93890 pte_t entry;
93891
93892 - pte_unmap(page_table);
93893 -
93894 - /* Check if we need to add a guard page to the stack */
93895 - if (check_stack_guard_page(vma, address) < 0)
93896 - return VM_FAULT_SIGBUS;
93897 -
93898 - /* Use the zero-page for reads */
93899 if (!(flags & FAULT_FLAG_WRITE)) {
93900 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
93901 vma->vm_page_prot));
93902 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
93903 + ptl = pte_lockptr(mm, pmd);
93904 + spin_lock(ptl);
93905 if (!pte_none(*page_table))
93906 goto unlock;
93907 goto setpte;
93908 }
93909
93910 /* Allocate our own private page. */
93911 + pte_unmap(page_table);
93912 +
93913 if (unlikely(anon_vma_prepare(vma)))
93914 goto oom;
93915 page = alloc_zeroed_user_highpage_movable(vma, address);
93916 @@ -3312,6 +3490,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
93917 if (!pte_none(*page_table))
93918 goto release;
93919
93920 +#ifdef CONFIG_PAX_SEGMEXEC
93921 + if (pax_find_mirror_vma(vma))
93922 + BUG_ON(!trylock_page(page));
93923 +#endif
93924 +
93925 inc_mm_counter_fast(mm, MM_ANONPAGES);
93926 page_add_new_anon_rmap(page, vma, address);
93927 setpte:
93928 @@ -3319,6 +3502,12 @@ setpte:
93929
93930 /* No need to invalidate - it was non-present before */
93931 update_mmu_cache(vma, address, page_table);
93932 +
93933 +#ifdef CONFIG_PAX_SEGMEXEC
93934 + if (page)
93935 + pax_mirror_anon_pte(vma, address, page, ptl);
93936 +#endif
93937 +
93938 unlock:
93939 pte_unmap_unlock(page_table, ptl);
93940 return 0;
93941 @@ -3515,7 +3704,8 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93942 * if page by the offset is not ready to be mapped (cold cache or
93943 * something).
93944 */
93945 - if (vma->vm_ops->map_pages && !(flags & FAULT_FLAG_NONLINEAR)) {
93946 + if (vma->vm_ops->map_pages && !(flags & FAULT_FLAG_NONLINEAR) &&
93947 + fault_around_pages() > 1) {
93948 pte = pte_offset_map_lock(mm, pmd, address, &ptl);
93949 do_fault_around(vma, address, pte, pgoff, flags);
93950 if (!pte_same(*pte, orig_pte))
93951 @@ -3535,6 +3725,11 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93952 return ret;
93953 }
93954 do_set_pte(vma, address, fault_page, pte, false, false);
93955 +
93956 +#ifdef CONFIG_PAX_SEGMEXEC
93957 + pax_mirror_file_pte(vma, address, fault_page, ptl);
93958 +#endif
93959 +
93960 unlock_page(fault_page);
93961 unlock_out:
93962 pte_unmap_unlock(pte, ptl);
93963 @@ -3576,7 +3771,18 @@ static int do_cow_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93964 page_cache_release(fault_page);
93965 goto uncharge_out;
93966 }
93967 +
93968 +#ifdef CONFIG_PAX_SEGMEXEC
93969 + if (pax_find_mirror_vma(vma))
93970 + BUG_ON(!trylock_page(new_page));
93971 +#endif
93972 +
93973 do_set_pte(vma, address, new_page, pte, true, true);
93974 +
93975 +#ifdef CONFIG_PAX_SEGMEXEC
93976 + pax_mirror_anon_pte(vma, address, new_page, ptl);
93977 +#endif
93978 +
93979 pte_unmap_unlock(pte, ptl);
93980 unlock_page(fault_page);
93981 page_cache_release(fault_page);
93982 @@ -3624,6 +3830,11 @@ static int do_shared_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93983 return ret;
93984 }
93985 do_set_pte(vma, address, fault_page, pte, true, false);
93986 +
93987 +#ifdef CONFIG_PAX_SEGMEXEC
93988 + pax_mirror_file_pte(vma, address, fault_page, ptl);
93989 +#endif
93990 +
93991 pte_unmap_unlock(pte, ptl);
93992
93993 if (set_page_dirty(fault_page))
93994 @@ -3854,6 +4065,12 @@ static int handle_pte_fault(struct mm_struct *mm,
93995 if (flags & FAULT_FLAG_WRITE)
93996 flush_tlb_fix_spurious_fault(vma, address);
93997 }
93998 +
93999 +#ifdef CONFIG_PAX_SEGMEXEC
94000 + pax_mirror_pte(vma, address, pte, pmd, ptl);
94001 + return 0;
94002 +#endif
94003 +
94004 unlock:
94005 pte_unmap_unlock(pte, ptl);
94006 return 0;
94007 @@ -3870,9 +4087,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
94008 pmd_t *pmd;
94009 pte_t *pte;
94010
94011 +#ifdef CONFIG_PAX_SEGMEXEC
94012 + struct vm_area_struct *vma_m;
94013 +#endif
94014 +
94015 if (unlikely(is_vm_hugetlb_page(vma)))
94016 return hugetlb_fault(mm, vma, address, flags);
94017
94018 +#ifdef CONFIG_PAX_SEGMEXEC
94019 + vma_m = pax_find_mirror_vma(vma);
94020 + if (vma_m) {
94021 + unsigned long address_m;
94022 + pgd_t *pgd_m;
94023 + pud_t *pud_m;
94024 + pmd_t *pmd_m;
94025 +
94026 + if (vma->vm_start > vma_m->vm_start) {
94027 + address_m = address;
94028 + address -= SEGMEXEC_TASK_SIZE;
94029 + vma = vma_m;
94030 + } else
94031 + address_m = address + SEGMEXEC_TASK_SIZE;
94032 +
94033 + pgd_m = pgd_offset(mm, address_m);
94034 + pud_m = pud_alloc(mm, pgd_m, address_m);
94035 + if (!pud_m)
94036 + return VM_FAULT_OOM;
94037 + pmd_m = pmd_alloc(mm, pud_m, address_m);
94038 + if (!pmd_m)
94039 + return VM_FAULT_OOM;
94040 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
94041 + return VM_FAULT_OOM;
94042 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
94043 + }
94044 +#endif
94045 +
94046 pgd = pgd_offset(mm, address);
94047 pud = pud_alloc(mm, pgd, address);
94048 if (!pud)
94049 @@ -4000,6 +4249,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
94050 spin_unlock(&mm->page_table_lock);
94051 return 0;
94052 }
94053 +
94054 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
94055 +{
94056 + pud_t *new = pud_alloc_one(mm, address);
94057 + if (!new)
94058 + return -ENOMEM;
94059 +
94060 + smp_wmb(); /* See comment in __pte_alloc */
94061 +
94062 + spin_lock(&mm->page_table_lock);
94063 + if (pgd_present(*pgd)) /* Another has populated it */
94064 + pud_free(mm, new);
94065 + else
94066 + pgd_populate_kernel(mm, pgd, new);
94067 + spin_unlock(&mm->page_table_lock);
94068 + return 0;
94069 +}
94070 #endif /* __PAGETABLE_PUD_FOLDED */
94071
94072 #ifndef __PAGETABLE_PMD_FOLDED
94073 @@ -4030,6 +4296,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
94074 spin_unlock(&mm->page_table_lock);
94075 return 0;
94076 }
94077 +
94078 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
94079 +{
94080 + pmd_t *new = pmd_alloc_one(mm, address);
94081 + if (!new)
94082 + return -ENOMEM;
94083 +
94084 + smp_wmb(); /* See comment in __pte_alloc */
94085 +
94086 + spin_lock(&mm->page_table_lock);
94087 +#ifndef __ARCH_HAS_4LEVEL_HACK
94088 + if (pud_present(*pud)) /* Another has populated it */
94089 + pmd_free(mm, new);
94090 + else
94091 + pud_populate_kernel(mm, pud, new);
94092 +#else
94093 + if (pgd_present(*pud)) /* Another has populated it */
94094 + pmd_free(mm, new);
94095 + else
94096 + pgd_populate_kernel(mm, pud, new);
94097 +#endif /* __ARCH_HAS_4LEVEL_HACK */
94098 + spin_unlock(&mm->page_table_lock);
94099 + return 0;
94100 +}
94101 #endif /* __PAGETABLE_PMD_FOLDED */
94102
94103 #if !defined(__HAVE_ARCH_GATE_AREA)
94104 @@ -4043,7 +4333,7 @@ static int __init gate_vma_init(void)
94105 gate_vma.vm_start = FIXADDR_USER_START;
94106 gate_vma.vm_end = FIXADDR_USER_END;
94107 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
94108 - gate_vma.vm_page_prot = __P101;
94109 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
94110
94111 return 0;
94112 }
94113 @@ -4177,8 +4467,8 @@ out:
94114 return ret;
94115 }
94116
94117 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
94118 - void *buf, int len, int write)
94119 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
94120 + void *buf, size_t len, int write)
94121 {
94122 resource_size_t phys_addr;
94123 unsigned long prot = 0;
94124 @@ -4204,8 +4494,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
94125 * Access another process' address space as given in mm. If non-NULL, use the
94126 * given task for page fault accounting.
94127 */
94128 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94129 - unsigned long addr, void *buf, int len, int write)
94130 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94131 + unsigned long addr, void *buf, size_t len, int write)
94132 {
94133 struct vm_area_struct *vma;
94134 void *old_buf = buf;
94135 @@ -4213,7 +4503,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94136 down_read(&mm->mmap_sem);
94137 /* ignore errors, just check how much was successfully transferred */
94138 while (len) {
94139 - int bytes, ret, offset;
94140 + ssize_t bytes, ret, offset;
94141 void *maddr;
94142 struct page *page = NULL;
94143
94144 @@ -4272,8 +4562,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94145 *
94146 * The caller must hold a reference on @mm.
94147 */
94148 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
94149 - void *buf, int len, int write)
94150 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
94151 + void *buf, size_t len, int write)
94152 {
94153 return __access_remote_vm(NULL, mm, addr, buf, len, write);
94154 }
94155 @@ -4283,11 +4573,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
94156 * Source/target buffer must be kernel space,
94157 * Do not walk the page table directly, use get_user_pages
94158 */
94159 -int access_process_vm(struct task_struct *tsk, unsigned long addr,
94160 - void *buf, int len, int write)
94161 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
94162 + void *buf, size_t len, int write)
94163 {
94164 struct mm_struct *mm;
94165 - int ret;
94166 + ssize_t ret;
94167
94168 mm = get_task_mm(tsk);
94169 if (!mm)
94170 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
94171 index 6b65d10..e6f415a 100644
94172 --- a/mm/mempolicy.c
94173 +++ b/mm/mempolicy.c
94174 @@ -747,6 +747,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
94175 unsigned long vmstart;
94176 unsigned long vmend;
94177
94178 +#ifdef CONFIG_PAX_SEGMEXEC
94179 + struct vm_area_struct *vma_m;
94180 +#endif
94181 +
94182 vma = find_vma(mm, start);
94183 if (!vma || vma->vm_start > start)
94184 return -EFAULT;
94185 @@ -790,6 +794,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
94186 err = vma_replace_policy(vma, new_pol);
94187 if (err)
94188 goto out;
94189 +
94190 +#ifdef CONFIG_PAX_SEGMEXEC
94191 + vma_m = pax_find_mirror_vma(vma);
94192 + if (vma_m) {
94193 + err = vma_replace_policy(vma_m, new_pol);
94194 + if (err)
94195 + goto out;
94196 + }
94197 +#endif
94198 +
94199 }
94200
94201 out:
94202 @@ -1222,6 +1236,17 @@ static long do_mbind(unsigned long start, unsigned long len,
94203
94204 if (end < start)
94205 return -EINVAL;
94206 +
94207 +#ifdef CONFIG_PAX_SEGMEXEC
94208 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
94209 + if (end > SEGMEXEC_TASK_SIZE)
94210 + return -EINVAL;
94211 + } else
94212 +#endif
94213 +
94214 + if (end > TASK_SIZE)
94215 + return -EINVAL;
94216 +
94217 if (end == start)
94218 return 0;
94219
94220 @@ -1447,8 +1472,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
94221 */
94222 tcred = __task_cred(task);
94223 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
94224 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
94225 - !capable(CAP_SYS_NICE)) {
94226 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
94227 rcu_read_unlock();
94228 err = -EPERM;
94229 goto out_put;
94230 @@ -1479,6 +1503,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
94231 goto out;
94232 }
94233
94234 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
94235 + if (mm != current->mm &&
94236 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
94237 + mmput(mm);
94238 + err = -EPERM;
94239 + goto out;
94240 + }
94241 +#endif
94242 +
94243 err = do_migrate_pages(mm, old, new,
94244 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
94245
94246 diff --git a/mm/migrate.c b/mm/migrate.c
94247 index bed4880..a493f67 100644
94248 --- a/mm/migrate.c
94249 +++ b/mm/migrate.c
94250 @@ -1485,8 +1485,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
94251 */
94252 tcred = __task_cred(task);
94253 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
94254 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
94255 - !capable(CAP_SYS_NICE)) {
94256 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
94257 rcu_read_unlock();
94258 err = -EPERM;
94259 goto out;
94260 diff --git a/mm/mlock.c b/mm/mlock.c
94261 index b1eb536..091d154 100644
94262 --- a/mm/mlock.c
94263 +++ b/mm/mlock.c
94264 @@ -14,6 +14,7 @@
94265 #include <linux/pagevec.h>
94266 #include <linux/mempolicy.h>
94267 #include <linux/syscalls.h>
94268 +#include <linux/security.h>
94269 #include <linux/sched.h>
94270 #include <linux/export.h>
94271 #include <linux/rmap.h>
94272 @@ -606,7 +607,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
94273 {
94274 unsigned long nstart, end, tmp;
94275 struct vm_area_struct * vma, * prev;
94276 - int error;
94277 + int error = 0;
94278
94279 VM_BUG_ON(start & ~PAGE_MASK);
94280 VM_BUG_ON(len != PAGE_ALIGN(len));
94281 @@ -615,6 +616,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
94282 return -EINVAL;
94283 if (end == start)
94284 return 0;
94285 + if (end > TASK_SIZE)
94286 + return -EINVAL;
94287 +
94288 vma = find_vma(current->mm, start);
94289 if (!vma || vma->vm_start > start)
94290 return -ENOMEM;
94291 @@ -626,6 +630,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
94292 for (nstart = start ; ; ) {
94293 vm_flags_t newflags;
94294
94295 +#ifdef CONFIG_PAX_SEGMEXEC
94296 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
94297 + break;
94298 +#endif
94299 +
94300 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
94301
94302 newflags = vma->vm_flags & ~VM_LOCKED;
94303 @@ -739,6 +748,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
94304 locked += current->mm->locked_vm;
94305
94306 /* check against resource limits */
94307 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
94308 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
94309 error = do_mlock(start, len, 1);
94310
94311 @@ -776,6 +786,11 @@ static int do_mlockall(int flags)
94312 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
94313 vm_flags_t newflags;
94314
94315 +#ifdef CONFIG_PAX_SEGMEXEC
94316 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
94317 + break;
94318 +#endif
94319 +
94320 newflags = vma->vm_flags & ~VM_LOCKED;
94321 if (flags & MCL_CURRENT)
94322 newflags |= VM_LOCKED;
94323 @@ -807,8 +822,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
94324 lock_limit >>= PAGE_SHIFT;
94325
94326 ret = -ENOMEM;
94327 +
94328 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
94329 +
94330 down_write(&current->mm->mmap_sem);
94331 -
94332 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
94333 capable(CAP_IPC_LOCK))
94334 ret = do_mlockall(flags);
94335 diff --git a/mm/mmap.c b/mm/mmap.c
94336 index b1202cf..ee487f8 100644
94337 --- a/mm/mmap.c
94338 +++ b/mm/mmap.c
94339 @@ -37,6 +37,7 @@
94340 #include <linux/sched/sysctl.h>
94341 #include <linux/notifier.h>
94342 #include <linux/memory.h>
94343 +#include <linux/random.h>
94344
94345 #include <asm/uaccess.h>
94346 #include <asm/cacheflush.h>
94347 @@ -53,6 +54,16 @@
94348 #define arch_rebalance_pgtables(addr, len) (addr)
94349 #endif
94350
94351 +static inline void verify_mm_writelocked(struct mm_struct *mm)
94352 +{
94353 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
94354 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
94355 + up_read(&mm->mmap_sem);
94356 + BUG();
94357 + }
94358 +#endif
94359 +}
94360 +
94361 static void unmap_region(struct mm_struct *mm,
94362 struct vm_area_struct *vma, struct vm_area_struct *prev,
94363 unsigned long start, unsigned long end);
94364 @@ -72,16 +83,25 @@ static void unmap_region(struct mm_struct *mm,
94365 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
94366 *
94367 */
94368 -pgprot_t protection_map[16] = {
94369 +pgprot_t protection_map[16] __read_only = {
94370 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
94371 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
94372 };
94373
94374 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
94375 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
94376 {
94377 - return __pgprot(pgprot_val(protection_map[vm_flags &
94378 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
94379 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
94380 pgprot_val(arch_vm_get_page_prot(vm_flags)));
94381 +
94382 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
94383 + if (!(__supported_pte_mask & _PAGE_NX) &&
94384 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
94385 + (vm_flags & (VM_READ | VM_WRITE)))
94386 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
94387 +#endif
94388 +
94389 + return prot;
94390 }
94391 EXPORT_SYMBOL(vm_get_page_prot);
94392
94393 @@ -91,6 +111,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
94394 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
94395 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
94396 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
94397 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
94398 /*
94399 * Make sure vm_committed_as in one cacheline and not cacheline shared with
94400 * other variables. It can be updated by several CPUs frequently.
94401 @@ -247,6 +268,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
94402 struct vm_area_struct *next = vma->vm_next;
94403
94404 might_sleep();
94405 + BUG_ON(vma->vm_mirror);
94406 if (vma->vm_ops && vma->vm_ops->close)
94407 vma->vm_ops->close(vma);
94408 if (vma->vm_file)
94409 @@ -291,6 +313,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
94410 * not page aligned -Ram Gupta
94411 */
94412 rlim = rlimit(RLIMIT_DATA);
94413 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
94414 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
94415 (mm->end_data - mm->start_data) > rlim)
94416 goto out;
94417 @@ -942,6 +965,12 @@ static int
94418 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
94419 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
94420 {
94421 +
94422 +#ifdef CONFIG_PAX_SEGMEXEC
94423 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
94424 + return 0;
94425 +#endif
94426 +
94427 if (is_mergeable_vma(vma, file, vm_flags) &&
94428 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
94429 if (vma->vm_pgoff == vm_pgoff)
94430 @@ -961,6 +990,12 @@ static int
94431 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
94432 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
94433 {
94434 +
94435 +#ifdef CONFIG_PAX_SEGMEXEC
94436 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
94437 + return 0;
94438 +#endif
94439 +
94440 if (is_mergeable_vma(vma, file, vm_flags) &&
94441 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
94442 pgoff_t vm_pglen;
94443 @@ -1003,13 +1038,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
94444 struct vm_area_struct *vma_merge(struct mm_struct *mm,
94445 struct vm_area_struct *prev, unsigned long addr,
94446 unsigned long end, unsigned long vm_flags,
94447 - struct anon_vma *anon_vma, struct file *file,
94448 + struct anon_vma *anon_vma, struct file *file,
94449 pgoff_t pgoff, struct mempolicy *policy)
94450 {
94451 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
94452 struct vm_area_struct *area, *next;
94453 int err;
94454
94455 +#ifdef CONFIG_PAX_SEGMEXEC
94456 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
94457 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
94458 +
94459 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
94460 +#endif
94461 +
94462 /*
94463 * We later require that vma->vm_flags == vm_flags,
94464 * so this tests vma->vm_flags & VM_SPECIAL, too.
94465 @@ -1025,6 +1067,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
94466 if (next && next->vm_end == end) /* cases 6, 7, 8 */
94467 next = next->vm_next;
94468
94469 +#ifdef CONFIG_PAX_SEGMEXEC
94470 + if (prev)
94471 + prev_m = pax_find_mirror_vma(prev);
94472 + if (area)
94473 + area_m = pax_find_mirror_vma(area);
94474 + if (next)
94475 + next_m = pax_find_mirror_vma(next);
94476 +#endif
94477 +
94478 /*
94479 * Can it merge with the predecessor?
94480 */
94481 @@ -1044,9 +1095,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
94482 /* cases 1, 6 */
94483 err = vma_adjust(prev, prev->vm_start,
94484 next->vm_end, prev->vm_pgoff, NULL);
94485 - } else /* cases 2, 5, 7 */
94486 +
94487 +#ifdef CONFIG_PAX_SEGMEXEC
94488 + if (!err && prev_m)
94489 + err = vma_adjust(prev_m, prev_m->vm_start,
94490 + next_m->vm_end, prev_m->vm_pgoff, NULL);
94491 +#endif
94492 +
94493 + } else { /* cases 2, 5, 7 */
94494 err = vma_adjust(prev, prev->vm_start,
94495 end, prev->vm_pgoff, NULL);
94496 +
94497 +#ifdef CONFIG_PAX_SEGMEXEC
94498 + if (!err && prev_m)
94499 + err = vma_adjust(prev_m, prev_m->vm_start,
94500 + end_m, prev_m->vm_pgoff, NULL);
94501 +#endif
94502 +
94503 + }
94504 if (err)
94505 return NULL;
94506 khugepaged_enter_vma_merge(prev);
94507 @@ -1060,12 +1126,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
94508 mpol_equal(policy, vma_policy(next)) &&
94509 can_vma_merge_before(next, vm_flags,
94510 anon_vma, file, pgoff+pglen)) {
94511 - if (prev && addr < prev->vm_end) /* case 4 */
94512 + if (prev && addr < prev->vm_end) { /* case 4 */
94513 err = vma_adjust(prev, prev->vm_start,
94514 addr, prev->vm_pgoff, NULL);
94515 - else /* cases 3, 8 */
94516 +
94517 +#ifdef CONFIG_PAX_SEGMEXEC
94518 + if (!err && prev_m)
94519 + err = vma_adjust(prev_m, prev_m->vm_start,
94520 + addr_m, prev_m->vm_pgoff, NULL);
94521 +#endif
94522 +
94523 + } else { /* cases 3, 8 */
94524 err = vma_adjust(area, addr, next->vm_end,
94525 next->vm_pgoff - pglen, NULL);
94526 +
94527 +#ifdef CONFIG_PAX_SEGMEXEC
94528 + if (!err && area_m)
94529 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
94530 + next_m->vm_pgoff - pglen, NULL);
94531 +#endif
94532 +
94533 + }
94534 if (err)
94535 return NULL;
94536 khugepaged_enter_vma_merge(area);
94537 @@ -1174,8 +1255,10 @@ none:
94538 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
94539 struct file *file, long pages)
94540 {
94541 - const unsigned long stack_flags
94542 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
94543 +
94544 +#ifdef CONFIG_PAX_RANDMMAP
94545 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
94546 +#endif
94547
94548 mm->total_vm += pages;
94549
94550 @@ -1183,7 +1266,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
94551 mm->shared_vm += pages;
94552 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
94553 mm->exec_vm += pages;
94554 - } else if (flags & stack_flags)
94555 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
94556 mm->stack_vm += pages;
94557 }
94558 #endif /* CONFIG_PROC_FS */
94559 @@ -1213,6 +1296,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
94560 locked += mm->locked_vm;
94561 lock_limit = rlimit(RLIMIT_MEMLOCK);
94562 lock_limit >>= PAGE_SHIFT;
94563 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
94564 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
94565 return -EAGAIN;
94566 }
94567 @@ -1239,7 +1323,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
94568 * (the exception is when the underlying filesystem is noexec
94569 * mounted, in which case we dont add PROT_EXEC.)
94570 */
94571 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
94572 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
94573 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
94574 prot |= PROT_EXEC;
94575
94576 @@ -1265,7 +1349,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
94577 /* Obtain the address to map to. we verify (or select) it and ensure
94578 * that it represents a valid section of the address space.
94579 */
94580 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
94581 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
94582 if (addr & ~PAGE_MASK)
94583 return addr;
94584
94585 @@ -1276,6 +1360,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
94586 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
94587 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
94588
94589 +#ifdef CONFIG_PAX_MPROTECT
94590 + if (mm->pax_flags & MF_PAX_MPROTECT) {
94591 +
94592 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
94593 + if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
94594 + mm->binfmt->handle_mmap)
94595 + mm->binfmt->handle_mmap(file);
94596 +#endif
94597 +
94598 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
94599 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
94600 + gr_log_rwxmmap(file);
94601 +
94602 +#ifdef CONFIG_PAX_EMUPLT
94603 + vm_flags &= ~VM_EXEC;
94604 +#else
94605 + return -EPERM;
94606 +#endif
94607 +
94608 + }
94609 +
94610 + if (!(vm_flags & VM_EXEC))
94611 + vm_flags &= ~VM_MAYEXEC;
94612 +#else
94613 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
94614 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
94615 +#endif
94616 + else
94617 + vm_flags &= ~VM_MAYWRITE;
94618 + }
94619 +#endif
94620 +
94621 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
94622 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
94623 + vm_flags &= ~VM_PAGEEXEC;
94624 +#endif
94625 +
94626 if (flags & MAP_LOCKED)
94627 if (!can_do_mlock())
94628 return -EPERM;
94629 @@ -1363,6 +1484,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
94630 vm_flags |= VM_NORESERVE;
94631 }
94632
94633 + if (!gr_acl_handle_mmap(file, prot))
94634 + return -EACCES;
94635 +
94636 addr = mmap_region(file, addr, len, vm_flags, pgoff);
94637 if (!IS_ERR_VALUE(addr) &&
94638 ((vm_flags & VM_LOCKED) ||
94639 @@ -1456,7 +1580,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
94640 vm_flags_t vm_flags = vma->vm_flags;
94641
94642 /* If it was private or non-writable, the write bit is already clear */
94643 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
94644 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
94645 return 0;
94646
94647 /* The backer wishes to know when pages are first written to? */
94648 @@ -1502,7 +1626,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
94649 struct rb_node **rb_link, *rb_parent;
94650 unsigned long charged = 0;
94651
94652 +#ifdef CONFIG_PAX_SEGMEXEC
94653 + struct vm_area_struct *vma_m = NULL;
94654 +#endif
94655 +
94656 + /*
94657 + * mm->mmap_sem is required to protect against another thread
94658 + * changing the mappings in case we sleep.
94659 + */
94660 + verify_mm_writelocked(mm);
94661 +
94662 /* Check against address space limit. */
94663 +
94664 +#ifdef CONFIG_PAX_RANDMMAP
94665 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
94666 +#endif
94667 +
94668 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
94669 unsigned long nr_pages;
94670
94671 @@ -1521,11 +1660,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
94672
94673 /* Clear old maps */
94674 error = -ENOMEM;
94675 -munmap_back:
94676 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
94677 if (do_munmap(mm, addr, len))
94678 return -ENOMEM;
94679 - goto munmap_back;
94680 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
94681 }
94682
94683 /*
94684 @@ -1556,6 +1694,16 @@ munmap_back:
94685 goto unacct_error;
94686 }
94687
94688 +#ifdef CONFIG_PAX_SEGMEXEC
94689 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
94690 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94691 + if (!vma_m) {
94692 + error = -ENOMEM;
94693 + goto free_vma;
94694 + }
94695 + }
94696 +#endif
94697 +
94698 vma->vm_mm = mm;
94699 vma->vm_start = addr;
94700 vma->vm_end = addr + len;
94701 @@ -1575,6 +1723,13 @@ munmap_back:
94702 if (error)
94703 goto unmap_and_free_vma;
94704
94705 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
94706 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
94707 + vma->vm_flags |= VM_PAGEEXEC;
94708 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
94709 + }
94710 +#endif
94711 +
94712 /* Can addr have changed??
94713 *
94714 * Answer: Yes, several device drivers can do it in their
94715 @@ -1608,6 +1763,12 @@ munmap_back:
94716 }
94717
94718 vma_link(mm, vma, prev, rb_link, rb_parent);
94719 +
94720 +#ifdef CONFIG_PAX_SEGMEXEC
94721 + if (vma_m)
94722 + BUG_ON(pax_mirror_vma(vma_m, vma));
94723 +#endif
94724 +
94725 /* Once vma denies write, undo our temporary denial count */
94726 if (vm_flags & VM_DENYWRITE)
94727 allow_write_access(file);
94728 @@ -1616,6 +1777,7 @@ out:
94729 perf_event_mmap(vma);
94730
94731 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
94732 + track_exec_limit(mm, addr, addr + len, vm_flags);
94733 if (vm_flags & VM_LOCKED) {
94734 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
94735 vma == get_gate_vma(current->mm)))
94736 @@ -1648,6 +1810,12 @@ unmap_and_free_vma:
94737 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
94738 charged = 0;
94739 free_vma:
94740 +
94741 +#ifdef CONFIG_PAX_SEGMEXEC
94742 + if (vma_m)
94743 + kmem_cache_free(vm_area_cachep, vma_m);
94744 +#endif
94745 +
94746 kmem_cache_free(vm_area_cachep, vma);
94747 unacct_error:
94748 if (charged)
94749 @@ -1655,7 +1823,63 @@ unacct_error:
94750 return error;
94751 }
94752
94753 -unsigned long unmapped_area(struct vm_unmapped_area_info *info)
94754 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
94755 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
94756 +{
94757 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
94758 + return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
94759 +
94760 + return 0;
94761 +}
94762 +#endif
94763 +
94764 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
94765 +{
94766 + if (!vma) {
94767 +#ifdef CONFIG_STACK_GROWSUP
94768 + if (addr > sysctl_heap_stack_gap)
94769 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
94770 + else
94771 + vma = find_vma(current->mm, 0);
94772 + if (vma && (vma->vm_flags & VM_GROWSUP))
94773 + return false;
94774 +#endif
94775 + return true;
94776 + }
94777 +
94778 + if (addr + len > vma->vm_start)
94779 + return false;
94780 +
94781 + if (vma->vm_flags & VM_GROWSDOWN)
94782 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
94783 +#ifdef CONFIG_STACK_GROWSUP
94784 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
94785 + return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
94786 +#endif
94787 + else if (offset)
94788 + return offset <= vma->vm_start - addr - len;
94789 +
94790 + return true;
94791 +}
94792 +
94793 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
94794 +{
94795 + if (vma->vm_start < len)
94796 + return -ENOMEM;
94797 +
94798 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
94799 + if (offset <= vma->vm_start - len)
94800 + return vma->vm_start - len - offset;
94801 + else
94802 + return -ENOMEM;
94803 + }
94804 +
94805 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
94806 + return vma->vm_start - len - sysctl_heap_stack_gap;
94807 + return -ENOMEM;
94808 +}
94809 +
94810 +unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
94811 {
94812 /*
94813 * We implement the search by looking for an rbtree node that
94814 @@ -1703,11 +1927,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
94815 }
94816 }
94817
94818 - gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
94819 + gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
94820 check_current:
94821 /* Check if current node has a suitable gap */
94822 if (gap_start > high_limit)
94823 return -ENOMEM;
94824 +
94825 + if (gap_end - gap_start > info->threadstack_offset)
94826 + gap_start += info->threadstack_offset;
94827 + else
94828 + gap_start = gap_end;
94829 +
94830 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
94831 + if (gap_end - gap_start > sysctl_heap_stack_gap)
94832 + gap_start += sysctl_heap_stack_gap;
94833 + else
94834 + gap_start = gap_end;
94835 + }
94836 + if (vma->vm_flags & VM_GROWSDOWN) {
94837 + if (gap_end - gap_start > sysctl_heap_stack_gap)
94838 + gap_end -= sysctl_heap_stack_gap;
94839 + else
94840 + gap_end = gap_start;
94841 + }
94842 if (gap_end >= low_limit && gap_end - gap_start >= length)
94843 goto found;
94844
94845 @@ -1757,7 +1999,7 @@ found:
94846 return gap_start;
94847 }
94848
94849 -unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
94850 +unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
94851 {
94852 struct mm_struct *mm = current->mm;
94853 struct vm_area_struct *vma;
94854 @@ -1811,6 +2053,24 @@ check_current:
94855 gap_end = vma->vm_start;
94856 if (gap_end < low_limit)
94857 return -ENOMEM;
94858 +
94859 + if (gap_end - gap_start > info->threadstack_offset)
94860 + gap_end -= info->threadstack_offset;
94861 + else
94862 + gap_end = gap_start;
94863 +
94864 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
94865 + if (gap_end - gap_start > sysctl_heap_stack_gap)
94866 + gap_start += sysctl_heap_stack_gap;
94867 + else
94868 + gap_start = gap_end;
94869 + }
94870 + if (vma->vm_flags & VM_GROWSDOWN) {
94871 + if (gap_end - gap_start > sysctl_heap_stack_gap)
94872 + gap_end -= sysctl_heap_stack_gap;
94873 + else
94874 + gap_end = gap_start;
94875 + }
94876 if (gap_start <= high_limit && gap_end - gap_start >= length)
94877 goto found;
94878
94879 @@ -1874,6 +2134,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94880 struct mm_struct *mm = current->mm;
94881 struct vm_area_struct *vma;
94882 struct vm_unmapped_area_info info;
94883 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
94884
94885 if (len > TASK_SIZE - mmap_min_addr)
94886 return -ENOMEM;
94887 @@ -1881,11 +2142,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94888 if (flags & MAP_FIXED)
94889 return addr;
94890
94891 +#ifdef CONFIG_PAX_RANDMMAP
94892 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
94893 +#endif
94894 +
94895 if (addr) {
94896 addr = PAGE_ALIGN(addr);
94897 vma = find_vma(mm, addr);
94898 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
94899 - (!vma || addr + len <= vma->vm_start))
94900 + check_heap_stack_gap(vma, addr, len, offset))
94901 return addr;
94902 }
94903
94904 @@ -1894,6 +2159,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94905 info.low_limit = mm->mmap_base;
94906 info.high_limit = TASK_SIZE;
94907 info.align_mask = 0;
94908 + info.threadstack_offset = offset;
94909 return vm_unmapped_area(&info);
94910 }
94911 #endif
94912 @@ -1912,6 +2178,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94913 struct mm_struct *mm = current->mm;
94914 unsigned long addr = addr0;
94915 struct vm_unmapped_area_info info;
94916 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
94917
94918 /* requested length too big for entire address space */
94919 if (len > TASK_SIZE - mmap_min_addr)
94920 @@ -1920,12 +2187,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94921 if (flags & MAP_FIXED)
94922 return addr;
94923
94924 +#ifdef CONFIG_PAX_RANDMMAP
94925 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
94926 +#endif
94927 +
94928 /* requesting a specific address */
94929 if (addr) {
94930 addr = PAGE_ALIGN(addr);
94931 vma = find_vma(mm, addr);
94932 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
94933 - (!vma || addr + len <= vma->vm_start))
94934 + check_heap_stack_gap(vma, addr, len, offset))
94935 return addr;
94936 }
94937
94938 @@ -1934,6 +2205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94939 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
94940 info.high_limit = mm->mmap_base;
94941 info.align_mask = 0;
94942 + info.threadstack_offset = offset;
94943 addr = vm_unmapped_area(&info);
94944
94945 /*
94946 @@ -1946,6 +2218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94947 VM_BUG_ON(addr != -ENOMEM);
94948 info.flags = 0;
94949 info.low_limit = TASK_UNMAPPED_BASE;
94950 +
94951 +#ifdef CONFIG_PAX_RANDMMAP
94952 + if (mm->pax_flags & MF_PAX_RANDMMAP)
94953 + info.low_limit += mm->delta_mmap;
94954 +#endif
94955 +
94956 info.high_limit = TASK_SIZE;
94957 addr = vm_unmapped_area(&info);
94958 }
94959 @@ -2046,6 +2324,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
94960 return vma;
94961 }
94962
94963 +#ifdef CONFIG_PAX_SEGMEXEC
94964 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
94965 +{
94966 + struct vm_area_struct *vma_m;
94967 +
94968 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
94969 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
94970 + BUG_ON(vma->vm_mirror);
94971 + return NULL;
94972 + }
94973 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
94974 + vma_m = vma->vm_mirror;
94975 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
94976 + BUG_ON(vma->vm_file != vma_m->vm_file);
94977 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
94978 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
94979 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
94980 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
94981 + return vma_m;
94982 +}
94983 +#endif
94984 +
94985 /*
94986 * Verify that the stack growth is acceptable and
94987 * update accounting. This is shared with both the
94988 @@ -2062,6 +2362,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94989 return -ENOMEM;
94990
94991 /* Stack limit test */
94992 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
94993 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
94994 return -ENOMEM;
94995
94996 @@ -2072,6 +2373,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94997 locked = mm->locked_vm + grow;
94998 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
94999 limit >>= PAGE_SHIFT;
95000 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
95001 if (locked > limit && !capable(CAP_IPC_LOCK))
95002 return -ENOMEM;
95003 }
95004 @@ -2101,37 +2403,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
95005 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
95006 * vma is the last one with address > vma->vm_end. Have to extend vma.
95007 */
95008 +#ifndef CONFIG_IA64
95009 +static
95010 +#endif
95011 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
95012 {
95013 int error;
95014 + bool locknext;
95015
95016 if (!(vma->vm_flags & VM_GROWSUP))
95017 return -EFAULT;
95018
95019 + /* Also guard against wrapping around to address 0. */
95020 + if (address < PAGE_ALIGN(address+1))
95021 + address = PAGE_ALIGN(address+1);
95022 + else
95023 + return -ENOMEM;
95024 +
95025 /*
95026 * We must make sure the anon_vma is allocated
95027 * so that the anon_vma locking is not a noop.
95028 */
95029 if (unlikely(anon_vma_prepare(vma)))
95030 return -ENOMEM;
95031 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
95032 + if (locknext && anon_vma_prepare(vma->vm_next))
95033 + return -ENOMEM;
95034 vma_lock_anon_vma(vma);
95035 + if (locknext)
95036 + vma_lock_anon_vma(vma->vm_next);
95037
95038 /*
95039 * vma->vm_start/vm_end cannot change under us because the caller
95040 * is required to hold the mmap_sem in read mode. We need the
95041 - * anon_vma lock to serialize against concurrent expand_stacks.
95042 - * Also guard against wrapping around to address 0.
95043 + * anon_vma locks to serialize against concurrent expand_stacks
95044 + * and expand_upwards.
95045 */
95046 - if (address < PAGE_ALIGN(address+4))
95047 - address = PAGE_ALIGN(address+4);
95048 - else {
95049 - vma_unlock_anon_vma(vma);
95050 - return -ENOMEM;
95051 - }
95052 error = 0;
95053
95054 /* Somebody else might have raced and expanded it already */
95055 - if (address > vma->vm_end) {
95056 + 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)
95057 + error = -ENOMEM;
95058 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
95059 unsigned long size, grow;
95060
95061 size = address - vma->vm_start;
95062 @@ -2166,6 +2479,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
95063 }
95064 }
95065 }
95066 + if (locknext)
95067 + vma_unlock_anon_vma(vma->vm_next);
95068 vma_unlock_anon_vma(vma);
95069 khugepaged_enter_vma_merge(vma);
95070 validate_mm(vma->vm_mm);
95071 @@ -2180,6 +2495,8 @@ int expand_downwards(struct vm_area_struct *vma,
95072 unsigned long address)
95073 {
95074 int error;
95075 + bool lockprev = false;
95076 + struct vm_area_struct *prev;
95077
95078 /*
95079 * We must make sure the anon_vma is allocated
95080 @@ -2193,6 +2510,15 @@ int expand_downwards(struct vm_area_struct *vma,
95081 if (error)
95082 return error;
95083
95084 + prev = vma->vm_prev;
95085 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
95086 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
95087 +#endif
95088 + if (lockprev && anon_vma_prepare(prev))
95089 + return -ENOMEM;
95090 + if (lockprev)
95091 + vma_lock_anon_vma(prev);
95092 +
95093 vma_lock_anon_vma(vma);
95094
95095 /*
95096 @@ -2202,9 +2528,17 @@ int expand_downwards(struct vm_area_struct *vma,
95097 */
95098
95099 /* Somebody else might have raced and expanded it already */
95100 - if (address < vma->vm_start) {
95101 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
95102 + error = -ENOMEM;
95103 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
95104 unsigned long size, grow;
95105
95106 +#ifdef CONFIG_PAX_SEGMEXEC
95107 + struct vm_area_struct *vma_m;
95108 +
95109 + vma_m = pax_find_mirror_vma(vma);
95110 +#endif
95111 +
95112 size = vma->vm_end - address;
95113 grow = (vma->vm_start - address) >> PAGE_SHIFT;
95114
95115 @@ -2229,13 +2563,27 @@ int expand_downwards(struct vm_area_struct *vma,
95116 vma->vm_pgoff -= grow;
95117 anon_vma_interval_tree_post_update_vma(vma);
95118 vma_gap_update(vma);
95119 +
95120 +#ifdef CONFIG_PAX_SEGMEXEC
95121 + if (vma_m) {
95122 + anon_vma_interval_tree_pre_update_vma(vma_m);
95123 + vma_m->vm_start -= grow << PAGE_SHIFT;
95124 + vma_m->vm_pgoff -= grow;
95125 + anon_vma_interval_tree_post_update_vma(vma_m);
95126 + vma_gap_update(vma_m);
95127 + }
95128 +#endif
95129 +
95130 spin_unlock(&vma->vm_mm->page_table_lock);
95131
95132 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
95133 perf_event_mmap(vma);
95134 }
95135 }
95136 }
95137 vma_unlock_anon_vma(vma);
95138 + if (lockprev)
95139 + vma_unlock_anon_vma(prev);
95140 khugepaged_enter_vma_merge(vma);
95141 validate_mm(vma->vm_mm);
95142 return error;
95143 @@ -2333,6 +2681,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
95144 do {
95145 long nrpages = vma_pages(vma);
95146
95147 +#ifdef CONFIG_PAX_SEGMEXEC
95148 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
95149 + vma = remove_vma(vma);
95150 + continue;
95151 + }
95152 +#endif
95153 +
95154 if (vma->vm_flags & VM_ACCOUNT)
95155 nr_accounted += nrpages;
95156 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
95157 @@ -2377,6 +2732,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
95158 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
95159 vma->vm_prev = NULL;
95160 do {
95161 +
95162 +#ifdef CONFIG_PAX_SEGMEXEC
95163 + if (vma->vm_mirror) {
95164 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
95165 + vma->vm_mirror->vm_mirror = NULL;
95166 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
95167 + vma->vm_mirror = NULL;
95168 + }
95169 +#endif
95170 +
95171 vma_rb_erase(vma, &mm->mm_rb);
95172 mm->map_count--;
95173 tail_vma = vma;
95174 @@ -2404,14 +2769,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
95175 struct vm_area_struct *new;
95176 int err = -ENOMEM;
95177
95178 +#ifdef CONFIG_PAX_SEGMEXEC
95179 + struct vm_area_struct *vma_m, *new_m = NULL;
95180 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
95181 +#endif
95182 +
95183 if (is_vm_hugetlb_page(vma) && (addr &
95184 ~(huge_page_mask(hstate_vma(vma)))))
95185 return -EINVAL;
95186
95187 +#ifdef CONFIG_PAX_SEGMEXEC
95188 + vma_m = pax_find_mirror_vma(vma);
95189 +#endif
95190 +
95191 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
95192 if (!new)
95193 goto out_err;
95194
95195 +#ifdef CONFIG_PAX_SEGMEXEC
95196 + if (vma_m) {
95197 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
95198 + if (!new_m) {
95199 + kmem_cache_free(vm_area_cachep, new);
95200 + goto out_err;
95201 + }
95202 + }
95203 +#endif
95204 +
95205 /* most fields are the same, copy all, and then fixup */
95206 *new = *vma;
95207
95208 @@ -2424,6 +2808,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
95209 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
95210 }
95211
95212 +#ifdef CONFIG_PAX_SEGMEXEC
95213 + if (vma_m) {
95214 + *new_m = *vma_m;
95215 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
95216 + new_m->vm_mirror = new;
95217 + new->vm_mirror = new_m;
95218 +
95219 + if (new_below)
95220 + new_m->vm_end = addr_m;
95221 + else {
95222 + new_m->vm_start = addr_m;
95223 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
95224 + }
95225 + }
95226 +#endif
95227 +
95228 err = vma_dup_policy(vma, new);
95229 if (err)
95230 goto out_free_vma;
95231 @@ -2443,6 +2843,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
95232 else
95233 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
95234
95235 +#ifdef CONFIG_PAX_SEGMEXEC
95236 + if (!err && vma_m) {
95237 + struct mempolicy *pol = vma_policy(new);
95238 +
95239 + if (anon_vma_clone(new_m, vma_m))
95240 + goto out_free_mpol;
95241 +
95242 + mpol_get(pol);
95243 + set_vma_policy(new_m, pol);
95244 +
95245 + if (new_m->vm_file)
95246 + get_file(new_m->vm_file);
95247 +
95248 + if (new_m->vm_ops && new_m->vm_ops->open)
95249 + new_m->vm_ops->open(new_m);
95250 +
95251 + if (new_below)
95252 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
95253 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
95254 + else
95255 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
95256 +
95257 + if (err) {
95258 + if (new_m->vm_ops && new_m->vm_ops->close)
95259 + new_m->vm_ops->close(new_m);
95260 + if (new_m->vm_file)
95261 + fput(new_m->vm_file);
95262 + mpol_put(pol);
95263 + }
95264 + }
95265 +#endif
95266 +
95267 /* Success. */
95268 if (!err)
95269 return 0;
95270 @@ -2452,10 +2884,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
95271 new->vm_ops->close(new);
95272 if (new->vm_file)
95273 fput(new->vm_file);
95274 - unlink_anon_vmas(new);
95275 out_free_mpol:
95276 mpol_put(vma_policy(new));
95277 out_free_vma:
95278 +
95279 +#ifdef CONFIG_PAX_SEGMEXEC
95280 + if (new_m) {
95281 + unlink_anon_vmas(new_m);
95282 + kmem_cache_free(vm_area_cachep, new_m);
95283 + }
95284 +#endif
95285 +
95286 + unlink_anon_vmas(new);
95287 kmem_cache_free(vm_area_cachep, new);
95288 out_err:
95289 return err;
95290 @@ -2468,6 +2908,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
95291 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
95292 unsigned long addr, int new_below)
95293 {
95294 +
95295 +#ifdef CONFIG_PAX_SEGMEXEC
95296 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
95297 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
95298 + if (mm->map_count >= sysctl_max_map_count-1)
95299 + return -ENOMEM;
95300 + } else
95301 +#endif
95302 +
95303 if (mm->map_count >= sysctl_max_map_count)
95304 return -ENOMEM;
95305
95306 @@ -2479,11 +2928,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
95307 * work. This now handles partial unmappings.
95308 * Jeremy Fitzhardinge <jeremy@goop.org>
95309 */
95310 +#ifdef CONFIG_PAX_SEGMEXEC
95311 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
95312 {
95313 + int ret = __do_munmap(mm, start, len);
95314 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
95315 + return ret;
95316 +
95317 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
95318 +}
95319 +
95320 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
95321 +#else
95322 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
95323 +#endif
95324 +{
95325 unsigned long end;
95326 struct vm_area_struct *vma, *prev, *last;
95327
95328 + /*
95329 + * mm->mmap_sem is required to protect against another thread
95330 + * changing the mappings in case we sleep.
95331 + */
95332 + verify_mm_writelocked(mm);
95333 +
95334 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
95335 return -EINVAL;
95336
95337 @@ -2558,6 +3026,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
95338 /* Fix up all other VM information */
95339 remove_vma_list(mm, vma);
95340
95341 + track_exec_limit(mm, start, end, 0UL);
95342 +
95343 return 0;
95344 }
95345
95346 @@ -2566,6 +3036,13 @@ int vm_munmap(unsigned long start, size_t len)
95347 int ret;
95348 struct mm_struct *mm = current->mm;
95349
95350 +
95351 +#ifdef CONFIG_PAX_SEGMEXEC
95352 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
95353 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
95354 + return -EINVAL;
95355 +#endif
95356 +
95357 down_write(&mm->mmap_sem);
95358 ret = do_munmap(mm, start, len);
95359 up_write(&mm->mmap_sem);
95360 @@ -2579,16 +3056,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
95361 return vm_munmap(addr, len);
95362 }
95363
95364 -static inline void verify_mm_writelocked(struct mm_struct *mm)
95365 -{
95366 -#ifdef CONFIG_DEBUG_VM
95367 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
95368 - WARN_ON(1);
95369 - up_read(&mm->mmap_sem);
95370 - }
95371 -#endif
95372 -}
95373 -
95374 /*
95375 * this is really a simplified "do_mmap". it only handles
95376 * anonymous maps. eventually we may be able to do some
95377 @@ -2602,6 +3069,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
95378 struct rb_node ** rb_link, * rb_parent;
95379 pgoff_t pgoff = addr >> PAGE_SHIFT;
95380 int error;
95381 + unsigned long charged;
95382
95383 len = PAGE_ALIGN(len);
95384 if (!len)
95385 @@ -2609,10 +3077,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
95386
95387 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
95388
95389 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
95390 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
95391 + flags &= ~VM_EXEC;
95392 +
95393 +#ifdef CONFIG_PAX_MPROTECT
95394 + if (mm->pax_flags & MF_PAX_MPROTECT)
95395 + flags &= ~VM_MAYEXEC;
95396 +#endif
95397 +
95398 + }
95399 +#endif
95400 +
95401 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
95402 if (error & ~PAGE_MASK)
95403 return error;
95404
95405 + charged = len >> PAGE_SHIFT;
95406 +
95407 error = mlock_future_check(mm, mm->def_flags, len);
95408 if (error)
95409 return error;
95410 @@ -2626,21 +3108,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
95411 /*
95412 * Clear old maps. this also does some error checking for us
95413 */
95414 - munmap_back:
95415 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
95416 if (do_munmap(mm, addr, len))
95417 return -ENOMEM;
95418 - goto munmap_back;
95419 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
95420 }
95421
95422 /* Check against address space limits *after* clearing old maps... */
95423 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
95424 + if (!may_expand_vm(mm, charged))
95425 return -ENOMEM;
95426
95427 if (mm->map_count > sysctl_max_map_count)
95428 return -ENOMEM;
95429
95430 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
95431 + if (security_vm_enough_memory_mm(mm, charged))
95432 return -ENOMEM;
95433
95434 /* Can we just expand an old private anonymous mapping? */
95435 @@ -2654,7 +3135,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
95436 */
95437 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
95438 if (!vma) {
95439 - vm_unacct_memory(len >> PAGE_SHIFT);
95440 + vm_unacct_memory(charged);
95441 return -ENOMEM;
95442 }
95443
95444 @@ -2668,10 +3149,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
95445 vma_link(mm, vma, prev, rb_link, rb_parent);
95446 out:
95447 perf_event_mmap(vma);
95448 - mm->total_vm += len >> PAGE_SHIFT;
95449 + mm->total_vm += charged;
95450 if (flags & VM_LOCKED)
95451 - mm->locked_vm += (len >> PAGE_SHIFT);
95452 + mm->locked_vm += charged;
95453 vma->vm_flags |= VM_SOFTDIRTY;
95454 + track_exec_limit(mm, addr, addr + len, flags);
95455 return addr;
95456 }
95457
95458 @@ -2733,6 +3215,7 @@ void exit_mmap(struct mm_struct *mm)
95459 while (vma) {
95460 if (vma->vm_flags & VM_ACCOUNT)
95461 nr_accounted += vma_pages(vma);
95462 + vma->vm_mirror = NULL;
95463 vma = remove_vma(vma);
95464 }
95465 vm_unacct_memory(nr_accounted);
95466 @@ -2750,6 +3233,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
95467 struct vm_area_struct *prev;
95468 struct rb_node **rb_link, *rb_parent;
95469
95470 +#ifdef CONFIG_PAX_SEGMEXEC
95471 + struct vm_area_struct *vma_m = NULL;
95472 +#endif
95473 +
95474 + if (security_mmap_addr(vma->vm_start))
95475 + return -EPERM;
95476 +
95477 /*
95478 * The vm_pgoff of a purely anonymous vma should be irrelevant
95479 * until its first write fault, when page's anon_vma and index
95480 @@ -2773,7 +3263,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
95481 security_vm_enough_memory_mm(mm, vma_pages(vma)))
95482 return -ENOMEM;
95483
95484 +#ifdef CONFIG_PAX_SEGMEXEC
95485 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
95486 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
95487 + if (!vma_m)
95488 + return -ENOMEM;
95489 + }
95490 +#endif
95491 +
95492 vma_link(mm, vma, prev, rb_link, rb_parent);
95493 +
95494 +#ifdef CONFIG_PAX_SEGMEXEC
95495 + if (vma_m)
95496 + BUG_ON(pax_mirror_vma(vma_m, vma));
95497 +#endif
95498 +
95499 return 0;
95500 }
95501
95502 @@ -2792,6 +3296,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
95503 struct rb_node **rb_link, *rb_parent;
95504 bool faulted_in_anon_vma = true;
95505
95506 + BUG_ON(vma->vm_mirror);
95507 +
95508 /*
95509 * If anonymous vma has not yet been faulted, update new pgoff
95510 * to match new location, to increase its chance of merging.
95511 @@ -2856,6 +3362,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
95512 return NULL;
95513 }
95514
95515 +#ifdef CONFIG_PAX_SEGMEXEC
95516 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
95517 +{
95518 + struct vm_area_struct *prev_m;
95519 + struct rb_node **rb_link_m, *rb_parent_m;
95520 + struct mempolicy *pol_m;
95521 +
95522 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
95523 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
95524 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
95525 + *vma_m = *vma;
95526 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
95527 + if (anon_vma_clone(vma_m, vma))
95528 + return -ENOMEM;
95529 + pol_m = vma_policy(vma_m);
95530 + mpol_get(pol_m);
95531 + set_vma_policy(vma_m, pol_m);
95532 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
95533 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
95534 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
95535 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
95536 + if (vma_m->vm_file)
95537 + get_file(vma_m->vm_file);
95538 + if (vma_m->vm_ops && vma_m->vm_ops->open)
95539 + vma_m->vm_ops->open(vma_m);
95540 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
95541 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
95542 + vma_m->vm_mirror = vma;
95543 + vma->vm_mirror = vma_m;
95544 + return 0;
95545 +}
95546 +#endif
95547 +
95548 /*
95549 * Return true if the calling process may expand its vm space by the passed
95550 * number of pages
95551 @@ -2867,6 +3406,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
95552
95553 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
95554
95555 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
95556 if (cur + npages > lim)
95557 return 0;
95558 return 1;
95559 @@ -2937,6 +3477,22 @@ struct vm_area_struct *_install_special_mapping(struct mm_struct *mm,
95560 vma->vm_start = addr;
95561 vma->vm_end = addr + len;
95562
95563 +#ifdef CONFIG_PAX_MPROTECT
95564 + if (mm->pax_flags & MF_PAX_MPROTECT) {
95565 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
95566 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
95567 + return ERR_PTR(-EPERM);
95568 + if (!(vm_flags & VM_EXEC))
95569 + vm_flags &= ~VM_MAYEXEC;
95570 +#else
95571 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
95572 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
95573 +#endif
95574 + else
95575 + vm_flags &= ~VM_MAYWRITE;
95576 + }
95577 +#endif
95578 +
95579 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
95580 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
95581
95582 diff --git a/mm/mprotect.c b/mm/mprotect.c
95583 index c43d557..0b7ccd2 100644
95584 --- a/mm/mprotect.c
95585 +++ b/mm/mprotect.c
95586 @@ -24,10 +24,18 @@
95587 #include <linux/migrate.h>
95588 #include <linux/perf_event.h>
95589 #include <linux/ksm.h>
95590 +#include <linux/sched/sysctl.h>
95591 +
95592 +#ifdef CONFIG_PAX_MPROTECT
95593 +#include <linux/elf.h>
95594 +#include <linux/binfmts.h>
95595 +#endif
95596 +
95597 #include <asm/uaccess.h>
95598 #include <asm/pgtable.h>
95599 #include <asm/cacheflush.h>
95600 #include <asm/tlbflush.h>
95601 +#include <asm/mmu_context.h>
95602
95603 #ifndef pgprot_modify
95604 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
95605 @@ -256,6 +264,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
95606 return pages;
95607 }
95608
95609 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
95610 +/* called while holding the mmap semaphor for writing except stack expansion */
95611 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
95612 +{
95613 + unsigned long oldlimit, newlimit = 0UL;
95614 +
95615 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
95616 + return;
95617 +
95618 + spin_lock(&mm->page_table_lock);
95619 + oldlimit = mm->context.user_cs_limit;
95620 + if ((prot & VM_EXEC) && oldlimit < end)
95621 + /* USER_CS limit moved up */
95622 + newlimit = end;
95623 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
95624 + /* USER_CS limit moved down */
95625 + newlimit = start;
95626 +
95627 + if (newlimit) {
95628 + mm->context.user_cs_limit = newlimit;
95629 +
95630 +#ifdef CONFIG_SMP
95631 + wmb();
95632 + cpus_clear(mm->context.cpu_user_cs_mask);
95633 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
95634 +#endif
95635 +
95636 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
95637 + }
95638 + spin_unlock(&mm->page_table_lock);
95639 + if (newlimit == end) {
95640 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
95641 +
95642 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
95643 + if (is_vm_hugetlb_page(vma))
95644 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
95645 + else
95646 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
95647 + }
95648 +}
95649 +#endif
95650 +
95651 int
95652 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
95653 unsigned long start, unsigned long end, unsigned long newflags)
95654 @@ -268,11 +318,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
95655 int error;
95656 int dirty_accountable = 0;
95657
95658 +#ifdef CONFIG_PAX_SEGMEXEC
95659 + struct vm_area_struct *vma_m = NULL;
95660 + unsigned long start_m, end_m;
95661 +
95662 + start_m = start + SEGMEXEC_TASK_SIZE;
95663 + end_m = end + SEGMEXEC_TASK_SIZE;
95664 +#endif
95665 +
95666 if (newflags == oldflags) {
95667 *pprev = vma;
95668 return 0;
95669 }
95670
95671 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
95672 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
95673 +
95674 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
95675 + return -ENOMEM;
95676 +
95677 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
95678 + return -ENOMEM;
95679 + }
95680 +
95681 /*
95682 * If we make a private mapping writable we increase our commit;
95683 * but (without finer accounting) cannot reduce our commit if we
95684 @@ -289,6 +357,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
95685 }
95686 }
95687
95688 +#ifdef CONFIG_PAX_SEGMEXEC
95689 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
95690 + if (start != vma->vm_start) {
95691 + error = split_vma(mm, vma, start, 1);
95692 + if (error)
95693 + goto fail;
95694 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
95695 + *pprev = (*pprev)->vm_next;
95696 + }
95697 +
95698 + if (end != vma->vm_end) {
95699 + error = split_vma(mm, vma, end, 0);
95700 + if (error)
95701 + goto fail;
95702 + }
95703 +
95704 + if (pax_find_mirror_vma(vma)) {
95705 + error = __do_munmap(mm, start_m, end_m - start_m);
95706 + if (error)
95707 + goto fail;
95708 + } else {
95709 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
95710 + if (!vma_m) {
95711 + error = -ENOMEM;
95712 + goto fail;
95713 + }
95714 + vma->vm_flags = newflags;
95715 + error = pax_mirror_vma(vma_m, vma);
95716 + if (error) {
95717 + vma->vm_flags = oldflags;
95718 + goto fail;
95719 + }
95720 + }
95721 + }
95722 +#endif
95723 +
95724 /*
95725 * First try to merge with previous and/or next vma.
95726 */
95727 @@ -319,9 +423,21 @@ success:
95728 * vm_flags and vm_page_prot are protected by the mmap_sem
95729 * held in write mode.
95730 */
95731 +
95732 +#ifdef CONFIG_PAX_SEGMEXEC
95733 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
95734 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
95735 +#endif
95736 +
95737 vma->vm_flags = newflags;
95738 +
95739 +#ifdef CONFIG_PAX_MPROTECT
95740 + if (mm->binfmt && mm->binfmt->handle_mprotect)
95741 + mm->binfmt->handle_mprotect(vma, newflags);
95742 +#endif
95743 +
95744 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
95745 - vm_get_page_prot(newflags));
95746 + vm_get_page_prot(vma->vm_flags));
95747
95748 if (vma_wants_writenotify(vma)) {
95749 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
95750 @@ -360,6 +476,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95751 end = start + len;
95752 if (end <= start)
95753 return -ENOMEM;
95754 +
95755 +#ifdef CONFIG_PAX_SEGMEXEC
95756 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
95757 + if (end > SEGMEXEC_TASK_SIZE)
95758 + return -EINVAL;
95759 + } else
95760 +#endif
95761 +
95762 + if (end > TASK_SIZE)
95763 + return -EINVAL;
95764 +
95765 if (!arch_validate_prot(prot))
95766 return -EINVAL;
95767
95768 @@ -367,7 +494,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95769 /*
95770 * Does the application expect PROT_READ to imply PROT_EXEC:
95771 */
95772 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
95773 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
95774 prot |= PROT_EXEC;
95775
95776 vm_flags = calc_vm_prot_bits(prot);
95777 @@ -399,6 +526,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95778 if (start > vma->vm_start)
95779 prev = vma;
95780
95781 +#ifdef CONFIG_PAX_MPROTECT
95782 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
95783 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
95784 +#endif
95785 +
95786 for (nstart = start ; ; ) {
95787 unsigned long newflags;
95788
95789 @@ -409,6 +541,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95790
95791 /* newflags >> 4 shift VM_MAY% in place of VM_% */
95792 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
95793 + if (prot & (PROT_WRITE | PROT_EXEC))
95794 + gr_log_rwxmprotect(vma);
95795 +
95796 + error = -EACCES;
95797 + goto out;
95798 + }
95799 +
95800 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
95801 error = -EACCES;
95802 goto out;
95803 }
95804 @@ -423,6 +563,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95805 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
95806 if (error)
95807 goto out;
95808 +
95809 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
95810 +
95811 nstart = tmp;
95812
95813 if (nstart < prev->vm_end)
95814 diff --git a/mm/mremap.c b/mm/mremap.c
95815 index 05f1180..c3cde48 100644
95816 --- a/mm/mremap.c
95817 +++ b/mm/mremap.c
95818 @@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
95819 continue;
95820 pte = ptep_get_and_clear(mm, old_addr, old_pte);
95821 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
95822 +
95823 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
95824 + if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
95825 + pte = pte_exprotect(pte);
95826 +#endif
95827 +
95828 pte = move_soft_dirty_pte(pte);
95829 set_pte_at(mm, new_addr, new_pte, pte);
95830 }
95831 @@ -344,6 +350,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
95832 if (is_vm_hugetlb_page(vma))
95833 goto Einval;
95834
95835 +#ifdef CONFIG_PAX_SEGMEXEC
95836 + if (pax_find_mirror_vma(vma))
95837 + goto Einval;
95838 +#endif
95839 +
95840 /* We can't remap across vm area boundaries */
95841 if (old_len > vma->vm_end - addr)
95842 goto Efault;
95843 @@ -399,20 +410,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
95844 unsigned long ret = -EINVAL;
95845 unsigned long charged = 0;
95846 unsigned long map_flags;
95847 + unsigned long pax_task_size = TASK_SIZE;
95848
95849 if (new_addr & ~PAGE_MASK)
95850 goto out;
95851
95852 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
95853 +#ifdef CONFIG_PAX_SEGMEXEC
95854 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
95855 + pax_task_size = SEGMEXEC_TASK_SIZE;
95856 +#endif
95857 +
95858 + pax_task_size -= PAGE_SIZE;
95859 +
95860 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
95861 goto out;
95862
95863 /* Check if the location we're moving into overlaps the
95864 * old location at all, and fail if it does.
95865 */
95866 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
95867 - goto out;
95868 -
95869 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
95870 + if (addr + old_len > new_addr && new_addr + new_len > addr)
95871 goto out;
95872
95873 ret = do_munmap(mm, new_addr, new_len);
95874 @@ -481,6 +497,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95875 unsigned long ret = -EINVAL;
95876 unsigned long charged = 0;
95877 bool locked = false;
95878 + unsigned long pax_task_size = TASK_SIZE;
95879
95880 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
95881 return ret;
95882 @@ -502,6 +519,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95883 if (!new_len)
95884 return ret;
95885
95886 +#ifdef CONFIG_PAX_SEGMEXEC
95887 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
95888 + pax_task_size = SEGMEXEC_TASK_SIZE;
95889 +#endif
95890 +
95891 + pax_task_size -= PAGE_SIZE;
95892 +
95893 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
95894 + old_len > pax_task_size || addr > pax_task_size-old_len)
95895 + return ret;
95896 +
95897 down_write(&current->mm->mmap_sem);
95898
95899 if (flags & MREMAP_FIXED) {
95900 @@ -552,6 +580,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95901 new_addr = addr;
95902 }
95903 ret = addr;
95904 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
95905 goto out;
95906 }
95907 }
95908 @@ -575,7 +604,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95909 goto out;
95910 }
95911
95912 + map_flags = vma->vm_flags;
95913 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
95914 + if (!(ret & ~PAGE_MASK)) {
95915 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
95916 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
95917 + }
95918 }
95919 out:
95920 if (ret & ~PAGE_MASK)
95921 diff --git a/mm/nommu.c b/mm/nommu.c
95922 index 431fd7c..8674512 100644
95923 --- a/mm/nommu.c
95924 +++ b/mm/nommu.c
95925 @@ -67,7 +67,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
95926 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
95927 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
95928 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
95929 -int heap_stack_gap = 0;
95930
95931 atomic_long_t mmap_pages_allocated;
95932
95933 @@ -854,15 +853,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
95934 EXPORT_SYMBOL(find_vma);
95935
95936 /*
95937 - * find a VMA
95938 - * - we don't extend stack VMAs under NOMMU conditions
95939 - */
95940 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
95941 -{
95942 - return find_vma(mm, addr);
95943 -}
95944 -
95945 -/*
95946 * expand a stack to a given address
95947 * - not supported under NOMMU conditions
95948 */
95949 @@ -1569,6 +1559,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
95950
95951 /* most fields are the same, copy all, and then fixup */
95952 *new = *vma;
95953 + INIT_LIST_HEAD(&new->anon_vma_chain);
95954 *region = *vma->vm_region;
95955 new->vm_region = region;
95956
95957 @@ -2004,8 +1995,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
95958 }
95959 EXPORT_SYMBOL(generic_file_remap_pages);
95960
95961 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95962 - unsigned long addr, void *buf, int len, int write)
95963 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95964 + unsigned long addr, void *buf, size_t len, int write)
95965 {
95966 struct vm_area_struct *vma;
95967
95968 @@ -2046,8 +2037,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95969 *
95970 * The caller must hold a reference on @mm.
95971 */
95972 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
95973 - void *buf, int len, int write)
95974 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
95975 + void *buf, size_t len, int write)
95976 {
95977 return __access_remote_vm(NULL, mm, addr, buf, len, write);
95978 }
95979 @@ -2056,7 +2047,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
95980 * Access another process' address space.
95981 * - source/target buffer must be kernel space
95982 */
95983 -int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
95984 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
95985 {
95986 struct mm_struct *mm;
95987
95988 diff --git a/mm/page-writeback.c b/mm/page-writeback.c
95989 index f972182..e7f7c07 100644
95990 --- a/mm/page-writeback.c
95991 +++ b/mm/page-writeback.c
95992 @@ -685,7 +685,7 @@ static long long pos_ratio_polynom(unsigned long setpoint,
95993 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
95994 * - the bdi dirty thresh drops quickly due to change of JBOD workload
95995 */
95996 -static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
95997 +static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
95998 unsigned long thresh,
95999 unsigned long bg_thresh,
96000 unsigned long dirty,
96001 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
96002 index e98306f..3311d5e 100644
96003 --- a/mm/page_alloc.c
96004 +++ b/mm/page_alloc.c
96005 @@ -61,6 +61,7 @@
96006 #include <linux/page-debug-flags.h>
96007 #include <linux/hugetlb.h>
96008 #include <linux/sched/rt.h>
96009 +#include <linux/random.h>
96010
96011 #include <asm/sections.h>
96012 #include <asm/tlbflush.h>
96013 @@ -356,7 +357,7 @@ out:
96014 * This usage means that zero-order pages may not be compound.
96015 */
96016
96017 -static void free_compound_page(struct page *page)
96018 +void free_compound_page(struct page *page)
96019 {
96020 __free_pages_ok(page, compound_order(page));
96021 }
96022 @@ -730,6 +731,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
96023 int i;
96024 int bad = 0;
96025
96026 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
96027 + unsigned long index = 1UL << order;
96028 +#endif
96029 +
96030 trace_mm_page_free(page, order);
96031 kmemcheck_free_shadow(page, order);
96032
96033 @@ -746,6 +751,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
96034 debug_check_no_obj_freed(page_address(page),
96035 PAGE_SIZE << order);
96036 }
96037 +
96038 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
96039 + for (; index; --index)
96040 + sanitize_highpage(page + index - 1);
96041 +#endif
96042 +
96043 arch_free_page(page, order);
96044 kernel_map_pages(page, 1 << order, 0);
96045
96046 @@ -768,6 +779,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
96047 local_irq_restore(flags);
96048 }
96049
96050 +#ifdef CONFIG_PAX_LATENT_ENTROPY
96051 +bool __meminitdata extra_latent_entropy;
96052 +
96053 +static int __init setup_pax_extra_latent_entropy(char *str)
96054 +{
96055 + extra_latent_entropy = true;
96056 + return 0;
96057 +}
96058 +early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
96059 +
96060 +volatile u64 latent_entropy __latent_entropy;
96061 +EXPORT_SYMBOL(latent_entropy);
96062 +#endif
96063 +
96064 void __init __free_pages_bootmem(struct page *page, unsigned int order)
96065 {
96066 unsigned int nr_pages = 1 << order;
96067 @@ -783,6 +808,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
96068 __ClearPageReserved(p);
96069 set_page_count(p, 0);
96070
96071 +#ifdef CONFIG_PAX_LATENT_ENTROPY
96072 + if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
96073 + u64 hash = 0;
96074 + size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
96075 + const u64 *data = lowmem_page_address(page);
96076 +
96077 + for (index = 0; index < end; index++)
96078 + hash ^= hash + data[index];
96079 + latent_entropy ^= hash;
96080 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
96081 + }
96082 +#endif
96083 +
96084 page_zone(page)->managed_pages += nr_pages;
96085 set_page_refcounted(page);
96086 __free_pages(page, order);
96087 @@ -911,8 +949,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
96088 arch_alloc_page(page, order);
96089 kernel_map_pages(page, 1 << order, 1);
96090
96091 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
96092 if (gfp_flags & __GFP_ZERO)
96093 prep_zero_page(page, order, gfp_flags);
96094 +#endif
96095
96096 if (order && (gfp_flags & __GFP_COMP))
96097 prep_compound_page(page, order);
96098 @@ -2415,7 +2455,7 @@ static void reset_alloc_batches(struct zonelist *zonelist,
96099 continue;
96100 mod_zone_page_state(zone, NR_ALLOC_BATCH,
96101 high_wmark_pages(zone) - low_wmark_pages(zone) -
96102 - atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
96103 + atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
96104 }
96105 }
96106
96107 diff --git a/mm/page_io.c b/mm/page_io.c
96108 index 7c59ef6..1358905 100644
96109 --- a/mm/page_io.c
96110 +++ b/mm/page_io.c
96111 @@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
96112 struct file *swap_file = sis->swap_file;
96113 struct address_space *mapping = swap_file->f_mapping;
96114 struct iovec iov = {
96115 - .iov_base = kmap(page),
96116 + .iov_base = (void __force_user *)kmap(page),
96117 .iov_len = PAGE_SIZE,
96118 };
96119
96120 diff --git a/mm/percpu.c b/mm/percpu.c
96121 index 2ddf9a9..f8fc075 100644
96122 --- a/mm/percpu.c
96123 +++ b/mm/percpu.c
96124 @@ -123,7 +123,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
96125 static unsigned int pcpu_high_unit_cpu __read_mostly;
96126
96127 /* the address of the first chunk which starts with the kernel static area */
96128 -void *pcpu_base_addr __read_mostly;
96129 +void *pcpu_base_addr __read_only;
96130 EXPORT_SYMBOL_GPL(pcpu_base_addr);
96131
96132 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
96133 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
96134 index 8505c92..946bfc9 100644
96135 --- a/mm/process_vm_access.c
96136 +++ b/mm/process_vm_access.c
96137 @@ -13,6 +13,7 @@
96138 #include <linux/uio.h>
96139 #include <linux/sched.h>
96140 #include <linux/highmem.h>
96141 +#include <linux/security.h>
96142 #include <linux/ptrace.h>
96143 #include <linux/slab.h>
96144 #include <linux/syscalls.h>
96145 @@ -161,19 +162,19 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
96146 ssize_t iov_len;
96147 size_t total_len = iov_iter_count(iter);
96148
96149 + return -ENOSYS; // PaX: until properly audited
96150 +
96151 /*
96152 * Work out how many pages of struct pages we're going to need
96153 * when eventually calling get_user_pages
96154 */
96155 for (i = 0; i < riovcnt; i++) {
96156 iov_len = rvec[i].iov_len;
96157 - if (iov_len > 0) {
96158 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
96159 - + iov_len)
96160 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
96161 - / PAGE_SIZE + 1;
96162 - nr_pages = max(nr_pages, nr_pages_iov);
96163 - }
96164 + if (iov_len <= 0)
96165 + continue;
96166 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
96167 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
96168 + nr_pages = max(nr_pages, nr_pages_iov);
96169 }
96170
96171 if (nr_pages == 0)
96172 @@ -201,6 +202,11 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
96173 goto free_proc_pages;
96174 }
96175
96176 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
96177 + rc = -EPERM;
96178 + goto put_task_struct;
96179 + }
96180 +
96181 mm = mm_access(task, PTRACE_MODE_ATTACH);
96182 if (!mm || IS_ERR(mm)) {
96183 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
96184 diff --git a/mm/rmap.c b/mm/rmap.c
96185 index 14d1e28..3777962 100644
96186 --- a/mm/rmap.c
96187 +++ b/mm/rmap.c
96188 @@ -164,6 +164,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
96189 struct anon_vma *anon_vma = vma->anon_vma;
96190 struct anon_vma_chain *avc;
96191
96192 +#ifdef CONFIG_PAX_SEGMEXEC
96193 + struct anon_vma_chain *avc_m = NULL;
96194 +#endif
96195 +
96196 might_sleep();
96197 if (unlikely(!anon_vma)) {
96198 struct mm_struct *mm = vma->vm_mm;
96199 @@ -173,6 +177,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
96200 if (!avc)
96201 goto out_enomem;
96202
96203 +#ifdef CONFIG_PAX_SEGMEXEC
96204 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
96205 + if (!avc_m)
96206 + goto out_enomem_free_avc;
96207 +#endif
96208 +
96209 anon_vma = find_mergeable_anon_vma(vma);
96210 allocated = NULL;
96211 if (!anon_vma) {
96212 @@ -186,6 +196,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
96213 /* page_table_lock to protect against threads */
96214 spin_lock(&mm->page_table_lock);
96215 if (likely(!vma->anon_vma)) {
96216 +
96217 +#ifdef CONFIG_PAX_SEGMEXEC
96218 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
96219 +
96220 + if (vma_m) {
96221 + BUG_ON(vma_m->anon_vma);
96222 + vma_m->anon_vma = anon_vma;
96223 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
96224 + avc_m = NULL;
96225 + }
96226 +#endif
96227 +
96228 vma->anon_vma = anon_vma;
96229 anon_vma_chain_link(vma, avc, anon_vma);
96230 allocated = NULL;
96231 @@ -196,12 +218,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
96232
96233 if (unlikely(allocated))
96234 put_anon_vma(allocated);
96235 +
96236 +#ifdef CONFIG_PAX_SEGMEXEC
96237 + if (unlikely(avc_m))
96238 + anon_vma_chain_free(avc_m);
96239 +#endif
96240 +
96241 if (unlikely(avc))
96242 anon_vma_chain_free(avc);
96243 }
96244 return 0;
96245
96246 out_enomem_free_avc:
96247 +
96248 +#ifdef CONFIG_PAX_SEGMEXEC
96249 + if (avc_m)
96250 + anon_vma_chain_free(avc_m);
96251 +#endif
96252 +
96253 anon_vma_chain_free(avc);
96254 out_enomem:
96255 return -ENOMEM;
96256 @@ -237,7 +271,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
96257 * Attach the anon_vmas from src to dst.
96258 * Returns 0 on success, -ENOMEM on failure.
96259 */
96260 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
96261 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
96262 {
96263 struct anon_vma_chain *avc, *pavc;
96264 struct anon_vma *root = NULL;
96265 @@ -270,7 +304,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
96266 * the corresponding VMA in the parent process is attached to.
96267 * Returns 0 on success, non-zero on failure.
96268 */
96269 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
96270 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
96271 {
96272 struct anon_vma_chain *avc;
96273 struct anon_vma *anon_vma;
96274 @@ -374,8 +408,10 @@ static void anon_vma_ctor(void *data)
96275 void __init anon_vma_init(void)
96276 {
96277 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
96278 - 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
96279 - anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
96280 + 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
96281 + anon_vma_ctor);
96282 + anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
96283 + SLAB_PANIC|SLAB_NO_SANITIZE);
96284 }
96285
96286 /*
96287 diff --git a/mm/shmem.c b/mm/shmem.c
96288 index a731cef..1e82984 100644
96289 --- a/mm/shmem.c
96290 +++ b/mm/shmem.c
96291 @@ -33,7 +33,7 @@
96292 #include <linux/swap.h>
96293 #include <linux/aio.h>
96294
96295 -static struct vfsmount *shm_mnt;
96296 +struct vfsmount *shm_mnt;
96297
96298 #ifdef CONFIG_SHMEM
96299 /*
96300 @@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
96301 #define BOGO_DIRENT_SIZE 20
96302
96303 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
96304 -#define SHORT_SYMLINK_LEN 128
96305 +#define SHORT_SYMLINK_LEN 64
96306
96307 /*
96308 * shmem_fallocate communicates with shmem_fault or shmem_writepage via
96309 @@ -2218,6 +2218,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
96310 static int shmem_xattr_validate(const char *name)
96311 {
96312 struct { const char *prefix; size_t len; } arr[] = {
96313 +
96314 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
96315 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
96316 +#endif
96317 +
96318 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
96319 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
96320 };
96321 @@ -2273,6 +2278,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
96322 if (err)
96323 return err;
96324
96325 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
96326 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
96327 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
96328 + return -EOPNOTSUPP;
96329 + if (size > 8)
96330 + return -EINVAL;
96331 + }
96332 +#endif
96333 +
96334 return simple_xattr_set(&info->xattrs, name, value, size, flags);
96335 }
96336
96337 @@ -2585,8 +2599,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
96338 int err = -ENOMEM;
96339
96340 /* Round up to L1_CACHE_BYTES to resist false sharing */
96341 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
96342 - L1_CACHE_BYTES), GFP_KERNEL);
96343 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
96344 if (!sbinfo)
96345 return -ENOMEM;
96346
96347 diff --git a/mm/slab.c b/mm/slab.c
96348 index 9432556..e0dc685 100644
96349 --- a/mm/slab.c
96350 +++ b/mm/slab.c
96351 @@ -311,10 +311,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
96352 if ((x)->max_freeable < i) \
96353 (x)->max_freeable = i; \
96354 } while (0)
96355 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
96356 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
96357 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
96358 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
96359 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
96360 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
96361 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
96362 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
96363 +#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
96364 +#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
96365 #else
96366 #define STATS_INC_ACTIVE(x) do { } while (0)
96367 #define STATS_DEC_ACTIVE(x) do { } while (0)
96368 @@ -331,6 +333,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
96369 #define STATS_INC_ALLOCMISS(x) do { } while (0)
96370 #define STATS_INC_FREEHIT(x) do { } while (0)
96371 #define STATS_INC_FREEMISS(x) do { } while (0)
96372 +#define STATS_INC_SANITIZED(x) do { } while (0)
96373 +#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
96374 #endif
96375
96376 #if DEBUG
96377 @@ -447,7 +451,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
96378 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
96379 */
96380 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
96381 - const struct page *page, void *obj)
96382 + const struct page *page, const void *obj)
96383 {
96384 u32 offset = (obj - page->s_mem);
96385 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
96386 @@ -1558,12 +1562,12 @@ void __init kmem_cache_init(void)
96387 */
96388
96389 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
96390 - kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
96391 + kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
96392
96393 if (INDEX_AC != INDEX_NODE)
96394 kmalloc_caches[INDEX_NODE] =
96395 create_kmalloc_cache("kmalloc-node",
96396 - kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
96397 + kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
96398
96399 slab_early_init = 0;
96400
96401 @@ -3525,6 +3529,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
96402 struct array_cache *ac = cpu_cache_get(cachep);
96403
96404 check_irq_off();
96405 +
96406 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
96407 + if (pax_sanitize_slab) {
96408 + if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
96409 + memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
96410 +
96411 + if (cachep->ctor)
96412 + cachep->ctor(objp);
96413 +
96414 + STATS_INC_SANITIZED(cachep);
96415 + } else
96416 + STATS_INC_NOT_SANITIZED(cachep);
96417 + }
96418 +#endif
96419 +
96420 kmemleak_free_recursive(objp, cachep->flags);
96421 objp = cache_free_debugcheck(cachep, objp, caller);
96422
96423 @@ -3748,6 +3767,7 @@ void kfree(const void *objp)
96424
96425 if (unlikely(ZERO_OR_NULL_PTR(objp)))
96426 return;
96427 + VM_BUG_ON(!virt_addr_valid(objp));
96428 local_irq_save(flags);
96429 kfree_debugcheck(objp);
96430 c = virt_to_cache(objp);
96431 @@ -4189,14 +4209,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
96432 }
96433 /* cpu stats */
96434 {
96435 - unsigned long allochit = atomic_read(&cachep->allochit);
96436 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
96437 - unsigned long freehit = atomic_read(&cachep->freehit);
96438 - unsigned long freemiss = atomic_read(&cachep->freemiss);
96439 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
96440 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
96441 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
96442 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
96443
96444 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
96445 allochit, allocmiss, freehit, freemiss);
96446 }
96447 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
96448 + {
96449 + unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
96450 + unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
96451 +
96452 + seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
96453 + }
96454 +#endif
96455 #endif
96456 }
96457
96458 @@ -4417,13 +4445,69 @@ static const struct file_operations proc_slabstats_operations = {
96459 static int __init slab_proc_init(void)
96460 {
96461 #ifdef CONFIG_DEBUG_SLAB_LEAK
96462 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
96463 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
96464 #endif
96465 return 0;
96466 }
96467 module_init(slab_proc_init);
96468 #endif
96469
96470 +bool is_usercopy_object(const void *ptr)
96471 +{
96472 + struct page *page;
96473 + struct kmem_cache *cachep;
96474 +
96475 + if (ZERO_OR_NULL_PTR(ptr))
96476 + return false;
96477 +
96478 + if (!slab_is_available())
96479 + return false;
96480 +
96481 + if (!virt_addr_valid(ptr))
96482 + return false;
96483 +
96484 + page = virt_to_head_page(ptr);
96485 +
96486 + if (!PageSlab(page))
96487 + return false;
96488 +
96489 + cachep = page->slab_cache;
96490 + return cachep->flags & SLAB_USERCOPY;
96491 +}
96492 +
96493 +#ifdef CONFIG_PAX_USERCOPY
96494 +const char *check_heap_object(const void *ptr, unsigned long n)
96495 +{
96496 + struct page *page;
96497 + struct kmem_cache *cachep;
96498 + unsigned int objnr;
96499 + unsigned long offset;
96500 +
96501 + if (ZERO_OR_NULL_PTR(ptr))
96502 + return "<null>";
96503 +
96504 + if (!virt_addr_valid(ptr))
96505 + return NULL;
96506 +
96507 + page = virt_to_head_page(ptr);
96508 +
96509 + if (!PageSlab(page))
96510 + return NULL;
96511 +
96512 + cachep = page->slab_cache;
96513 + if (!(cachep->flags & SLAB_USERCOPY))
96514 + return cachep->name;
96515 +
96516 + objnr = obj_to_index(cachep, page, ptr);
96517 + BUG_ON(objnr >= cachep->num);
96518 + offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
96519 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
96520 + return NULL;
96521 +
96522 + return cachep->name;
96523 +}
96524 +#endif
96525 +
96526 /**
96527 * ksize - get the actual amount of memory allocated for a given object
96528 * @objp: Pointer to the object
96529 diff --git a/mm/slab.h b/mm/slab.h
96530 index 6bd4c35..97565a1 100644
96531 --- a/mm/slab.h
96532 +++ b/mm/slab.h
96533 @@ -32,6 +32,15 @@ extern struct list_head slab_caches;
96534 /* The slab cache that manages slab cache information */
96535 extern struct kmem_cache *kmem_cache;
96536
96537 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
96538 +#ifdef CONFIG_X86_64
96539 +#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
96540 +#else
96541 +#define PAX_MEMORY_SANITIZE_VALUE '\xff'
96542 +#endif
96543 +extern bool pax_sanitize_slab;
96544 +#endif
96545 +
96546 unsigned long calculate_alignment(unsigned long flags,
96547 unsigned long align, unsigned long size);
96548
96549 @@ -67,7 +76,8 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
96550
96551 /* Legal flag mask for kmem_cache_create(), for various configurations */
96552 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
96553 - SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
96554 + SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
96555 + SLAB_USERCOPY | SLAB_NO_SANITIZE)
96556
96557 #if defined(CONFIG_DEBUG_SLAB)
96558 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
96559 @@ -245,6 +255,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
96560 return s;
96561
96562 page = virt_to_head_page(x);
96563 +
96564 + BUG_ON(!PageSlab(page));
96565 +
96566 cachep = page->slab_cache;
96567 if (slab_equal_or_root(cachep, s))
96568 return cachep;
96569 diff --git a/mm/slab_common.c b/mm/slab_common.c
96570 index b810fba..ae882bf 100644
96571 --- a/mm/slab_common.c
96572 +++ b/mm/slab_common.c
96573 @@ -23,11 +23,22 @@
96574
96575 #include "slab.h"
96576
96577 -enum slab_state slab_state;
96578 +enum slab_state slab_state __read_only;
96579 LIST_HEAD(slab_caches);
96580 DEFINE_MUTEX(slab_mutex);
96581 struct kmem_cache *kmem_cache;
96582
96583 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
96584 +bool pax_sanitize_slab __read_only = true;
96585 +static int __init pax_sanitize_slab_setup(char *str)
96586 +{
96587 + pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
96588 + printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
96589 + return 1;
96590 +}
96591 +__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
96592 +#endif
96593 +
96594 #ifdef CONFIG_DEBUG_VM
96595 static int kmem_cache_sanity_check(const char *name, size_t size)
96596 {
96597 @@ -158,7 +169,7 @@ do_kmem_cache_create(char *name, size_t object_size, size_t size, size_t align,
96598 if (err)
96599 goto out_free_cache;
96600
96601 - s->refcount = 1;
96602 + atomic_set(&s->refcount, 1);
96603 list_add(&s->list, &slab_caches);
96604 memcg_register_cache(s);
96605 out:
96606 @@ -334,8 +345,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
96607 get_online_cpus();
96608 mutex_lock(&slab_mutex);
96609
96610 - s->refcount--;
96611 - if (s->refcount)
96612 + if (!atomic_dec_and_test(&s->refcount))
96613 goto out_unlock;
96614
96615 if (kmem_cache_destroy_memcg_children(s) != 0)
96616 @@ -358,7 +368,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
96617 rcu_barrier();
96618
96619 memcg_free_cache_params(s);
96620 -#ifdef SLAB_SUPPORTS_SYSFS
96621 +#if defined(SLAB_SUPPORTS_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96622 sysfs_slab_remove(s);
96623 #else
96624 slab_kmem_cache_release(s);
96625 @@ -393,7 +403,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
96626 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
96627 name, size, err);
96628
96629 - s->refcount = -1; /* Exempt from merging for now */
96630 + atomic_set(&s->refcount, -1); /* Exempt from merging for now */
96631 }
96632
96633 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
96634 @@ -406,7 +416,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
96635
96636 create_boot_cache(s, name, size, flags);
96637 list_add(&s->list, &slab_caches);
96638 - s->refcount = 1;
96639 + atomic_set(&s->refcount, 1);
96640 return s;
96641 }
96642
96643 @@ -418,6 +428,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
96644 EXPORT_SYMBOL(kmalloc_dma_caches);
96645 #endif
96646
96647 +#ifdef CONFIG_PAX_USERCOPY_SLABS
96648 +struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
96649 +EXPORT_SYMBOL(kmalloc_usercopy_caches);
96650 +#endif
96651 +
96652 /*
96653 * Conversion table for small slabs sizes / 8 to the index in the
96654 * kmalloc array. This is necessary for slabs < 192 since we have non power
96655 @@ -482,6 +497,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
96656 return kmalloc_dma_caches[index];
96657
96658 #endif
96659 +
96660 +#ifdef CONFIG_PAX_USERCOPY_SLABS
96661 + if (unlikely((flags & GFP_USERCOPY)))
96662 + return kmalloc_usercopy_caches[index];
96663 +
96664 +#endif
96665 +
96666 return kmalloc_caches[index];
96667 }
96668
96669 @@ -538,7 +560,7 @@ void __init create_kmalloc_caches(unsigned long flags)
96670 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
96671 if (!kmalloc_caches[i]) {
96672 kmalloc_caches[i] = create_kmalloc_cache(NULL,
96673 - 1 << i, flags);
96674 + 1 << i, SLAB_USERCOPY | flags);
96675 }
96676
96677 /*
96678 @@ -547,10 +569,10 @@ void __init create_kmalloc_caches(unsigned long flags)
96679 * earlier power of two caches
96680 */
96681 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
96682 - kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
96683 + kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
96684
96685 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
96686 - kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
96687 + kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
96688 }
96689
96690 /* Kmalloc array is now usable */
96691 @@ -583,6 +605,23 @@ void __init create_kmalloc_caches(unsigned long flags)
96692 }
96693 }
96694 #endif
96695 +
96696 +#ifdef CONFIG_PAX_USERCOPY_SLABS
96697 + for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
96698 + struct kmem_cache *s = kmalloc_caches[i];
96699 +
96700 + if (s) {
96701 + int size = kmalloc_size(i);
96702 + char *n = kasprintf(GFP_NOWAIT,
96703 + "usercopy-kmalloc-%d", size);
96704 +
96705 + BUG_ON(!n);
96706 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
96707 + size, SLAB_USERCOPY | flags);
96708 + }
96709 + }
96710 +#endif
96711 +
96712 }
96713 #endif /* !CONFIG_SLOB */
96714
96715 @@ -623,6 +662,9 @@ void print_slabinfo_header(struct seq_file *m)
96716 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
96717 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
96718 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
96719 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
96720 + seq_puts(m, " : pax <sanitized> <not_sanitized>");
96721 +#endif
96722 #endif
96723 seq_putc(m, '\n');
96724 }
96725 diff --git a/mm/slob.c b/mm/slob.c
96726 index 730cad4..8cfd442 100644
96727 --- a/mm/slob.c
96728 +++ b/mm/slob.c
96729 @@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
96730 /*
96731 * Return the size of a slob block.
96732 */
96733 -static slobidx_t slob_units(slob_t *s)
96734 +static slobidx_t slob_units(const slob_t *s)
96735 {
96736 if (s->units > 0)
96737 return s->units;
96738 @@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
96739 /*
96740 * Return the next free slob block pointer after this one.
96741 */
96742 -static slob_t *slob_next(slob_t *s)
96743 +static slob_t *slob_next(const slob_t *s)
96744 {
96745 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
96746 slobidx_t next;
96747 @@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
96748 /*
96749 * Returns true if s is the last free block in its page.
96750 */
96751 -static int slob_last(slob_t *s)
96752 +static int slob_last(const slob_t *s)
96753 {
96754 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
96755 }
96756
96757 -static void *slob_new_pages(gfp_t gfp, int order, int node)
96758 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
96759 {
96760 - void *page;
96761 + struct page *page;
96762
96763 #ifdef CONFIG_NUMA
96764 if (node != NUMA_NO_NODE)
96765 @@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
96766 if (!page)
96767 return NULL;
96768
96769 - return page_address(page);
96770 + __SetPageSlab(page);
96771 + return page;
96772 }
96773
96774 -static void slob_free_pages(void *b, int order)
96775 +static void slob_free_pages(struct page *sp, int order)
96776 {
96777 if (current->reclaim_state)
96778 current->reclaim_state->reclaimed_slab += 1 << order;
96779 - free_pages((unsigned long)b, order);
96780 + __ClearPageSlab(sp);
96781 + page_mapcount_reset(sp);
96782 + sp->private = 0;
96783 + __free_pages(sp, order);
96784 }
96785
96786 /*
96787 @@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
96788
96789 /* Not enough space: must allocate a new page */
96790 if (!b) {
96791 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
96792 - if (!b)
96793 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
96794 + if (!sp)
96795 return NULL;
96796 - sp = virt_to_page(b);
96797 - __SetPageSlab(sp);
96798 + b = page_address(sp);
96799
96800 spin_lock_irqsave(&slob_lock, flags);
96801 sp->units = SLOB_UNITS(PAGE_SIZE);
96802 sp->freelist = b;
96803 + sp->private = 0;
96804 INIT_LIST_HEAD(&sp->lru);
96805 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
96806 set_slob_page_free(sp, slob_list);
96807 @@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
96808 if (slob_page_free(sp))
96809 clear_slob_page_free(sp);
96810 spin_unlock_irqrestore(&slob_lock, flags);
96811 - __ClearPageSlab(sp);
96812 - page_mapcount_reset(sp);
96813 - slob_free_pages(b, 0);
96814 + slob_free_pages(sp, 0);
96815 return;
96816 }
96817
96818 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
96819 + if (pax_sanitize_slab)
96820 + memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
96821 +#endif
96822 +
96823 if (!slob_page_free(sp)) {
96824 /* This slob page is about to become partially free. Easy! */
96825 sp->units = units;
96826 @@ -424,11 +431,10 @@ out:
96827 */
96828
96829 static __always_inline void *
96830 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96831 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
96832 {
96833 - unsigned int *m;
96834 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96835 - void *ret;
96836 + slob_t *m;
96837 + void *ret = NULL;
96838
96839 gfp &= gfp_allowed_mask;
96840
96841 @@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96842
96843 if (!m)
96844 return NULL;
96845 - *m = size;
96846 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
96847 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
96848 + m[0].units = size;
96849 + m[1].units = align;
96850 ret = (void *)m + align;
96851
96852 trace_kmalloc_node(caller, ret,
96853 size, size + align, gfp, node);
96854 } else {
96855 unsigned int order = get_order(size);
96856 + struct page *page;
96857
96858 if (likely(order))
96859 gfp |= __GFP_COMP;
96860 - ret = slob_new_pages(gfp, order, node);
96861 + page = slob_new_pages(gfp, order, node);
96862 + if (page) {
96863 + ret = page_address(page);
96864 + page->private = size;
96865 + }
96866
96867 trace_kmalloc_node(caller, ret,
96868 size, PAGE_SIZE << order, gfp, node);
96869 }
96870
96871 - kmemleak_alloc(ret, size, 1, gfp);
96872 + return ret;
96873 +}
96874 +
96875 +static __always_inline void *
96876 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96877 +{
96878 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96879 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
96880 +
96881 + if (!ZERO_OR_NULL_PTR(ret))
96882 + kmemleak_alloc(ret, size, 1, gfp);
96883 return ret;
96884 }
96885
96886 @@ -493,34 +517,112 @@ void kfree(const void *block)
96887 return;
96888 kmemleak_free(block);
96889
96890 + VM_BUG_ON(!virt_addr_valid(block));
96891 sp = virt_to_page(block);
96892 - if (PageSlab(sp)) {
96893 + VM_BUG_ON(!PageSlab(sp));
96894 + if (!sp->private) {
96895 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96896 - unsigned int *m = (unsigned int *)(block - align);
96897 - slob_free(m, *m + align);
96898 - } else
96899 + slob_t *m = (slob_t *)(block - align);
96900 + slob_free(m, m[0].units + align);
96901 + } else {
96902 + __ClearPageSlab(sp);
96903 + page_mapcount_reset(sp);
96904 + sp->private = 0;
96905 __free_pages(sp, compound_order(sp));
96906 + }
96907 }
96908 EXPORT_SYMBOL(kfree);
96909
96910 +bool is_usercopy_object(const void *ptr)
96911 +{
96912 + if (!slab_is_available())
96913 + return false;
96914 +
96915 + // PAX: TODO
96916 +
96917 + return false;
96918 +}
96919 +
96920 +#ifdef CONFIG_PAX_USERCOPY
96921 +const char *check_heap_object(const void *ptr, unsigned long n)
96922 +{
96923 + struct page *page;
96924 + const slob_t *free;
96925 + const void *base;
96926 + unsigned long flags;
96927 +
96928 + if (ZERO_OR_NULL_PTR(ptr))
96929 + return "<null>";
96930 +
96931 + if (!virt_addr_valid(ptr))
96932 + return NULL;
96933 +
96934 + page = virt_to_head_page(ptr);
96935 + if (!PageSlab(page))
96936 + return NULL;
96937 +
96938 + if (page->private) {
96939 + base = page;
96940 + if (base <= ptr && n <= page->private - (ptr - base))
96941 + return NULL;
96942 + return "<slob>";
96943 + }
96944 +
96945 + /* some tricky double walking to find the chunk */
96946 + spin_lock_irqsave(&slob_lock, flags);
96947 + base = (void *)((unsigned long)ptr & PAGE_MASK);
96948 + free = page->freelist;
96949 +
96950 + while (!slob_last(free) && (void *)free <= ptr) {
96951 + base = free + slob_units(free);
96952 + free = slob_next(free);
96953 + }
96954 +
96955 + while (base < (void *)free) {
96956 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
96957 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
96958 + int offset;
96959 +
96960 + if (ptr < base + align)
96961 + break;
96962 +
96963 + offset = ptr - base - align;
96964 + if (offset >= m) {
96965 + base += size;
96966 + continue;
96967 + }
96968 +
96969 + if (n > m - offset)
96970 + break;
96971 +
96972 + spin_unlock_irqrestore(&slob_lock, flags);
96973 + return NULL;
96974 + }
96975 +
96976 + spin_unlock_irqrestore(&slob_lock, flags);
96977 + return "<slob>";
96978 +}
96979 +#endif
96980 +
96981 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
96982 size_t ksize(const void *block)
96983 {
96984 struct page *sp;
96985 int align;
96986 - unsigned int *m;
96987 + slob_t *m;
96988
96989 BUG_ON(!block);
96990 if (unlikely(block == ZERO_SIZE_PTR))
96991 return 0;
96992
96993 sp = virt_to_page(block);
96994 - if (unlikely(!PageSlab(sp)))
96995 - return PAGE_SIZE << compound_order(sp);
96996 + VM_BUG_ON(!PageSlab(sp));
96997 + if (sp->private)
96998 + return sp->private;
96999
97000 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
97001 - m = (unsigned int *)(block - align);
97002 - return SLOB_UNITS(*m) * SLOB_UNIT;
97003 + m = (slob_t *)(block - align);
97004 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
97005 }
97006 EXPORT_SYMBOL(ksize);
97007
97008 @@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
97009
97010 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
97011 {
97012 - void *b;
97013 + void *b = NULL;
97014
97015 flags &= gfp_allowed_mask;
97016
97017 lockdep_trace_alloc(flags);
97018
97019 +#ifdef CONFIG_PAX_USERCOPY_SLABS
97020 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
97021 +#else
97022 if (c->size < PAGE_SIZE) {
97023 b = slob_alloc(c->size, flags, c->align, node);
97024 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
97025 SLOB_UNITS(c->size) * SLOB_UNIT,
97026 flags, node);
97027 } else {
97028 - b = slob_new_pages(flags, get_order(c->size), node);
97029 + struct page *sp;
97030 +
97031 + sp = slob_new_pages(flags, get_order(c->size), node);
97032 + if (sp) {
97033 + b = page_address(sp);
97034 + sp->private = c->size;
97035 + }
97036 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
97037 PAGE_SIZE << get_order(c->size),
97038 flags, node);
97039 }
97040 +#endif
97041
97042 if (b && c->ctor)
97043 c->ctor(b);
97044 @@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
97045
97046 static void __kmem_cache_free(void *b, int size)
97047 {
97048 - if (size < PAGE_SIZE)
97049 + struct page *sp;
97050 +
97051 + sp = virt_to_page(b);
97052 + BUG_ON(!PageSlab(sp));
97053 + if (!sp->private)
97054 slob_free(b, size);
97055 else
97056 - slob_free_pages(b, get_order(size));
97057 + slob_free_pages(sp, get_order(size));
97058 }
97059
97060 static void kmem_rcu_free(struct rcu_head *head)
97061 @@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
97062
97063 void kmem_cache_free(struct kmem_cache *c, void *b)
97064 {
97065 + int size = c->size;
97066 +
97067 +#ifdef CONFIG_PAX_USERCOPY_SLABS
97068 + if (size + c->align < PAGE_SIZE) {
97069 + size += c->align;
97070 + b -= c->align;
97071 + }
97072 +#endif
97073 +
97074 kmemleak_free_recursive(b, c->flags);
97075 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
97076 struct slob_rcu *slob_rcu;
97077 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
97078 - slob_rcu->size = c->size;
97079 + slob_rcu = b + (size - sizeof(struct slob_rcu));
97080 + slob_rcu->size = size;
97081 call_rcu(&slob_rcu->head, kmem_rcu_free);
97082 } else {
97083 - __kmem_cache_free(b, c->size);
97084 + __kmem_cache_free(b, size);
97085 }
97086
97087 +#ifdef CONFIG_PAX_USERCOPY_SLABS
97088 + trace_kfree(_RET_IP_, b);
97089 +#else
97090 trace_kmem_cache_free(_RET_IP_, b);
97091 +#endif
97092 +
97093 }
97094 EXPORT_SYMBOL(kmem_cache_free);
97095
97096 diff --git a/mm/slub.c b/mm/slub.c
97097 index 2b1ce69..4a2193f 100644
97098 --- a/mm/slub.c
97099 +++ b/mm/slub.c
97100 @@ -207,7 +207,7 @@ struct track {
97101
97102 enum track_item { TRACK_ALLOC, TRACK_FREE };
97103
97104 -#ifdef CONFIG_SYSFS
97105 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
97106 static int sysfs_slab_add(struct kmem_cache *);
97107 static int sysfs_slab_alias(struct kmem_cache *, const char *);
97108 static void memcg_propagate_slab_attrs(struct kmem_cache *s);
97109 @@ -546,7 +546,7 @@ static void print_track(const char *s, struct track *t)
97110 if (!t->addr)
97111 return;
97112
97113 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
97114 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
97115 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
97116 #ifdef CONFIG_STACKTRACE
97117 {
97118 @@ -2666,6 +2666,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
97119
97120 slab_free_hook(s, x);
97121
97122 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
97123 + if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
97124 + memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
97125 + if (s->ctor)
97126 + s->ctor(x);
97127 + }
97128 +#endif
97129 +
97130 redo:
97131 /*
97132 * Determine the currently cpus per cpu slab.
97133 @@ -2733,7 +2741,7 @@ static int slub_min_objects;
97134 * Merge control. If this is set then no merging of slab caches will occur.
97135 * (Could be removed. This was introduced to pacify the merge skeptics.)
97136 */
97137 -static int slub_nomerge;
97138 +static int slub_nomerge = 1;
97139
97140 /*
97141 * Calculate the order of allocation given an slab object size.
97142 @@ -3014,6 +3022,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
97143 s->inuse = size;
97144
97145 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
97146 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
97147 + (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
97148 +#endif
97149 s->ctor)) {
97150 /*
97151 * Relocate free pointer after the object if it is not
97152 @@ -3343,6 +3354,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
97153 EXPORT_SYMBOL(__kmalloc_node);
97154 #endif
97155
97156 +bool is_usercopy_object(const void *ptr)
97157 +{
97158 + struct page *page;
97159 + struct kmem_cache *s;
97160 +
97161 + if (ZERO_OR_NULL_PTR(ptr))
97162 + return false;
97163 +
97164 + if (!slab_is_available())
97165 + return false;
97166 +
97167 + if (!virt_addr_valid(ptr))
97168 + return false;
97169 +
97170 + page = virt_to_head_page(ptr);
97171 +
97172 + if (!PageSlab(page))
97173 + return false;
97174 +
97175 + s = page->slab_cache;
97176 + return s->flags & SLAB_USERCOPY;
97177 +}
97178 +
97179 +#ifdef CONFIG_PAX_USERCOPY
97180 +const char *check_heap_object(const void *ptr, unsigned long n)
97181 +{
97182 + struct page *page;
97183 + struct kmem_cache *s;
97184 + unsigned long offset;
97185 +
97186 + if (ZERO_OR_NULL_PTR(ptr))
97187 + return "<null>";
97188 +
97189 + if (!virt_addr_valid(ptr))
97190 + return NULL;
97191 +
97192 + page = virt_to_head_page(ptr);
97193 +
97194 + if (!PageSlab(page))
97195 + return NULL;
97196 +
97197 + s = page->slab_cache;
97198 + if (!(s->flags & SLAB_USERCOPY))
97199 + return s->name;
97200 +
97201 + offset = (ptr - page_address(page)) % s->size;
97202 + if (offset <= s->object_size && n <= s->object_size - offset)
97203 + return NULL;
97204 +
97205 + return s->name;
97206 +}
97207 +#endif
97208 +
97209 size_t ksize(const void *object)
97210 {
97211 struct page *page;
97212 @@ -3371,6 +3435,7 @@ void kfree(const void *x)
97213 if (unlikely(ZERO_OR_NULL_PTR(x)))
97214 return;
97215
97216 + VM_BUG_ON(!virt_addr_valid(x));
97217 page = virt_to_head_page(x);
97218 if (unlikely(!PageSlab(page))) {
97219 BUG_ON(!PageCompound(page));
97220 @@ -3679,7 +3744,7 @@ static int slab_unmergeable(struct kmem_cache *s)
97221 /*
97222 * We may have set a slab to be unmergeable during bootstrap.
97223 */
97224 - if (s->refcount < 0)
97225 + if (atomic_read(&s->refcount) < 0)
97226 return 1;
97227
97228 return 0;
97229 @@ -3736,7 +3801,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
97230 int i;
97231 struct kmem_cache *c;
97232
97233 - s->refcount++;
97234 + atomic_inc(&s->refcount);
97235
97236 /*
97237 * Adjust the object sizes so that we clear
97238 @@ -3755,7 +3820,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
97239 }
97240
97241 if (sysfs_slab_alias(s, name)) {
97242 - s->refcount--;
97243 + atomic_dec(&s->refcount);
97244 s = NULL;
97245 }
97246 }
97247 @@ -3872,7 +3937,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
97248 }
97249 #endif
97250
97251 -#ifdef CONFIG_SYSFS
97252 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
97253 static int count_inuse(struct page *page)
97254 {
97255 return page->inuse;
97256 @@ -4156,7 +4221,11 @@ static int list_locations(struct kmem_cache *s, char *buf,
97257 len += sprintf(buf + len, "%7ld ", l->count);
97258
97259 if (l->addr)
97260 +#ifdef CONFIG_GRKERNSEC_HIDESYM
97261 + len += sprintf(buf + len, "%pS", NULL);
97262 +#else
97263 len += sprintf(buf + len, "%pS", (void *)l->addr);
97264 +#endif
97265 else
97266 len += sprintf(buf + len, "<not-available>");
97267
97268 @@ -4261,12 +4330,12 @@ static void resiliency_test(void)
97269 validate_slab_cache(kmalloc_caches[9]);
97270 }
97271 #else
97272 -#ifdef CONFIG_SYSFS
97273 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
97274 static void resiliency_test(void) {};
97275 #endif
97276 #endif
97277
97278 -#ifdef CONFIG_SYSFS
97279 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
97280 enum slab_stat_type {
97281 SL_ALL, /* All slabs */
97282 SL_PARTIAL, /* Only partially allocated slabs */
97283 @@ -4506,13 +4575,17 @@ static ssize_t ctor_show(struct kmem_cache *s, char *buf)
97284 {
97285 if (!s->ctor)
97286 return 0;
97287 +#ifdef CONFIG_GRKERNSEC_HIDESYM
97288 + return sprintf(buf, "%pS\n", NULL);
97289 +#else
97290 return sprintf(buf, "%pS\n", s->ctor);
97291 +#endif
97292 }
97293 SLAB_ATTR_RO(ctor);
97294
97295 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
97296 {
97297 - return sprintf(buf, "%d\n", s->refcount - 1);
97298 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
97299 }
97300 SLAB_ATTR_RO(aliases);
97301
97302 @@ -4600,6 +4673,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
97303 SLAB_ATTR_RO(cache_dma);
97304 #endif
97305
97306 +#ifdef CONFIG_PAX_USERCOPY_SLABS
97307 +static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
97308 +{
97309 + return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
97310 +}
97311 +SLAB_ATTR_RO(usercopy);
97312 +#endif
97313 +
97314 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
97315 {
97316 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
97317 @@ -4934,6 +5015,9 @@ static struct attribute *slab_attrs[] = {
97318 #ifdef CONFIG_ZONE_DMA
97319 &cache_dma_attr.attr,
97320 #endif
97321 +#ifdef CONFIG_PAX_USERCOPY_SLABS
97322 + &usercopy_attr.attr,
97323 +#endif
97324 #ifdef CONFIG_NUMA
97325 &remote_node_defrag_ratio_attr.attr,
97326 #endif
97327 @@ -5184,6 +5268,7 @@ static char *create_unique_id(struct kmem_cache *s)
97328 return name;
97329 }
97330
97331 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
97332 static int sysfs_slab_add(struct kmem_cache *s)
97333 {
97334 int err;
97335 @@ -5257,6 +5342,7 @@ void sysfs_slab_remove(struct kmem_cache *s)
97336 kobject_del(&s->kobj);
97337 kobject_put(&s->kobj);
97338 }
97339 +#endif
97340
97341 /*
97342 * Need to buffer aliases during bootup until sysfs becomes
97343 @@ -5270,6 +5356,7 @@ struct saved_alias {
97344
97345 static struct saved_alias *alias_list;
97346
97347 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
97348 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
97349 {
97350 struct saved_alias *al;
97351 @@ -5292,6 +5379,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
97352 alias_list = al;
97353 return 0;
97354 }
97355 +#endif
97356
97357 static int __init slab_sysfs_init(void)
97358 {
97359 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
97360 index 4cba9c2..b4f9fcc 100644
97361 --- a/mm/sparse-vmemmap.c
97362 +++ b/mm/sparse-vmemmap.c
97363 @@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
97364 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
97365 if (!p)
97366 return NULL;
97367 - pud_populate(&init_mm, pud, p);
97368 + pud_populate_kernel(&init_mm, pud, p);
97369 }
97370 return pud;
97371 }
97372 @@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
97373 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
97374 if (!p)
97375 return NULL;
97376 - pgd_populate(&init_mm, pgd, p);
97377 + pgd_populate_kernel(&init_mm, pgd, p);
97378 }
97379 return pgd;
97380 }
97381 diff --git a/mm/sparse.c b/mm/sparse.c
97382 index d1b48b6..6e8590e 100644
97383 --- a/mm/sparse.c
97384 +++ b/mm/sparse.c
97385 @@ -750,7 +750,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
97386
97387 for (i = 0; i < PAGES_PER_SECTION; i++) {
97388 if (PageHWPoison(&memmap[i])) {
97389 - atomic_long_sub(1, &num_poisoned_pages);
97390 + atomic_long_sub_unchecked(1, &num_poisoned_pages);
97391 ClearPageHWPoison(&memmap[i]);
97392 }
97393 }
97394 diff --git a/mm/swap.c b/mm/swap.c
97395 index 9ce43ba..43bdc4c 100644
97396 --- a/mm/swap.c
97397 +++ b/mm/swap.c
97398 @@ -31,6 +31,7 @@
97399 #include <linux/memcontrol.h>
97400 #include <linux/gfp.h>
97401 #include <linux/uio.h>
97402 +#include <linux/hugetlb.h>
97403
97404 #include "internal.h"
97405
97406 @@ -76,6 +77,8 @@ static void __put_compound_page(struct page *page)
97407
97408 __page_cache_release(page);
97409 dtor = get_compound_page_dtor(page);
97410 + if (!PageHuge(page))
97411 + BUG_ON(dtor != free_compound_page);
97412 (*dtor)(page);
97413 }
97414
97415 diff --git a/mm/swapfile.c b/mm/swapfile.c
97416 index 4a7f7e6..22cddf5 100644
97417 --- a/mm/swapfile.c
97418 +++ b/mm/swapfile.c
97419 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
97420
97421 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
97422 /* Activity counter to indicate that a swapon or swapoff has occurred */
97423 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
97424 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
97425
97426 static inline unsigned char swap_count(unsigned char ent)
97427 {
97428 @@ -1959,7 +1959,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
97429 spin_unlock(&swap_lock);
97430
97431 err = 0;
97432 - atomic_inc(&proc_poll_event);
97433 + atomic_inc_unchecked(&proc_poll_event);
97434 wake_up_interruptible(&proc_poll_wait);
97435
97436 out_dput:
97437 @@ -1976,8 +1976,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
97438
97439 poll_wait(file, &proc_poll_wait, wait);
97440
97441 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
97442 - seq->poll_event = atomic_read(&proc_poll_event);
97443 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
97444 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
97445 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
97446 }
97447
97448 @@ -2075,7 +2075,7 @@ static int swaps_open(struct inode *inode, struct file *file)
97449 return ret;
97450
97451 seq = file->private_data;
97452 - seq->poll_event = atomic_read(&proc_poll_event);
97453 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
97454 return 0;
97455 }
97456
97457 @@ -2534,7 +2534,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
97458 (frontswap_map) ? "FS" : "");
97459
97460 mutex_unlock(&swapon_mutex);
97461 - atomic_inc(&proc_poll_event);
97462 + atomic_inc_unchecked(&proc_poll_event);
97463 wake_up_interruptible(&proc_poll_wait);
97464
97465 if (S_ISREG(inode->i_mode))
97466 diff --git a/mm/util.c b/mm/util.c
97467 index d5ea733..e8953f9 100644
97468 --- a/mm/util.c
97469 +++ b/mm/util.c
97470 @@ -299,6 +299,12 @@ done:
97471 void arch_pick_mmap_layout(struct mm_struct *mm)
97472 {
97473 mm->mmap_base = TASK_UNMAPPED_BASE;
97474 +
97475 +#ifdef CONFIG_PAX_RANDMMAP
97476 + if (mm->pax_flags & MF_PAX_RANDMMAP)
97477 + mm->mmap_base += mm->delta_mmap;
97478 +#endif
97479 +
97480 mm->get_unmapped_area = arch_get_unmapped_area;
97481 }
97482 #endif
97483 @@ -475,6 +481,9 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
97484 if (!mm->arg_end)
97485 goto out_mm; /* Shh! No looking before we're done */
97486
97487 + if (gr_acl_handle_procpidmem(task))
97488 + goto out_mm;
97489 +
97490 len = mm->arg_end - mm->arg_start;
97491
97492 if (len > buflen)
97493 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
97494 index bf233b2..1dfa1bc 100644
97495 --- a/mm/vmalloc.c
97496 +++ b/mm/vmalloc.c
97497 @@ -40,6 +40,21 @@ struct vfree_deferred {
97498 };
97499 static DEFINE_PER_CPU(struct vfree_deferred, vfree_deferred);
97500
97501 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
97502 +struct stack_deferred_llist {
97503 + struct llist_head list;
97504 + void *stack;
97505 + void *lowmem_stack;
97506 +};
97507 +
97508 +struct stack_deferred {
97509 + struct stack_deferred_llist list;
97510 + struct work_struct wq;
97511 +};
97512 +
97513 +static DEFINE_PER_CPU(struct stack_deferred, stack_deferred);
97514 +#endif
97515 +
97516 static void __vunmap(const void *, int);
97517
97518 static void free_work(struct work_struct *w)
97519 @@ -47,12 +62,30 @@ static void free_work(struct work_struct *w)
97520 struct vfree_deferred *p = container_of(w, struct vfree_deferred, wq);
97521 struct llist_node *llnode = llist_del_all(&p->list);
97522 while (llnode) {
97523 - void *p = llnode;
97524 + void *x = llnode;
97525 llnode = llist_next(llnode);
97526 - __vunmap(p, 1);
97527 + __vunmap(x, 1);
97528 }
97529 }
97530
97531 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
97532 +static void unmap_work(struct work_struct *w)
97533 +{
97534 + struct stack_deferred *p = container_of(w, struct stack_deferred, wq);
97535 + struct llist_node *llnode = llist_del_all(&p->list.list);
97536 + while (llnode) {
97537 + struct stack_deferred_llist *x =
97538 + llist_entry((struct llist_head *)llnode,
97539 + struct stack_deferred_llist, list);
97540 + void *stack = ACCESS_ONCE(x->stack);
97541 + void *lowmem_stack = ACCESS_ONCE(x->lowmem_stack);
97542 + llnode = llist_next(llnode);
97543 + __vunmap(stack, 0);
97544 + free_memcg_kmem_pages((unsigned long)lowmem_stack, THREAD_SIZE_ORDER);
97545 + }
97546 +}
97547 +#endif
97548 +
97549 /*** Page table manipulation functions ***/
97550
97551 static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
97552 @@ -61,8 +94,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
97553
97554 pte = pte_offset_kernel(pmd, addr);
97555 do {
97556 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
97557 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
97558 +
97559 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
97560 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
97561 + BUG_ON(!pte_exec(*pte));
97562 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
97563 + continue;
97564 + }
97565 +#endif
97566 +
97567 + {
97568 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
97569 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
97570 + }
97571 } while (pte++, addr += PAGE_SIZE, addr != end);
97572 }
97573
97574 @@ -122,16 +166,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
97575 pte = pte_alloc_kernel(pmd, addr);
97576 if (!pte)
97577 return -ENOMEM;
97578 +
97579 + pax_open_kernel();
97580 do {
97581 struct page *page = pages[*nr];
97582
97583 - if (WARN_ON(!pte_none(*pte)))
97584 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
97585 + if (pgprot_val(prot) & _PAGE_NX)
97586 +#endif
97587 +
97588 + if (!pte_none(*pte)) {
97589 + pax_close_kernel();
97590 + WARN_ON(1);
97591 return -EBUSY;
97592 - if (WARN_ON(!page))
97593 + }
97594 + if (!page) {
97595 + pax_close_kernel();
97596 + WARN_ON(1);
97597 return -ENOMEM;
97598 + }
97599 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
97600 (*nr)++;
97601 } while (pte++, addr += PAGE_SIZE, addr != end);
97602 + pax_close_kernel();
97603 return 0;
97604 }
97605
97606 @@ -141,7 +198,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
97607 pmd_t *pmd;
97608 unsigned long next;
97609
97610 - pmd = pmd_alloc(&init_mm, pud, addr);
97611 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
97612 if (!pmd)
97613 return -ENOMEM;
97614 do {
97615 @@ -158,7 +215,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
97616 pud_t *pud;
97617 unsigned long next;
97618
97619 - pud = pud_alloc(&init_mm, pgd, addr);
97620 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
97621 if (!pud)
97622 return -ENOMEM;
97623 do {
97624 @@ -218,6 +275,12 @@ int is_vmalloc_or_module_addr(const void *x)
97625 if (addr >= MODULES_VADDR && addr < MODULES_END)
97626 return 1;
97627 #endif
97628 +
97629 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
97630 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
97631 + return 1;
97632 +#endif
97633 +
97634 return is_vmalloc_addr(x);
97635 }
97636
97637 @@ -238,8 +301,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
97638
97639 if (!pgd_none(*pgd)) {
97640 pud_t *pud = pud_offset(pgd, addr);
97641 +#ifdef CONFIG_X86
97642 + if (!pud_large(*pud))
97643 +#endif
97644 if (!pud_none(*pud)) {
97645 pmd_t *pmd = pmd_offset(pud, addr);
97646 +#ifdef CONFIG_X86
97647 + if (!pmd_large(*pmd))
97648 +#endif
97649 if (!pmd_none(*pmd)) {
97650 pte_t *ptep, pte;
97651
97652 @@ -1183,13 +1252,23 @@ void __init vmalloc_init(void)
97653 for_each_possible_cpu(i) {
97654 struct vmap_block_queue *vbq;
97655 struct vfree_deferred *p;
97656 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
97657 + struct stack_deferred *p2;
97658 +#endif
97659
97660 vbq = &per_cpu(vmap_block_queue, i);
97661 spin_lock_init(&vbq->lock);
97662 INIT_LIST_HEAD(&vbq->free);
97663 +
97664 p = &per_cpu(vfree_deferred, i);
97665 init_llist_head(&p->list);
97666 INIT_WORK(&p->wq, free_work);
97667 +
97668 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
97669 + p2 = &per_cpu(stack_deferred, i);
97670 + init_llist_head(&p2->list.list);
97671 + INIT_WORK(&p2->wq, unmap_work);
97672 +#endif
97673 }
97674
97675 /* Import existing vmlist entries. */
97676 @@ -1317,6 +1396,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
97677 struct vm_struct *area;
97678
97679 BUG_ON(in_interrupt());
97680 +
97681 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
97682 + if (flags & VM_KERNEXEC) {
97683 + if (start != VMALLOC_START || end != VMALLOC_END)
97684 + return NULL;
97685 + start = (unsigned long)MODULES_EXEC_VADDR;
97686 + end = (unsigned long)MODULES_EXEC_END;
97687 + }
97688 +#endif
97689 +
97690 if (flags & VM_IOREMAP)
97691 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
97692
97693 @@ -1522,6 +1611,23 @@ void vunmap(const void *addr)
97694 }
97695 EXPORT_SYMBOL(vunmap);
97696
97697 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
97698 +void unmap_process_stacks(struct task_struct *task)
97699 +{
97700 + if (unlikely(in_interrupt())) {
97701 + struct stack_deferred *p = &__get_cpu_var(stack_deferred);
97702 + struct stack_deferred_llist *list = task->stack;
97703 + list->stack = task->stack;
97704 + list->lowmem_stack = task->lowmem_stack;
97705 + if (llist_add((struct llist_node *)&list->list, &p->list.list))
97706 + schedule_work(&p->wq);
97707 + } else {
97708 + __vunmap(task->stack, 0);
97709 + free_memcg_kmem_pages((unsigned long)task->lowmem_stack, THREAD_SIZE_ORDER);
97710 + }
97711 +}
97712 +#endif
97713 +
97714 /**
97715 * vmap - map an array of pages into virtually contiguous space
97716 * @pages: array of page pointers
97717 @@ -1542,6 +1648,11 @@ void *vmap(struct page **pages, unsigned int count,
97718 if (count > totalram_pages)
97719 return NULL;
97720
97721 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
97722 + if (!(pgprot_val(prot) & _PAGE_NX))
97723 + flags |= VM_KERNEXEC;
97724 +#endif
97725 +
97726 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
97727 __builtin_return_address(0));
97728 if (!area)
97729 @@ -1642,6 +1753,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
97730 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
97731 goto fail;
97732
97733 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
97734 + if (!(pgprot_val(prot) & _PAGE_NX))
97735 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
97736 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
97737 + else
97738 +#endif
97739 +
97740 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
97741 start, end, node, gfp_mask, caller);
97742 if (!area)
97743 @@ -1818,10 +1936,9 @@ EXPORT_SYMBOL(vzalloc_node);
97744 * For tight control over page level allocator and protection flags
97745 * use __vmalloc() instead.
97746 */
97747 -
97748 void *vmalloc_exec(unsigned long size)
97749 {
97750 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
97751 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
97752 NUMA_NO_NODE, __builtin_return_address(0));
97753 }
97754
97755 @@ -2128,6 +2245,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
97756 {
97757 struct vm_struct *area;
97758
97759 + BUG_ON(vma->vm_mirror);
97760 +
97761 size = PAGE_ALIGN(size);
97762
97763 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
97764 @@ -2610,7 +2729,11 @@ static int s_show(struct seq_file *m, void *p)
97765 v->addr, v->addr + v->size, v->size);
97766
97767 if (v->caller)
97768 +#ifdef CONFIG_GRKERNSEC_HIDESYM
97769 + seq_printf(m, " %pK", v->caller);
97770 +#else
97771 seq_printf(m, " %pS", v->caller);
97772 +#endif
97773
97774 if (v->nr_pages)
97775 seq_printf(m, " pages=%d", v->nr_pages);
97776 diff --git a/mm/vmstat.c b/mm/vmstat.c
97777 index 302dd07..3841f1c 100644
97778 --- a/mm/vmstat.c
97779 +++ b/mm/vmstat.c
97780 @@ -20,6 +20,7 @@
97781 #include <linux/writeback.h>
97782 #include <linux/compaction.h>
97783 #include <linux/mm_inline.h>
97784 +#include <linux/grsecurity.h>
97785
97786 #include "internal.h"
97787
97788 @@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
97789 *
97790 * vm_stat contains the global counters
97791 */
97792 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
97793 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
97794 EXPORT_SYMBOL(vm_stat);
97795
97796 #ifdef CONFIG_SMP
97797 @@ -423,7 +424,7 @@ static inline void fold_diff(int *diff)
97798
97799 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
97800 if (diff[i])
97801 - atomic_long_add(diff[i], &vm_stat[i]);
97802 + atomic_long_add_unchecked(diff[i], &vm_stat[i]);
97803 }
97804
97805 /*
97806 @@ -455,7 +456,7 @@ static void refresh_cpu_vm_stats(void)
97807 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
97808 if (v) {
97809
97810 - atomic_long_add(v, &zone->vm_stat[i]);
97811 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97812 global_diff[i] += v;
97813 #ifdef CONFIG_NUMA
97814 /* 3 seconds idle till flush */
97815 @@ -517,7 +518,7 @@ void cpu_vm_stats_fold(int cpu)
97816
97817 v = p->vm_stat_diff[i];
97818 p->vm_stat_diff[i] = 0;
97819 - atomic_long_add(v, &zone->vm_stat[i]);
97820 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97821 global_diff[i] += v;
97822 }
97823 }
97824 @@ -537,8 +538,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
97825 if (pset->vm_stat_diff[i]) {
97826 int v = pset->vm_stat_diff[i];
97827 pset->vm_stat_diff[i] = 0;
97828 - atomic_long_add(v, &zone->vm_stat[i]);
97829 - atomic_long_add(v, &vm_stat[i]);
97830 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97831 + atomic_long_add_unchecked(v, &vm_stat[i]);
97832 }
97833 }
97834 #endif
97835 @@ -1156,10 +1157,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
97836 stat_items_size += sizeof(struct vm_event_state);
97837 #endif
97838
97839 - v = kmalloc(stat_items_size, GFP_KERNEL);
97840 + v = kzalloc(stat_items_size, GFP_KERNEL);
97841 m->private = v;
97842 if (!v)
97843 return ERR_PTR(-ENOMEM);
97844 +
97845 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
97846 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
97847 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
97848 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
97849 + && !in_group_p(grsec_proc_gid)
97850 +#endif
97851 + )
97852 + return (unsigned long *)m->private + *pos;
97853 +#endif
97854 +#endif
97855 +
97856 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
97857 v[i] = global_page_state(i);
97858 v += NR_VM_ZONE_STAT_ITEMS;
97859 @@ -1308,10 +1321,16 @@ static int __init setup_vmstat(void)
97860 cpu_notifier_register_done();
97861 #endif
97862 #ifdef CONFIG_PROC_FS
97863 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
97864 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
97865 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
97866 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
97867 + {
97868 + mode_t gr_mode = S_IRUGO;
97869 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
97870 + gr_mode = S_IRUSR;
97871 +#endif
97872 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
97873 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
97874 + proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
97875 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
97876 + }
97877 #endif
97878 return 0;
97879 }
97880 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
97881 index 44ebd5c..1f732bae 100644
97882 --- a/net/8021q/vlan.c
97883 +++ b/net/8021q/vlan.c
97884 @@ -475,7 +475,7 @@ out:
97885 return NOTIFY_DONE;
97886 }
97887
97888 -static struct notifier_block vlan_notifier_block __read_mostly = {
97889 +static struct notifier_block vlan_notifier_block = {
97890 .notifier_call = vlan_device_event,
97891 };
97892
97893 @@ -550,8 +550,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
97894 err = -EPERM;
97895 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
97896 break;
97897 - if ((args.u.name_type >= 0) &&
97898 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
97899 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
97900 struct vlan_net *vn;
97901
97902 vn = net_generic(net, vlan_net_id);
97903 diff --git a/net/9p/client.c b/net/9p/client.c
97904 index 0004cba..feba240 100644
97905 --- a/net/9p/client.c
97906 +++ b/net/9p/client.c
97907 @@ -596,7 +596,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
97908 len - inline_len);
97909 } else {
97910 err = copy_from_user(ename + inline_len,
97911 - uidata, len - inline_len);
97912 + (char __force_user *)uidata, len - inline_len);
97913 if (err) {
97914 err = -EFAULT;
97915 goto out_err;
97916 @@ -1571,7 +1571,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
97917 kernel_buf = 1;
97918 indata = data;
97919 } else
97920 - indata = (__force char *)udata;
97921 + indata = (__force_kernel char *)udata;
97922 /*
97923 * response header len is 11
97924 * PDU Header(7) + IO Size (4)
97925 @@ -1646,7 +1646,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
97926 kernel_buf = 1;
97927 odata = data;
97928 } else
97929 - odata = (char *)udata;
97930 + odata = (char __force_kernel *)udata;
97931 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
97932 P9_ZC_HDR_SZ, kernel_buf, "dqd",
97933 fid->fid, offset, rsize);
97934 diff --git a/net/9p/mod.c b/net/9p/mod.c
97935 index 6ab36ae..6f1841b 100644
97936 --- a/net/9p/mod.c
97937 +++ b/net/9p/mod.c
97938 @@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
97939 void v9fs_register_trans(struct p9_trans_module *m)
97940 {
97941 spin_lock(&v9fs_trans_lock);
97942 - list_add_tail(&m->list, &v9fs_trans_list);
97943 + pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
97944 spin_unlock(&v9fs_trans_lock);
97945 }
97946 EXPORT_SYMBOL(v9fs_register_trans);
97947 @@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
97948 void v9fs_unregister_trans(struct p9_trans_module *m)
97949 {
97950 spin_lock(&v9fs_trans_lock);
97951 - list_del_init(&m->list);
97952 + pax_list_del_init((struct list_head *)&m->list);
97953 spin_unlock(&v9fs_trans_lock);
97954 }
97955 EXPORT_SYMBOL(v9fs_unregister_trans);
97956 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
97957 index 80d08f6..de63fd1 100644
97958 --- a/net/9p/trans_fd.c
97959 +++ b/net/9p/trans_fd.c
97960 @@ -428,7 +428,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
97961 oldfs = get_fs();
97962 set_fs(get_ds());
97963 /* The cast to a user pointer is valid due to the set_fs() */
97964 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
97965 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
97966 set_fs(oldfs);
97967
97968 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
97969 diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
97970 index af46bc4..f9adfcd 100644
97971 --- a/net/appletalk/atalk_proc.c
97972 +++ b/net/appletalk/atalk_proc.c
97973 @@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
97974 struct proc_dir_entry *p;
97975 int rc = -ENOMEM;
97976
97977 - atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
97978 + atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
97979 if (!atalk_proc_dir)
97980 goto out;
97981
97982 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
97983 index 876fbe8..8bbea9f 100644
97984 --- a/net/atm/atm_misc.c
97985 +++ b/net/atm/atm_misc.c
97986 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
97987 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
97988 return 1;
97989 atm_return(vcc, truesize);
97990 - atomic_inc(&vcc->stats->rx_drop);
97991 + atomic_inc_unchecked(&vcc->stats->rx_drop);
97992 return 0;
97993 }
97994 EXPORT_SYMBOL(atm_charge);
97995 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
97996 }
97997 }
97998 atm_return(vcc, guess);
97999 - atomic_inc(&vcc->stats->rx_drop);
98000 + atomic_inc_unchecked(&vcc->stats->rx_drop);
98001 return NULL;
98002 }
98003 EXPORT_SYMBOL(atm_alloc_charge);
98004 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
98005
98006 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
98007 {
98008 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
98009 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
98010 __SONET_ITEMS
98011 #undef __HANDLE_ITEM
98012 }
98013 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
98014
98015 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
98016 {
98017 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
98018 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
98019 __SONET_ITEMS
98020 #undef __HANDLE_ITEM
98021 }
98022 diff --git a/net/atm/lec.c b/net/atm/lec.c
98023 index 4c5b8ba..95f7005 100644
98024 --- a/net/atm/lec.c
98025 +++ b/net/atm/lec.c
98026 @@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
98027 }
98028
98029 static struct lane2_ops lane2_ops = {
98030 - lane2_resolve, /* resolve, spec 3.1.3 */
98031 - lane2_associate_req, /* associate_req, spec 3.1.4 */
98032 - NULL /* associate indicator, spec 3.1.5 */
98033 + .resolve = lane2_resolve,
98034 + .associate_req = lane2_associate_req,
98035 + .associate_indicator = NULL
98036 };
98037
98038 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
98039 diff --git a/net/atm/lec.h b/net/atm/lec.h
98040 index 4149db1..f2ab682 100644
98041 --- a/net/atm/lec.h
98042 +++ b/net/atm/lec.h
98043 @@ -48,7 +48,7 @@ struct lane2_ops {
98044 const u8 *tlvs, u32 sizeoftlvs);
98045 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
98046 const u8 *tlvs, u32 sizeoftlvs);
98047 -};
98048 +} __no_const;
98049
98050 /*
98051 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
98052 diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
98053 index d1b2d9a..d549f7f 100644
98054 --- a/net/atm/mpoa_caches.c
98055 +++ b/net/atm/mpoa_caches.c
98056 @@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
98057
98058
98059 static struct in_cache_ops ingress_ops = {
98060 - in_cache_add_entry, /* add_entry */
98061 - in_cache_get, /* get */
98062 - in_cache_get_with_mask, /* get_with_mask */
98063 - in_cache_get_by_vcc, /* get_by_vcc */
98064 - in_cache_put, /* put */
98065 - in_cache_remove_entry, /* remove_entry */
98066 - cache_hit, /* cache_hit */
98067 - clear_count_and_expired, /* clear_count */
98068 - check_resolving_entries, /* check_resolving */
98069 - refresh_entries, /* refresh */
98070 - in_destroy_cache /* destroy_cache */
98071 + .add_entry = in_cache_add_entry,
98072 + .get = in_cache_get,
98073 + .get_with_mask = in_cache_get_with_mask,
98074 + .get_by_vcc = in_cache_get_by_vcc,
98075 + .put = in_cache_put,
98076 + .remove_entry = in_cache_remove_entry,
98077 + .cache_hit = cache_hit,
98078 + .clear_count = clear_count_and_expired,
98079 + .check_resolving = check_resolving_entries,
98080 + .refresh = refresh_entries,
98081 + .destroy_cache = in_destroy_cache
98082 };
98083
98084 static struct eg_cache_ops egress_ops = {
98085 - eg_cache_add_entry, /* add_entry */
98086 - eg_cache_get_by_cache_id, /* get_by_cache_id */
98087 - eg_cache_get_by_tag, /* get_by_tag */
98088 - eg_cache_get_by_vcc, /* get_by_vcc */
98089 - eg_cache_get_by_src_ip, /* get_by_src_ip */
98090 - eg_cache_put, /* put */
98091 - eg_cache_remove_entry, /* remove_entry */
98092 - update_eg_cache_entry, /* update */
98093 - clear_expired, /* clear_expired */
98094 - eg_destroy_cache /* destroy_cache */
98095 + .add_entry = eg_cache_add_entry,
98096 + .get_by_cache_id = eg_cache_get_by_cache_id,
98097 + .get_by_tag = eg_cache_get_by_tag,
98098 + .get_by_vcc = eg_cache_get_by_vcc,
98099 + .get_by_src_ip = eg_cache_get_by_src_ip,
98100 + .put = eg_cache_put,
98101 + .remove_entry = eg_cache_remove_entry,
98102 + .update = update_eg_cache_entry,
98103 + .clear_expired = clear_expired,
98104 + .destroy_cache = eg_destroy_cache
98105 };
98106
98107
98108 diff --git a/net/atm/proc.c b/net/atm/proc.c
98109 index bbb6461..cf04016 100644
98110 --- a/net/atm/proc.c
98111 +++ b/net/atm/proc.c
98112 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
98113 const struct k_atm_aal_stats *stats)
98114 {
98115 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
98116 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
98117 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
98118 - atomic_read(&stats->rx_drop));
98119 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
98120 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
98121 + atomic_read_unchecked(&stats->rx_drop));
98122 }
98123
98124 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
98125 diff --git a/net/atm/resources.c b/net/atm/resources.c
98126 index 0447d5d..3cf4728 100644
98127 --- a/net/atm/resources.c
98128 +++ b/net/atm/resources.c
98129 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
98130 static void copy_aal_stats(struct k_atm_aal_stats *from,
98131 struct atm_aal_stats *to)
98132 {
98133 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
98134 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
98135 __AAL_STAT_ITEMS
98136 #undef __HANDLE_ITEM
98137 }
98138 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
98139 static void subtract_aal_stats(struct k_atm_aal_stats *from,
98140 struct atm_aal_stats *to)
98141 {
98142 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
98143 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
98144 __AAL_STAT_ITEMS
98145 #undef __HANDLE_ITEM
98146 }
98147 diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
98148 index 919a5ce..cc6b444 100644
98149 --- a/net/ax25/sysctl_net_ax25.c
98150 +++ b/net/ax25/sysctl_net_ax25.c
98151 @@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
98152 {
98153 char path[sizeof("net/ax25/") + IFNAMSIZ];
98154 int k;
98155 - struct ctl_table *table;
98156 + ctl_table_no_const *table;
98157
98158 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
98159 if (!table)
98160 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
98161 index f04224c..f326579 100644
98162 --- a/net/batman-adv/bat_iv_ogm.c
98163 +++ b/net/batman-adv/bat_iv_ogm.c
98164 @@ -312,7 +312,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
98165
98166 /* randomize initial seqno to avoid collision */
98167 get_random_bytes(&random_seqno, sizeof(random_seqno));
98168 - atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
98169 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
98170
98171 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
98172 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
98173 @@ -917,9 +917,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
98174 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
98175
98176 /* change sequence number to network order */
98177 - seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
98178 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
98179 batadv_ogm_packet->seqno = htonl(seqno);
98180 - atomic_inc(&hard_iface->bat_iv.ogm_seqno);
98181 + atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
98182
98183 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
98184
98185 @@ -1596,7 +1596,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
98186 return;
98187
98188 /* could be changed by schedule_own_packet() */
98189 - if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
98190 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
98191
98192 if (ogm_packet->flags & BATADV_DIRECTLINK)
98193 has_directlink_flag = true;
98194 diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
98195 index 022d18a..919daff 100644
98196 --- a/net/batman-adv/fragmentation.c
98197 +++ b/net/batman-adv/fragmentation.c
98198 @@ -450,7 +450,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
98199 frag_header.packet_type = BATADV_UNICAST_FRAG;
98200 frag_header.version = BATADV_COMPAT_VERSION;
98201 frag_header.ttl = BATADV_TTL;
98202 - frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
98203 + frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
98204 frag_header.reserved = 0;
98205 frag_header.no = 0;
98206 frag_header.total_size = htons(skb->len);
98207 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
98208 index 744a59b..8fd037c 100644
98209 --- a/net/batman-adv/soft-interface.c
98210 +++ b/net/batman-adv/soft-interface.c
98211 @@ -296,7 +296,7 @@ send:
98212 primary_if->net_dev->dev_addr);
98213
98214 /* set broadcast sequence number */
98215 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
98216 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
98217 bcast_packet->seqno = htonl(seqno);
98218
98219 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
98220 @@ -729,7 +729,7 @@ static int batadv_softif_init_late(struct net_device *dev)
98221 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
98222
98223 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
98224 - atomic_set(&bat_priv->bcast_seqno, 1);
98225 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
98226 atomic_set(&bat_priv->tt.vn, 0);
98227 atomic_set(&bat_priv->tt.local_changes, 0);
98228 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
98229 @@ -743,7 +743,7 @@ static int batadv_softif_init_late(struct net_device *dev)
98230
98231 /* randomize initial seqno to avoid collision */
98232 get_random_bytes(&random_seqno, sizeof(random_seqno));
98233 - atomic_set(&bat_priv->frag_seqno, random_seqno);
98234 + atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
98235
98236 bat_priv->primary_if = NULL;
98237 bat_priv->num_ifaces = 0;
98238 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
98239 index 34891a5..3cfece0 100644
98240 --- a/net/batman-adv/types.h
98241 +++ b/net/batman-adv/types.h
98242 @@ -67,7 +67,7 @@ enum batadv_dhcp_recipient {
98243 struct batadv_hard_iface_bat_iv {
98244 unsigned char *ogm_buff;
98245 int ogm_buff_len;
98246 - atomic_t ogm_seqno;
98247 + atomic_unchecked_t ogm_seqno;
98248 };
98249
98250 /**
98251 @@ -766,7 +766,7 @@ struct batadv_priv {
98252 atomic_t bonding;
98253 atomic_t fragmentation;
98254 atomic_t packet_size_max;
98255 - atomic_t frag_seqno;
98256 + atomic_unchecked_t frag_seqno;
98257 #ifdef CONFIG_BATMAN_ADV_BLA
98258 atomic_t bridge_loop_avoidance;
98259 #endif
98260 @@ -785,7 +785,7 @@ struct batadv_priv {
98261 #endif
98262 uint32_t isolation_mark;
98263 uint32_t isolation_mark_mask;
98264 - atomic_t bcast_seqno;
98265 + atomic_unchecked_t bcast_seqno;
98266 atomic_t bcast_queue_left;
98267 atomic_t batman_queue_left;
98268 char num_ifaces;
98269 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
98270 index b9a418e..2af862a 100644
98271 --- a/net/bluetooth/hci_sock.c
98272 +++ b/net/bluetooth/hci_sock.c
98273 @@ -1053,7 +1053,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
98274 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
98275 }
98276
98277 - len = min_t(unsigned int, len, sizeof(uf));
98278 + len = min((size_t)len, sizeof(uf));
98279 if (copy_from_user(&uf, optval, len)) {
98280 err = -EFAULT;
98281 break;
98282 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
98283 index 1c97b7a..9171d69 100644
98284 --- a/net/bluetooth/l2cap_core.c
98285 +++ b/net/bluetooth/l2cap_core.c
98286 @@ -3542,8 +3542,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
98287 break;
98288
98289 case L2CAP_CONF_RFC:
98290 - if (olen == sizeof(rfc))
98291 - memcpy(&rfc, (void *)val, olen);
98292 + if (olen != sizeof(rfc))
98293 + break;
98294 +
98295 + memcpy(&rfc, (void *)val, olen);
98296
98297 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
98298 rfc.mode != chan->mode)
98299 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
98300 index e137869..33f3ebd 100644
98301 --- a/net/bluetooth/l2cap_sock.c
98302 +++ b/net/bluetooth/l2cap_sock.c
98303 @@ -628,7 +628,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
98304 struct sock *sk = sock->sk;
98305 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
98306 struct l2cap_options opts;
98307 - int len, err = 0;
98308 + int err = 0;
98309 + size_t len = optlen;
98310 u32 opt;
98311
98312 BT_DBG("sk %p", sk);
98313 @@ -655,7 +656,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
98314 opts.max_tx = chan->max_tx;
98315 opts.txwin_size = chan->tx_win;
98316
98317 - len = min_t(unsigned int, sizeof(opts), optlen);
98318 + len = min(sizeof(opts), len);
98319 if (copy_from_user((char *) &opts, optval, len)) {
98320 err = -EFAULT;
98321 break;
98322 @@ -742,7 +743,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
98323 struct bt_security sec;
98324 struct bt_power pwr;
98325 struct l2cap_conn *conn;
98326 - int len, err = 0;
98327 + int err = 0;
98328 + size_t len = optlen;
98329 u32 opt;
98330
98331 BT_DBG("sk %p", sk);
98332 @@ -766,7 +768,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
98333
98334 sec.level = BT_SECURITY_LOW;
98335
98336 - len = min_t(unsigned int, sizeof(sec), optlen);
98337 + len = min(sizeof(sec), len);
98338 if (copy_from_user((char *) &sec, optval, len)) {
98339 err = -EFAULT;
98340 break;
98341 @@ -861,7 +863,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
98342
98343 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
98344
98345 - len = min_t(unsigned int, sizeof(pwr), optlen);
98346 + len = min(sizeof(pwr), len);
98347 if (copy_from_user((char *) &pwr, optval, len)) {
98348 err = -EFAULT;
98349 break;
98350 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
98351 index c603a5e..7f08991 100644
98352 --- a/net/bluetooth/rfcomm/sock.c
98353 +++ b/net/bluetooth/rfcomm/sock.c
98354 @@ -687,7 +687,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
98355 struct sock *sk = sock->sk;
98356 struct bt_security sec;
98357 int err = 0;
98358 - size_t len;
98359 + size_t len = optlen;
98360 u32 opt;
98361
98362 BT_DBG("sk %p", sk);
98363 @@ -709,7 +709,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
98364
98365 sec.level = BT_SECURITY_LOW;
98366
98367 - len = min_t(unsigned int, sizeof(sec), optlen);
98368 + len = min(sizeof(sec), len);
98369 if (copy_from_user((char *) &sec, optval, len)) {
98370 err = -EFAULT;
98371 break;
98372 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
98373 index 403ec09..a21a003 100644
98374 --- a/net/bluetooth/rfcomm/tty.c
98375 +++ b/net/bluetooth/rfcomm/tty.c
98376 @@ -752,7 +752,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
98377 BT_DBG("tty %p id %d", tty, tty->index);
98378
98379 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
98380 - dev->channel, dev->port.count);
98381 + dev->channel, atomic_read(&dev->port.count));
98382
98383 err = tty_port_open(&dev->port, tty, filp);
98384 if (err)
98385 @@ -775,7 +775,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
98386 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
98387
98388 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
98389 - dev->port.count);
98390 + atomic_read(&dev->port.count));
98391
98392 tty_port_close(&dev->port, tty, filp);
98393 }
98394 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
98395 index 1059ed3..d70846a 100644
98396 --- a/net/bridge/netfilter/ebtables.c
98397 +++ b/net/bridge/netfilter/ebtables.c
98398 @@ -1524,7 +1524,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
98399 tmp.valid_hooks = t->table->valid_hooks;
98400 }
98401 mutex_unlock(&ebt_mutex);
98402 - if (copy_to_user(user, &tmp, *len) != 0) {
98403 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
98404 BUGPRINT("c2u Didn't work\n");
98405 ret = -EFAULT;
98406 break;
98407 @@ -2330,7 +2330,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
98408 goto out;
98409 tmp.valid_hooks = t->valid_hooks;
98410
98411 - if (copy_to_user(user, &tmp, *len) != 0) {
98412 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
98413 ret = -EFAULT;
98414 break;
98415 }
98416 @@ -2341,7 +2341,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
98417 tmp.entries_size = t->table->entries_size;
98418 tmp.valid_hooks = t->table->valid_hooks;
98419
98420 - if (copy_to_user(user, &tmp, *len) != 0) {
98421 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
98422 ret = -EFAULT;
98423 break;
98424 }
98425 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
98426 index 0f45522..dab651f 100644
98427 --- a/net/caif/cfctrl.c
98428 +++ b/net/caif/cfctrl.c
98429 @@ -10,6 +10,7 @@
98430 #include <linux/spinlock.h>
98431 #include <linux/slab.h>
98432 #include <linux/pkt_sched.h>
98433 +#include <linux/sched.h>
98434 #include <net/caif/caif_layer.h>
98435 #include <net/caif/cfpkt.h>
98436 #include <net/caif/cfctrl.h>
98437 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
98438 memset(&dev_info, 0, sizeof(dev_info));
98439 dev_info.id = 0xff;
98440 cfsrvl_init(&this->serv, 0, &dev_info, false);
98441 - atomic_set(&this->req_seq_no, 1);
98442 - atomic_set(&this->rsp_seq_no, 1);
98443 + atomic_set_unchecked(&this->req_seq_no, 1);
98444 + atomic_set_unchecked(&this->rsp_seq_no, 1);
98445 this->serv.layer.receive = cfctrl_recv;
98446 sprintf(this->serv.layer.name, "ctrl");
98447 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
98448 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
98449 struct cfctrl_request_info *req)
98450 {
98451 spin_lock_bh(&ctrl->info_list_lock);
98452 - atomic_inc(&ctrl->req_seq_no);
98453 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
98454 + atomic_inc_unchecked(&ctrl->req_seq_no);
98455 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
98456 list_add_tail(&req->list, &ctrl->list);
98457 spin_unlock_bh(&ctrl->info_list_lock);
98458 }
98459 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
98460 if (p != first)
98461 pr_warn("Requests are not received in order\n");
98462
98463 - atomic_set(&ctrl->rsp_seq_no,
98464 + atomic_set_unchecked(&ctrl->rsp_seq_no,
98465 p->sequence_no);
98466 list_del(&p->list);
98467 goto out;
98468 diff --git a/net/can/af_can.c b/net/can/af_can.c
98469 index a27f8aa..67174a3 100644
98470 --- a/net/can/af_can.c
98471 +++ b/net/can/af_can.c
98472 @@ -863,7 +863,7 @@ static const struct net_proto_family can_family_ops = {
98473 };
98474
98475 /* notifier block for netdevice event */
98476 -static struct notifier_block can_netdev_notifier __read_mostly = {
98477 +static struct notifier_block can_netdev_notifier = {
98478 .notifier_call = can_notifier,
98479 };
98480
98481 diff --git a/net/can/bcm.c b/net/can/bcm.c
98482 index dcb75c0..24b1b43 100644
98483 --- a/net/can/bcm.c
98484 +++ b/net/can/bcm.c
98485 @@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
98486 }
98487
98488 /* create /proc/net/can-bcm directory */
98489 - proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
98490 + proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
98491 return 0;
98492 }
98493
98494 diff --git a/net/can/gw.c b/net/can/gw.c
98495 index 050a211..bb9fe33 100644
98496 --- a/net/can/gw.c
98497 +++ b/net/can/gw.c
98498 @@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
98499 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
98500
98501 static HLIST_HEAD(cgw_list);
98502 -static struct notifier_block notifier;
98503
98504 static struct kmem_cache *cgw_cache __read_mostly;
98505
98506 @@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
98507 return err;
98508 }
98509
98510 +static struct notifier_block notifier = {
98511 + .notifier_call = cgw_notifier
98512 +};
98513 +
98514 static __init int cgw_module_init(void)
98515 {
98516 /* sanitize given module parameter */
98517 @@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
98518 return -ENOMEM;
98519
98520 /* set notifier */
98521 - notifier.notifier_call = cgw_notifier;
98522 register_netdevice_notifier(&notifier);
98523
98524 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
98525 diff --git a/net/can/proc.c b/net/can/proc.c
98526 index b543470..d2ddae2 100644
98527 --- a/net/can/proc.c
98528 +++ b/net/can/proc.c
98529 @@ -468,7 +468,7 @@ static void can_remove_proc_readentry(const char *name)
98530 void can_init_proc(void)
98531 {
98532 /* create /proc/net/can directory */
98533 - can_dir = proc_mkdir("can", init_net.proc_net);
98534 + can_dir = proc_mkdir_restrict("can", init_net.proc_net);
98535
98536 if (!can_dir) {
98537 printk(KERN_INFO "can: failed to create /proc/net/can . "
98538 diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
98539 index 1948d59..9e854d5 100644
98540 --- a/net/ceph/messenger.c
98541 +++ b/net/ceph/messenger.c
98542 @@ -187,7 +187,7 @@ static void con_fault(struct ceph_connection *con);
98543 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
98544
98545 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
98546 -static atomic_t addr_str_seq = ATOMIC_INIT(0);
98547 +static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
98548
98549 static struct page *zero_page; /* used in certain error cases */
98550
98551 @@ -198,7 +198,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
98552 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
98553 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
98554
98555 - i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
98556 + i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
98557 s = addr_str[i];
98558
98559 switch (ss->ss_family) {
98560 diff --git a/net/compat.c b/net/compat.c
98561 index bc8aeef..f9c070c 100644
98562 --- a/net/compat.c
98563 +++ b/net/compat.c
98564 @@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
98565 return -EFAULT;
98566 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
98567 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
98568 - kmsg->msg_name = compat_ptr(tmp1);
98569 - kmsg->msg_iov = compat_ptr(tmp2);
98570 - kmsg->msg_control = compat_ptr(tmp3);
98571 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
98572 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
98573 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
98574 return 0;
98575 }
98576
98577 @@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
98578
98579 if (kern_msg->msg_name && kern_msg->msg_namelen) {
98580 if (mode == VERIFY_READ) {
98581 - int err = move_addr_to_kernel(kern_msg->msg_name,
98582 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
98583 kern_msg->msg_namelen,
98584 kern_address);
98585 if (err < 0)
98586 @@ -100,7 +100,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
98587 }
98588
98589 tot_len = iov_from_user_compat_to_kern(kern_iov,
98590 - (struct compat_iovec __user *)kern_msg->msg_iov,
98591 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
98592 kern_msg->msg_iovlen);
98593 if (tot_len >= 0)
98594 kern_msg->msg_iov = kern_iov;
98595 @@ -120,20 +120,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
98596
98597 #define CMSG_COMPAT_FIRSTHDR(msg) \
98598 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
98599 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
98600 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
98601 (struct compat_cmsghdr __user *)NULL)
98602
98603 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
98604 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
98605 (ucmlen) <= (unsigned long) \
98606 ((mhdr)->msg_controllen - \
98607 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
98608 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
98609
98610 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
98611 struct compat_cmsghdr __user *cmsg, int cmsg_len)
98612 {
98613 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
98614 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
98615 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
98616 msg->msg_controllen)
98617 return NULL;
98618 return (struct compat_cmsghdr __user *)ptr;
98619 @@ -223,7 +223,7 @@ Efault:
98620
98621 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
98622 {
98623 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
98624 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
98625 struct compat_cmsghdr cmhdr;
98626 struct compat_timeval ctv;
98627 struct compat_timespec cts[3];
98628 @@ -279,7 +279,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
98629
98630 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
98631 {
98632 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
98633 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
98634 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
98635 int fdnum = scm->fp->count;
98636 struct file **fp = scm->fp->fp;
98637 @@ -367,7 +367,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
98638 return -EFAULT;
98639 old_fs = get_fs();
98640 set_fs(KERNEL_DS);
98641 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
98642 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
98643 set_fs(old_fs);
98644
98645 return err;
98646 @@ -428,7 +428,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
98647 len = sizeof(ktime);
98648 old_fs = get_fs();
98649 set_fs(KERNEL_DS);
98650 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
98651 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
98652 set_fs(old_fs);
98653
98654 if (!err) {
98655 @@ -571,7 +571,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
98656 case MCAST_JOIN_GROUP:
98657 case MCAST_LEAVE_GROUP:
98658 {
98659 - struct compat_group_req __user *gr32 = (void *)optval;
98660 + struct compat_group_req __user *gr32 = (void __user *)optval;
98661 struct group_req __user *kgr =
98662 compat_alloc_user_space(sizeof(struct group_req));
98663 u32 interface;
98664 @@ -592,7 +592,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
98665 case MCAST_BLOCK_SOURCE:
98666 case MCAST_UNBLOCK_SOURCE:
98667 {
98668 - struct compat_group_source_req __user *gsr32 = (void *)optval;
98669 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
98670 struct group_source_req __user *kgsr = compat_alloc_user_space(
98671 sizeof(struct group_source_req));
98672 u32 interface;
98673 @@ -613,7 +613,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
98674 }
98675 case MCAST_MSFILTER:
98676 {
98677 - struct compat_group_filter __user *gf32 = (void *)optval;
98678 + struct compat_group_filter __user *gf32 = (void __user *)optval;
98679 struct group_filter __user *kgf;
98680 u32 interface, fmode, numsrc;
98681
98682 @@ -651,7 +651,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
98683 char __user *optval, int __user *optlen,
98684 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
98685 {
98686 - struct compat_group_filter __user *gf32 = (void *)optval;
98687 + struct compat_group_filter __user *gf32 = (void __user *)optval;
98688 struct group_filter __user *kgf;
98689 int __user *koptlen;
98690 u32 interface, fmode, numsrc;
98691 @@ -804,7 +804,7 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args)
98692
98693 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
98694 return -EINVAL;
98695 - if (copy_from_user(a, args, nas[call]))
98696 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
98697 return -EFAULT;
98698 a0 = a[0];
98699 a1 = a[1];
98700 diff --git a/net/core/datagram.c b/net/core/datagram.c
98701 index a16ed7b..eb44d17 100644
98702 --- a/net/core/datagram.c
98703 +++ b/net/core/datagram.c
98704 @@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
98705 }
98706
98707 kfree_skb(skb);
98708 - atomic_inc(&sk->sk_drops);
98709 + atomic_inc_unchecked(&sk->sk_drops);
98710 sk_mem_reclaim_partial(sk);
98711
98712 return err;
98713 diff --git a/net/core/dev.c b/net/core/dev.c
98714 index a7621f3..ca7dac3 100644
98715 --- a/net/core/dev.c
98716 +++ b/net/core/dev.c
98717 @@ -1690,14 +1690,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
98718 {
98719 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
98720 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
98721 - atomic_long_inc(&dev->rx_dropped);
98722 + atomic_long_inc_unchecked(&dev->rx_dropped);
98723 kfree_skb(skb);
98724 return NET_RX_DROP;
98725 }
98726 }
98727
98728 if (unlikely(!is_skb_forwardable(dev, skb))) {
98729 - atomic_long_inc(&dev->rx_dropped);
98730 + atomic_long_inc_unchecked(&dev->rx_dropped);
98731 kfree_skb(skb);
98732 return NET_RX_DROP;
98733 }
98734 @@ -2470,7 +2470,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
98735
98736 struct dev_gso_cb {
98737 void (*destructor)(struct sk_buff *skb);
98738 -};
98739 +} __no_const;
98740
98741 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
98742
98743 @@ -2900,7 +2900,7 @@ recursion_alert:
98744 rc = -ENETDOWN;
98745 rcu_read_unlock_bh();
98746
98747 - atomic_long_inc(&dev->tx_dropped);
98748 + atomic_long_inc_unchecked(&dev->tx_dropped);
98749 kfree_skb(skb);
98750 return rc;
98751 out:
98752 @@ -3244,7 +3244,7 @@ enqueue:
98753
98754 local_irq_restore(flags);
98755
98756 - atomic_long_inc(&skb->dev->rx_dropped);
98757 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
98758 kfree_skb(skb);
98759 return NET_RX_DROP;
98760 }
98761 @@ -3321,7 +3321,7 @@ int netif_rx_ni(struct sk_buff *skb)
98762 }
98763 EXPORT_SYMBOL(netif_rx_ni);
98764
98765 -static void net_tx_action(struct softirq_action *h)
98766 +static __latent_entropy void net_tx_action(void)
98767 {
98768 struct softnet_data *sd = &__get_cpu_var(softnet_data);
98769
98770 @@ -3654,7 +3654,7 @@ ncls:
98771 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
98772 } else {
98773 drop:
98774 - atomic_long_inc(&skb->dev->rx_dropped);
98775 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
98776 kfree_skb(skb);
98777 /* Jamal, now you will not able to escape explaining
98778 * me how you were going to use this. :-)
98779 @@ -4375,7 +4375,7 @@ void netif_napi_del(struct napi_struct *napi)
98780 }
98781 EXPORT_SYMBOL(netif_napi_del);
98782
98783 -static void net_rx_action(struct softirq_action *h)
98784 +static __latent_entropy void net_rx_action(void)
98785 {
98786 struct softnet_data *sd = &__get_cpu_var(softnet_data);
98787 unsigned long time_limit = jiffies + 2;
98788 @@ -6375,8 +6375,8 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
98789 } else {
98790 netdev_stats_to_stats64(storage, &dev->stats);
98791 }
98792 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
98793 - storage->tx_dropped += atomic_long_read(&dev->tx_dropped);
98794 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
98795 + storage->tx_dropped += atomic_long_read_unchecked(&dev->tx_dropped);
98796 return storage;
98797 }
98798 EXPORT_SYMBOL(dev_get_stats);
98799 diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
98800 index cf999e0..c59a975 100644
98801 --- a/net/core/dev_ioctl.c
98802 +++ b/net/core/dev_ioctl.c
98803 @@ -366,9 +366,13 @@ void dev_load(struct net *net, const char *name)
98804 if (no_module && capable(CAP_NET_ADMIN))
98805 no_module = request_module("netdev-%s", name);
98806 if (no_module && capable(CAP_SYS_MODULE)) {
98807 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
98808 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
98809 +#else
98810 if (!request_module("%s", name))
98811 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
98812 name);
98813 +#endif
98814 }
98815 }
98816 EXPORT_SYMBOL(dev_load);
98817 diff --git a/net/core/filter.c b/net/core/filter.c
98818 index 5310d5e..01f885e 100644
98819 --- a/net/core/filter.c
98820 +++ b/net/core/filter.c
98821 @@ -1121,7 +1121,11 @@ do_pass:
98822 break;
98823
98824 default:
98825 - goto err;
98826 + WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
98827 + fp->code, fp->jt, fp->jf, fp->k);
98828 + kfree(addrs);
98829 + BUG();
98830 + return -EINVAL;
98831 }
98832
98833 insn++;
98834 @@ -1170,7 +1174,7 @@ static int check_load_and_stores(struct sock_filter *filter, int flen)
98835 u16 *masks, memvalid = 0; /* one bit per cell, 16 cells */
98836 int pc, ret = 0;
98837
98838 - BUILD_BUG_ON(BPF_MEMWORDS > 16);
98839 + BUILD_BUG_ON(BPF_MEMWORDS != 16);
98840 masks = kmalloc(flen * sizeof(*masks), GFP_KERNEL);
98841 if (!masks)
98842 return -ENOMEM;
98843 @@ -1605,7 +1609,7 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
98844 if (!fp)
98845 return -ENOMEM;
98846
98847 - memcpy(fp->insns, fprog->filter, fsize);
98848 + memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
98849
98850 atomic_set(&fp->refcnt, 1);
98851 fp->len = fprog->len;
98852 diff --git a/net/core/flow.c b/net/core/flow.c
98853 index a0348fd..6951c76 100644
98854 --- a/net/core/flow.c
98855 +++ b/net/core/flow.c
98856 @@ -65,7 +65,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
98857 static int flow_entry_valid(struct flow_cache_entry *fle,
98858 struct netns_xfrm *xfrm)
98859 {
98860 - if (atomic_read(&xfrm->flow_cache_genid) != fle->genid)
98861 + if (atomic_read_unchecked(&xfrm->flow_cache_genid) != fle->genid)
98862 return 0;
98863 if (fle->object && !fle->object->ops->check(fle->object))
98864 return 0;
98865 @@ -242,7 +242,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
98866 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
98867 fcp->hash_count++;
98868 }
98869 - } else if (likely(fle->genid == atomic_read(&net->xfrm.flow_cache_genid))) {
98870 + } else if (likely(fle->genid == atomic_read_unchecked(&net->xfrm.flow_cache_genid))) {
98871 flo = fle->object;
98872 if (!flo)
98873 goto ret_object;
98874 @@ -263,7 +263,7 @@ nocache:
98875 }
98876 flo = resolver(net, key, family, dir, flo, ctx);
98877 if (fle) {
98878 - fle->genid = atomic_read(&net->xfrm.flow_cache_genid);
98879 + fle->genid = atomic_read_unchecked(&net->xfrm.flow_cache_genid);
98880 if (!IS_ERR(flo))
98881 fle->object = flo;
98882 else
98883 diff --git a/net/core/iovec.c b/net/core/iovec.c
98884 index 26dc006..89e838e 100644
98885 --- a/net/core/iovec.c
98886 +++ b/net/core/iovec.c
98887 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
98888 if (m->msg_name && m->msg_namelen) {
98889 if (mode == VERIFY_READ) {
98890 void __user *namep;
98891 - namep = (void __user __force *) m->msg_name;
98892 + namep = (void __force_user *) m->msg_name;
98893 err = move_addr_to_kernel(namep, m->msg_namelen,
98894 address);
98895 if (err < 0)
98896 @@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
98897 }
98898
98899 size = m->msg_iovlen * sizeof(struct iovec);
98900 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
98901 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
98902 return -EFAULT;
98903
98904 m->msg_iov = iov;
98905 diff --git a/net/core/neighbour.c b/net/core/neighbour.c
98906 index 32d872e..487e769 100644
98907 --- a/net/core/neighbour.c
98908 +++ b/net/core/neighbour.c
98909 @@ -2825,7 +2825,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
98910 void __user *buffer, size_t *lenp, loff_t *ppos)
98911 {
98912 int size, ret;
98913 - struct ctl_table tmp = *ctl;
98914 + ctl_table_no_const tmp = *ctl;
98915
98916 tmp.extra1 = &zero;
98917 tmp.extra2 = &unres_qlen_max;
98918 @@ -2887,7 +2887,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
98919 void __user *buffer,
98920 size_t *lenp, loff_t *ppos)
98921 {
98922 - struct ctl_table tmp = *ctl;
98923 + ctl_table_no_const tmp = *ctl;
98924 int ret;
98925
98926 tmp.extra1 = &zero;
98927 @@ -3059,11 +3059,12 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
98928 memset(&t->neigh_vars[NEIGH_VAR_GC_INTERVAL], 0,
98929 sizeof(t->neigh_vars[NEIGH_VAR_GC_INTERVAL]));
98930 } else {
98931 + struct neigh_table *ntable = container_of(p, struct neigh_table, parms);
98932 dev_name_source = "default";
98933 - t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = (int *)(p + 1);
98934 - t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = (int *)(p + 1) + 1;
98935 - t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = (int *)(p + 1) + 2;
98936 - t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = (int *)(p + 1) + 3;
98937 + t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = &ntable->gc_interval;
98938 + t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = &ntable->gc_thresh1;
98939 + t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = &ntable->gc_thresh2;
98940 + t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = &ntable->gc_thresh3;
98941 }
98942
98943 if (handler) {
98944 diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
98945 index 2bf8329..2eb1423 100644
98946 --- a/net/core/net-procfs.c
98947 +++ b/net/core/net-procfs.c
98948 @@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
98949 struct rtnl_link_stats64 temp;
98950 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
98951
98952 - seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98953 + if (gr_proc_is_restricted())
98954 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98955 + "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
98956 + dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
98957 + 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
98958 + else
98959 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98960 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
98961 dev->name, stats->rx_bytes, stats->rx_packets,
98962 stats->rx_errors,
98963 @@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
98964 return 0;
98965 }
98966
98967 -static const struct seq_operations dev_seq_ops = {
98968 +const struct seq_operations dev_seq_ops = {
98969 .start = dev_seq_start,
98970 .next = dev_seq_next,
98971 .stop = dev_seq_stop,
98972 @@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
98973
98974 static int softnet_seq_open(struct inode *inode, struct file *file)
98975 {
98976 - return seq_open(file, &softnet_seq_ops);
98977 + return seq_open_restrict(file, &softnet_seq_ops);
98978 }
98979
98980 static const struct file_operations softnet_seq_fops = {
98981 @@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
98982 else
98983 seq_printf(seq, "%04x", ntohs(pt->type));
98984
98985 +#ifdef CONFIG_GRKERNSEC_HIDESYM
98986 + seq_printf(seq, " %-8s %pf\n",
98987 + pt->dev ? pt->dev->name : "", NULL);
98988 +#else
98989 seq_printf(seq, " %-8s %pf\n",
98990 pt->dev ? pt->dev->name : "", pt->func);
98991 +#endif
98992 }
98993
98994 return 0;
98995 diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
98996 index 1cac29e..fb482f3 100644
98997 --- a/net/core/net-sysfs.c
98998 +++ b/net/core/net-sysfs.c
98999 @@ -259,7 +259,7 @@ static ssize_t carrier_changes_show(struct device *dev,
99000 {
99001 struct net_device *netdev = to_net_dev(dev);
99002 return sprintf(buf, fmt_dec,
99003 - atomic_read(&netdev->carrier_changes));
99004 + atomic_read_unchecked(&netdev->carrier_changes));
99005 }
99006 static DEVICE_ATTR_RO(carrier_changes);
99007
99008 diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
99009 index 7c8ffd9..0cb3687 100644
99010 --- a/net/core/net_namespace.c
99011 +++ b/net/core/net_namespace.c
99012 @@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
99013 int error;
99014 LIST_HEAD(net_exit_list);
99015
99016 - list_add_tail(&ops->list, list);
99017 + pax_list_add_tail((struct list_head *)&ops->list, list);
99018 if (ops->init || (ops->id && ops->size)) {
99019 for_each_net(net) {
99020 error = ops_init(ops, net);
99021 @@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
99022
99023 out_undo:
99024 /* If I have an error cleanup all namespaces I initialized */
99025 - list_del(&ops->list);
99026 + pax_list_del((struct list_head *)&ops->list);
99027 ops_exit_list(ops, &net_exit_list);
99028 ops_free_list(ops, &net_exit_list);
99029 return error;
99030 @@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
99031 struct net *net;
99032 LIST_HEAD(net_exit_list);
99033
99034 - list_del(&ops->list);
99035 + pax_list_del((struct list_head *)&ops->list);
99036 for_each_net(net)
99037 list_add_tail(&net->exit_list, &net_exit_list);
99038 ops_exit_list(ops, &net_exit_list);
99039 @@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
99040 mutex_lock(&net_mutex);
99041 error = register_pernet_operations(&pernet_list, ops);
99042 if (!error && (first_device == &pernet_list))
99043 - first_device = &ops->list;
99044 + first_device = (struct list_head *)&ops->list;
99045 mutex_unlock(&net_mutex);
99046 return error;
99047 }
99048 diff --git a/net/core/netpoll.c b/net/core/netpoll.c
99049 index e33937f..b2b4981 100644
99050 --- a/net/core/netpoll.c
99051 +++ b/net/core/netpoll.c
99052 @@ -382,7 +382,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
99053 struct udphdr *udph;
99054 struct iphdr *iph;
99055 struct ethhdr *eth;
99056 - static atomic_t ip_ident;
99057 + static atomic_unchecked_t ip_ident;
99058 struct ipv6hdr *ip6h;
99059
99060 udp_len = len + sizeof(*udph);
99061 @@ -453,7 +453,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
99062 put_unaligned(0x45, (unsigned char *)iph);
99063 iph->tos = 0;
99064 put_unaligned(htons(ip_len), &(iph->tot_len));
99065 - iph->id = htons(atomic_inc_return(&ip_ident));
99066 + iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
99067 iph->frag_off = 0;
99068 iph->ttl = 64;
99069 iph->protocol = IPPROTO_UDP;
99070 diff --git a/net/core/pktgen.c b/net/core/pktgen.c
99071 index 0304f98..ddfead6 100644
99072 --- a/net/core/pktgen.c
99073 +++ b/net/core/pktgen.c
99074 @@ -3725,7 +3725,7 @@ static int __net_init pg_net_init(struct net *net)
99075 pn->net = net;
99076 INIT_LIST_HEAD(&pn->pktgen_threads);
99077 pn->pktgen_exiting = false;
99078 - pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
99079 + pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
99080 if (!pn->proc_dir) {
99081 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
99082 return -ENODEV;
99083 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
99084 index 1999ed8..1e6e58a 100644
99085 --- a/net/core/rtnetlink.c
99086 +++ b/net/core/rtnetlink.c
99087 @@ -58,7 +58,7 @@ struct rtnl_link {
99088 rtnl_doit_func doit;
99089 rtnl_dumpit_func dumpit;
99090 rtnl_calcit_func calcit;
99091 -};
99092 +} __no_const;
99093
99094 static DEFINE_MUTEX(rtnl_mutex);
99095
99096 @@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
99097 if (rtnl_link_ops_get(ops->kind))
99098 return -EEXIST;
99099
99100 - if (!ops->dellink)
99101 - ops->dellink = unregister_netdevice_queue;
99102 + if (!ops->dellink) {
99103 + pax_open_kernel();
99104 + *(void **)&ops->dellink = unregister_netdevice_queue;
99105 + pax_close_kernel();
99106 + }
99107
99108 - list_add_tail(&ops->list, &link_ops);
99109 + pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
99110 return 0;
99111 }
99112 EXPORT_SYMBOL_GPL(__rtnl_link_register);
99113 @@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
99114 for_each_net(net) {
99115 __rtnl_kill_links(net, ops);
99116 }
99117 - list_del(&ops->list);
99118 + pax_list_del((struct list_head *)&ops->list);
99119 }
99120 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
99121
99122 @@ -1008,7 +1011,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
99123 (dev->ifalias &&
99124 nla_put_string(skb, IFLA_IFALIAS, dev->ifalias)) ||
99125 nla_put_u32(skb, IFLA_CARRIER_CHANGES,
99126 - atomic_read(&dev->carrier_changes)))
99127 + atomic_read_unchecked(&dev->carrier_changes)))
99128 goto nla_put_failure;
99129
99130 if (1) {
99131 diff --git a/net/core/scm.c b/net/core/scm.c
99132 index b442e7e..6f5b5a2 100644
99133 --- a/net/core/scm.c
99134 +++ b/net/core/scm.c
99135 @@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
99136 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
99137 {
99138 struct cmsghdr __user *cm
99139 - = (__force struct cmsghdr __user *)msg->msg_control;
99140 + = (struct cmsghdr __force_user *)msg->msg_control;
99141 struct cmsghdr cmhdr;
99142 int cmlen = CMSG_LEN(len);
99143 int err;
99144 @@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
99145 err = -EFAULT;
99146 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
99147 goto out;
99148 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
99149 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
99150 goto out;
99151 cmlen = CMSG_SPACE(len);
99152 if (msg->msg_controllen < cmlen)
99153 @@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
99154 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
99155 {
99156 struct cmsghdr __user *cm
99157 - = (__force struct cmsghdr __user*)msg->msg_control;
99158 + = (struct cmsghdr __force_user *)msg->msg_control;
99159
99160 int fdmax = 0;
99161 int fdnum = scm->fp->count;
99162 @@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
99163 if (fdnum < fdmax)
99164 fdmax = fdnum;
99165
99166 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
99167 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
99168 i++, cmfptr++)
99169 {
99170 struct socket *sock;
99171 diff --git a/net/core/skbuff.c b/net/core/skbuff.c
99172 index 6ab5f77..6fd2a81 100644
99173 --- a/net/core/skbuff.c
99174 +++ b/net/core/skbuff.c
99175 @@ -2003,7 +2003,7 @@ EXPORT_SYMBOL(__skb_checksum);
99176 __wsum skb_checksum(const struct sk_buff *skb, int offset,
99177 int len, __wsum csum)
99178 {
99179 - const struct skb_checksum_ops ops = {
99180 + static const struct skb_checksum_ops ops = {
99181 .update = csum_partial_ext,
99182 .combine = csum_block_add_ext,
99183 };
99184 @@ -3221,13 +3221,15 @@ void __init skb_init(void)
99185 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
99186 sizeof(struct sk_buff),
99187 0,
99188 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
99189 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
99190 + SLAB_NO_SANITIZE,
99191 NULL);
99192 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
99193 (2*sizeof(struct sk_buff)) +
99194 sizeof(atomic_t),
99195 0,
99196 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
99197 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
99198 + SLAB_NO_SANITIZE,
99199 NULL);
99200 }
99201
99202 diff --git a/net/core/sock.c b/net/core/sock.c
99203 index 664ee42..aaf9e6e 100644
99204 --- a/net/core/sock.c
99205 +++ b/net/core/sock.c
99206 @@ -442,7 +442,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
99207 struct sk_buff_head *list = &sk->sk_receive_queue;
99208
99209 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
99210 - atomic_inc(&sk->sk_drops);
99211 + atomic_inc_unchecked(&sk->sk_drops);
99212 trace_sock_rcvqueue_full(sk, skb);
99213 return -ENOMEM;
99214 }
99215 @@ -452,7 +452,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
99216 return err;
99217
99218 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
99219 - atomic_inc(&sk->sk_drops);
99220 + atomic_inc_unchecked(&sk->sk_drops);
99221 return -ENOBUFS;
99222 }
99223
99224 @@ -472,7 +472,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
99225 skb_dst_force(skb);
99226
99227 spin_lock_irqsave(&list->lock, flags);
99228 - skb->dropcount = atomic_read(&sk->sk_drops);
99229 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
99230 __skb_queue_tail(list, skb);
99231 spin_unlock_irqrestore(&list->lock, flags);
99232
99233 @@ -492,7 +492,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
99234 skb->dev = NULL;
99235
99236 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
99237 - atomic_inc(&sk->sk_drops);
99238 + atomic_inc_unchecked(&sk->sk_drops);
99239 goto discard_and_relse;
99240 }
99241 if (nested)
99242 @@ -510,7 +510,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
99243 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
99244 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
99245 bh_unlock_sock(sk);
99246 - atomic_inc(&sk->sk_drops);
99247 + atomic_inc_unchecked(&sk->sk_drops);
99248 goto discard_and_relse;
99249 }
99250
99251 @@ -998,12 +998,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
99252 struct timeval tm;
99253 } v;
99254
99255 - int lv = sizeof(int);
99256 - int len;
99257 + unsigned int lv = sizeof(int);
99258 + unsigned int len;
99259
99260 if (get_user(len, optlen))
99261 return -EFAULT;
99262 - if (len < 0)
99263 + if (len > INT_MAX)
99264 return -EINVAL;
99265
99266 memset(&v, 0, sizeof(v));
99267 @@ -1155,11 +1155,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
99268
99269 case SO_PEERNAME:
99270 {
99271 - char address[128];
99272 + char address[_K_SS_MAXSIZE];
99273
99274 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
99275 return -ENOTCONN;
99276 - if (lv < len)
99277 + if (lv < len || sizeof address < len)
99278 return -EINVAL;
99279 if (copy_to_user(optval, address, len))
99280 return -EFAULT;
99281 @@ -1240,7 +1240,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
99282
99283 if (len > lv)
99284 len = lv;
99285 - if (copy_to_user(optval, &v, len))
99286 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
99287 return -EFAULT;
99288 lenout:
99289 if (put_user(len, optlen))
99290 @@ -2375,7 +2375,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
99291 */
99292 smp_wmb();
99293 atomic_set(&sk->sk_refcnt, 1);
99294 - atomic_set(&sk->sk_drops, 0);
99295 + atomic_set_unchecked(&sk->sk_drops, 0);
99296 }
99297 EXPORT_SYMBOL(sock_init_data);
99298
99299 @@ -2503,6 +2503,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
99300 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
99301 int level, int type)
99302 {
99303 + struct sock_extended_err ee;
99304 struct sock_exterr_skb *serr;
99305 struct sk_buff *skb, *skb2;
99306 int copied, err;
99307 @@ -2524,7 +2525,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
99308 sock_recv_timestamp(msg, sk, skb);
99309
99310 serr = SKB_EXT_ERR(skb);
99311 - put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
99312 + ee = serr->ee;
99313 + put_cmsg(msg, level, type, sizeof ee, &ee);
99314
99315 msg->msg_flags |= MSG_ERRQUEUE;
99316 err = copied;
99317 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
99318 index a4216a4..1c07687 100644
99319 --- a/net/core/sock_diag.c
99320 +++ b/net/core/sock_diag.c
99321 @@ -9,26 +9,33 @@
99322 #include <linux/inet_diag.h>
99323 #include <linux/sock_diag.h>
99324
99325 -static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
99326 +static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
99327 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
99328 static DEFINE_MUTEX(sock_diag_table_mutex);
99329
99330 int sock_diag_check_cookie(void *sk, __u32 *cookie)
99331 {
99332 +#ifndef CONFIG_GRKERNSEC_HIDESYM
99333 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
99334 cookie[1] != INET_DIAG_NOCOOKIE) &&
99335 ((u32)(unsigned long)sk != cookie[0] ||
99336 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
99337 return -ESTALE;
99338 else
99339 +#endif
99340 return 0;
99341 }
99342 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
99343
99344 void sock_diag_save_cookie(void *sk, __u32 *cookie)
99345 {
99346 +#ifdef CONFIG_GRKERNSEC_HIDESYM
99347 + cookie[0] = 0;
99348 + cookie[1] = 0;
99349 +#else
99350 cookie[0] = (u32)(unsigned long)sk;
99351 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
99352 +#endif
99353 }
99354 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
99355
99356 @@ -110,8 +117,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
99357 mutex_lock(&sock_diag_table_mutex);
99358 if (sock_diag_handlers[hndl->family])
99359 err = -EBUSY;
99360 - else
99361 + else {
99362 + pax_open_kernel();
99363 sock_diag_handlers[hndl->family] = hndl;
99364 + pax_close_kernel();
99365 + }
99366 mutex_unlock(&sock_diag_table_mutex);
99367
99368 return err;
99369 @@ -127,7 +137,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
99370
99371 mutex_lock(&sock_diag_table_mutex);
99372 BUG_ON(sock_diag_handlers[family] != hnld);
99373 + pax_open_kernel();
99374 sock_diag_handlers[family] = NULL;
99375 + pax_close_kernel();
99376 mutex_unlock(&sock_diag_table_mutex);
99377 }
99378 EXPORT_SYMBOL_GPL(sock_diag_unregister);
99379 diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
99380 index cf9cd13..8b56af3 100644
99381 --- a/net/core/sysctl_net_core.c
99382 +++ b/net/core/sysctl_net_core.c
99383 @@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
99384 {
99385 unsigned int orig_size, size;
99386 int ret, i;
99387 - struct ctl_table tmp = {
99388 + ctl_table_no_const tmp = {
99389 .data = &size,
99390 .maxlen = sizeof(size),
99391 .mode = table->mode
99392 @@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
99393 void __user *buffer, size_t *lenp, loff_t *ppos)
99394 {
99395 char id[IFNAMSIZ];
99396 - struct ctl_table tbl = {
99397 + ctl_table_no_const tbl = {
99398 .data = id,
99399 .maxlen = IFNAMSIZ,
99400 };
99401 @@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
99402
99403 static __net_init int sysctl_core_net_init(struct net *net)
99404 {
99405 - struct ctl_table *tbl;
99406 + ctl_table_no_const *tbl = NULL;
99407
99408 net->core.sysctl_somaxconn = SOMAXCONN;
99409
99410 - tbl = netns_core_table;
99411 if (!net_eq(net, &init_net)) {
99412 - tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
99413 + tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
99414 if (tbl == NULL)
99415 goto err_dup;
99416
99417 @@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
99418 if (net->user_ns != &init_user_ns) {
99419 tbl[0].procname = NULL;
99420 }
99421 - }
99422 -
99423 - net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
99424 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
99425 + } else
99426 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
99427 if (net->core.sysctl_hdr == NULL)
99428 goto err_reg;
99429
99430 return 0;
99431
99432 err_reg:
99433 - if (tbl != netns_core_table)
99434 - kfree(tbl);
99435 + kfree(tbl);
99436 err_dup:
99437 return -ENOMEM;
99438 }
99439 @@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
99440 kfree(tbl);
99441 }
99442
99443 -static __net_initdata struct pernet_operations sysctl_core_ops = {
99444 +static __net_initconst struct pernet_operations sysctl_core_ops = {
99445 .init = sysctl_core_net_init,
99446 .exit = sysctl_core_net_exit,
99447 };
99448 diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
99449 index 4c04848..f575934 100644
99450 --- a/net/decnet/af_decnet.c
99451 +++ b/net/decnet/af_decnet.c
99452 @@ -465,6 +465,7 @@ static struct proto dn_proto = {
99453 .sysctl_rmem = sysctl_decnet_rmem,
99454 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
99455 .obj_size = sizeof(struct dn_sock),
99456 + .slab_flags = SLAB_USERCOPY,
99457 };
99458
99459 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
99460 diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
99461 index 3b726f3..1af6368 100644
99462 --- a/net/decnet/dn_dev.c
99463 +++ b/net/decnet/dn_dev.c
99464 @@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
99465 .extra1 = &min_t3,
99466 .extra2 = &max_t3
99467 },
99468 - {0}
99469 + { }
99470 },
99471 };
99472
99473 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
99474 index 5325b54..a0d4d69 100644
99475 --- a/net/decnet/sysctl_net_decnet.c
99476 +++ b/net/decnet/sysctl_net_decnet.c
99477 @@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
99478
99479 if (len > *lenp) len = *lenp;
99480
99481 - if (copy_to_user(buffer, addr, len))
99482 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
99483 return -EFAULT;
99484
99485 *lenp = len;
99486 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
99487
99488 if (len > *lenp) len = *lenp;
99489
99490 - if (copy_to_user(buffer, devname, len))
99491 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
99492 return -EFAULT;
99493
99494 *lenp = len;
99495 diff --git a/net/ieee802154/reassembly.c b/net/ieee802154/reassembly.c
99496 index ef2d543..5b9b73f 100644
99497 --- a/net/ieee802154/reassembly.c
99498 +++ b/net/ieee802154/reassembly.c
99499 @@ -434,12 +434,11 @@ static struct ctl_table lowpan_frags_ctl_table[] = {
99500
99501 static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
99502 {
99503 - struct ctl_table *table;
99504 + ctl_table_no_const *table = NULL;
99505 struct ctl_table_header *hdr;
99506
99507 - table = lowpan_frags_ns_ctl_table;
99508 if (!net_eq(net, &init_net)) {
99509 - table = kmemdup(table, sizeof(lowpan_frags_ns_ctl_table),
99510 + table = kmemdup(lowpan_frags_ns_ctl_table, sizeof(lowpan_frags_ns_ctl_table),
99511 GFP_KERNEL);
99512 if (table == NULL)
99513 goto err_alloc;
99514 @@ -452,9 +451,9 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
99515 /* Don't export sysctls to unprivileged users */
99516 if (net->user_ns != &init_user_ns)
99517 table[0].procname = NULL;
99518 - }
99519 -
99520 - hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
99521 + hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
99522 + } else
99523 + hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", lowpan_frags_ns_ctl_table);
99524 if (hdr == NULL)
99525 goto err_reg;
99526
99527 @@ -462,8 +461,7 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
99528 return 0;
99529
99530 err_reg:
99531 - if (!net_eq(net, &init_net))
99532 - kfree(table);
99533 + kfree(table);
99534 err_alloc:
99535 return -ENOMEM;
99536 }
99537 diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
99538 index 6af8ab6..3831cb8 100644
99539 --- a/net/ipv4/af_inet.c
99540 +++ b/net/ipv4/af_inet.c
99541 @@ -1739,13 +1739,9 @@ static int __init inet_init(void)
99542
99543 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
99544
99545 - sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
99546 - if (!sysctl_local_reserved_ports)
99547 - goto out;
99548 -
99549 rc = proto_register(&tcp_prot, 1);
99550 if (rc)
99551 - goto out_free_reserved_ports;
99552 + goto out;
99553
99554 rc = proto_register(&udp_prot, 1);
99555 if (rc)
99556 @@ -1855,8 +1851,6 @@ out_unregister_udp_proto:
99557 proto_unregister(&udp_prot);
99558 out_unregister_tcp_proto:
99559 proto_unregister(&tcp_prot);
99560 -out_free_reserved_ports:
99561 - kfree(sysctl_local_reserved_ports);
99562 goto out;
99563 }
99564
99565 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
99566 index bdbf68b..deb4759 100644
99567 --- a/net/ipv4/devinet.c
99568 +++ b/net/ipv4/devinet.c
99569 @@ -1543,7 +1543,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
99570 idx = 0;
99571 head = &net->dev_index_head[h];
99572 rcu_read_lock();
99573 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
99574 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
99575 net->dev_base_seq;
99576 hlist_for_each_entry_rcu(dev, head, index_hlist) {
99577 if (idx < s_idx)
99578 @@ -1861,7 +1861,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
99579 idx = 0;
99580 head = &net->dev_index_head[h];
99581 rcu_read_lock();
99582 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
99583 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
99584 net->dev_base_seq;
99585 hlist_for_each_entry_rcu(dev, head, index_hlist) {
99586 if (idx < s_idx)
99587 @@ -2096,7 +2096,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
99588 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
99589 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
99590
99591 -static struct devinet_sysctl_table {
99592 +static const struct devinet_sysctl_table {
99593 struct ctl_table_header *sysctl_header;
99594 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
99595 } devinet_sysctl = {
99596 @@ -2218,7 +2218,7 @@ static __net_init int devinet_init_net(struct net *net)
99597 int err;
99598 struct ipv4_devconf *all, *dflt;
99599 #ifdef CONFIG_SYSCTL
99600 - struct ctl_table *tbl = ctl_forward_entry;
99601 + ctl_table_no_const *tbl = NULL;
99602 struct ctl_table_header *forw_hdr;
99603 #endif
99604
99605 @@ -2236,7 +2236,7 @@ static __net_init int devinet_init_net(struct net *net)
99606 goto err_alloc_dflt;
99607
99608 #ifdef CONFIG_SYSCTL
99609 - tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
99610 + tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
99611 if (tbl == NULL)
99612 goto err_alloc_ctl;
99613
99614 @@ -2256,7 +2256,10 @@ static __net_init int devinet_init_net(struct net *net)
99615 goto err_reg_dflt;
99616
99617 err = -ENOMEM;
99618 - forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
99619 + if (!net_eq(net, &init_net))
99620 + forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
99621 + else
99622 + forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
99623 if (forw_hdr == NULL)
99624 goto err_reg_ctl;
99625 net->ipv4.forw_hdr = forw_hdr;
99626 @@ -2272,8 +2275,7 @@ err_reg_ctl:
99627 err_reg_dflt:
99628 __devinet_sysctl_unregister(all);
99629 err_reg_all:
99630 - if (tbl != ctl_forward_entry)
99631 - kfree(tbl);
99632 + kfree(tbl);
99633 err_alloc_ctl:
99634 #endif
99635 if (dflt != &ipv4_devconf_dflt)
99636 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
99637 index 255aa99..45c78f8 100644
99638 --- a/net/ipv4/fib_frontend.c
99639 +++ b/net/ipv4/fib_frontend.c
99640 @@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
99641 #ifdef CONFIG_IP_ROUTE_MULTIPATH
99642 fib_sync_up(dev);
99643 #endif
99644 - atomic_inc(&net->ipv4.dev_addr_genid);
99645 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
99646 rt_cache_flush(dev_net(dev));
99647 break;
99648 case NETDEV_DOWN:
99649 fib_del_ifaddr(ifa, NULL);
99650 - atomic_inc(&net->ipv4.dev_addr_genid);
99651 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
99652 if (ifa->ifa_dev->ifa_list == NULL) {
99653 /* Last address was deleted from this interface.
99654 * Disable IP.
99655 @@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
99656 #ifdef CONFIG_IP_ROUTE_MULTIPATH
99657 fib_sync_up(dev);
99658 #endif
99659 - atomic_inc(&net->ipv4.dev_addr_genid);
99660 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
99661 rt_cache_flush(net);
99662 break;
99663 case NETDEV_DOWN:
99664 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
99665 index b10cd43a..22327f9 100644
99666 --- a/net/ipv4/fib_semantics.c
99667 +++ b/net/ipv4/fib_semantics.c
99668 @@ -768,7 +768,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
99669 nh->nh_saddr = inet_select_addr(nh->nh_dev,
99670 nh->nh_gw,
99671 nh->nh_parent->fib_scope);
99672 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
99673 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
99674
99675 return nh->nh_saddr;
99676 }
99677 diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
99678 index a56b8e6..5be2a30 100644
99679 --- a/net/ipv4/inet_connection_sock.c
99680 +++ b/net/ipv4/inet_connection_sock.c
99681 @@ -29,7 +29,7 @@ const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
99682 EXPORT_SYMBOL(inet_csk_timer_bug_msg);
99683 #endif
99684
99685 -unsigned long *sysctl_local_reserved_ports;
99686 +unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
99687 EXPORT_SYMBOL(sysctl_local_reserved_ports);
99688
99689 void inet_get_local_port_range(struct net *net, int *low, int *high)
99690 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
99691 index 8b9cf27..0d8d592 100644
99692 --- a/net/ipv4/inet_hashtables.c
99693 +++ b/net/ipv4/inet_hashtables.c
99694 @@ -18,6 +18,7 @@
99695 #include <linux/sched.h>
99696 #include <linux/slab.h>
99697 #include <linux/wait.h>
99698 +#include <linux/security.h>
99699
99700 #include <net/inet_connection_sock.h>
99701 #include <net/inet_hashtables.h>
99702 @@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
99703 return inet_ehashfn(net, laddr, lport, faddr, fport);
99704 }
99705
99706 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
99707 +
99708 /*
99709 * Allocate and initialize a new local port bind bucket.
99710 * The bindhash mutex for snum's hash chain must be held here.
99711 @@ -554,6 +557,8 @@ ok:
99712 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
99713 spin_unlock(&head->lock);
99714
99715 + gr_update_task_in_ip_table(current, inet_sk(sk));
99716 +
99717 if (tw) {
99718 inet_twsk_deschedule(tw, death_row);
99719 while (twrefcnt) {
99720 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
99721 index bf2cb4a..d83ba8a 100644
99722 --- a/net/ipv4/inetpeer.c
99723 +++ b/net/ipv4/inetpeer.c
99724 @@ -482,7 +482,7 @@ relookup:
99725 if (p) {
99726 p->daddr = *daddr;
99727 atomic_set(&p->refcnt, 1);
99728 - atomic_set(&p->rid, 0);
99729 + atomic_set_unchecked(&p->rid, 0);
99730 p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
99731 p->rate_tokens = 0;
99732 /* 60*HZ is arbitrary, but chosen enough high so that the first
99733 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
99734 index ed32313..3762abe 100644
99735 --- a/net/ipv4/ip_fragment.c
99736 +++ b/net/ipv4/ip_fragment.c
99737 @@ -284,7 +284,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
99738 return 0;
99739
99740 start = qp->rid;
99741 - end = atomic_inc_return(&peer->rid);
99742 + end = atomic_inc_return_unchecked(&peer->rid);
99743 qp->rid = end;
99744
99745 rc = qp->q.fragments && (end - start) > max;
99746 @@ -761,12 +761,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
99747
99748 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
99749 {
99750 - struct ctl_table *table;
99751 + ctl_table_no_const *table = NULL;
99752 struct ctl_table_header *hdr;
99753
99754 - table = ip4_frags_ns_ctl_table;
99755 if (!net_eq(net, &init_net)) {
99756 - table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
99757 + table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
99758 if (table == NULL)
99759 goto err_alloc;
99760
99761 @@ -777,9 +776,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
99762 /* Don't export sysctls to unprivileged users */
99763 if (net->user_ns != &init_user_ns)
99764 table[0].procname = NULL;
99765 - }
99766 + hdr = register_net_sysctl(net, "net/ipv4", table);
99767 + } else
99768 + hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
99769
99770 - hdr = register_net_sysctl(net, "net/ipv4", table);
99771 if (hdr == NULL)
99772 goto err_reg;
99773
99774 @@ -787,8 +787,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
99775 return 0;
99776
99777 err_reg:
99778 - if (!net_eq(net, &init_net))
99779 - kfree(table);
99780 + kfree(table);
99781 err_alloc:
99782 return -ENOMEM;
99783 }
99784 diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
99785 index 94213c8..8bdb342 100644
99786 --- a/net/ipv4/ip_gre.c
99787 +++ b/net/ipv4/ip_gre.c
99788 @@ -115,7 +115,7 @@ static bool log_ecn_error = true;
99789 module_param(log_ecn_error, bool, 0644);
99790 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
99791
99792 -static struct rtnl_link_ops ipgre_link_ops __read_mostly;
99793 +static struct rtnl_link_ops ipgre_link_ops;
99794 static int ipgre_tunnel_init(struct net_device *dev);
99795
99796 static int ipgre_net_id __read_mostly;
99797 @@ -732,7 +732,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
99798 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
99799 };
99800
99801 -static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
99802 +static struct rtnl_link_ops ipgre_link_ops = {
99803 .kind = "gre",
99804 .maxtype = IFLA_GRE_MAX,
99805 .policy = ipgre_policy,
99806 @@ -746,7 +746,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
99807 .fill_info = ipgre_fill_info,
99808 };
99809
99810 -static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
99811 +static struct rtnl_link_ops ipgre_tap_ops = {
99812 .kind = "gretap",
99813 .maxtype = IFLA_GRE_MAX,
99814 .policy = ipgre_policy,
99815 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
99816 index 64741b9..6f334a2 100644
99817 --- a/net/ipv4/ip_sockglue.c
99818 +++ b/net/ipv4/ip_sockglue.c
99819 @@ -1188,7 +1188,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
99820 len = min_t(unsigned int, len, opt->optlen);
99821 if (put_user(len, optlen))
99822 return -EFAULT;
99823 - if (copy_to_user(optval, opt->__data, len))
99824 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
99825 + copy_to_user(optval, opt->__data, len))
99826 return -EFAULT;
99827 return 0;
99828 }
99829 @@ -1319,7 +1320,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
99830 if (sk->sk_type != SOCK_STREAM)
99831 return -ENOPROTOOPT;
99832
99833 - msg.msg_control = optval;
99834 + msg.msg_control = (void __force_kernel *)optval;
99835 msg.msg_controllen = len;
99836 msg.msg_flags = flags;
99837
99838 diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
99839 index 13ef00f..8ffca25 100644
99840 --- a/net/ipv4/ip_vti.c
99841 +++ b/net/ipv4/ip_vti.c
99842 @@ -45,7 +45,7 @@
99843 #include <net/net_namespace.h>
99844 #include <net/netns/generic.h>
99845
99846 -static struct rtnl_link_ops vti_link_ops __read_mostly;
99847 +static struct rtnl_link_ops vti_link_ops;
99848
99849 static int vti_net_id __read_mostly;
99850 static int vti_tunnel_init(struct net_device *dev);
99851 @@ -513,7 +513,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
99852 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
99853 };
99854
99855 -static struct rtnl_link_ops vti_link_ops __read_mostly = {
99856 +static struct rtnl_link_ops vti_link_ops = {
99857 .kind = "vti",
99858 .maxtype = IFLA_VTI_MAX,
99859 .policy = vti_policy,
99860 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
99861 index b3e86ea..18ce98c 100644
99862 --- a/net/ipv4/ipconfig.c
99863 +++ b/net/ipv4/ipconfig.c
99864 @@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
99865
99866 mm_segment_t oldfs = get_fs();
99867 set_fs(get_ds());
99868 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
99869 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
99870 set_fs(oldfs);
99871 return res;
99872 }
99873 @@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
99874
99875 mm_segment_t oldfs = get_fs();
99876 set_fs(get_ds());
99877 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
99878 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
99879 set_fs(oldfs);
99880 return res;
99881 }
99882 @@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
99883
99884 mm_segment_t oldfs = get_fs();
99885 set_fs(get_ds());
99886 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
99887 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
99888 set_fs(oldfs);
99889 return res;
99890 }
99891 diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
99892 index 62eaa00..29b2dc2 100644
99893 --- a/net/ipv4/ipip.c
99894 +++ b/net/ipv4/ipip.c
99895 @@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
99896 static int ipip_net_id __read_mostly;
99897
99898 static int ipip_tunnel_init(struct net_device *dev);
99899 -static struct rtnl_link_ops ipip_link_ops __read_mostly;
99900 +static struct rtnl_link_ops ipip_link_ops;
99901
99902 static int ipip_err(struct sk_buff *skb, u32 info)
99903 {
99904 @@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
99905 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
99906 };
99907
99908 -static struct rtnl_link_ops ipip_link_ops __read_mostly = {
99909 +static struct rtnl_link_ops ipip_link_ops = {
99910 .kind = "ipip",
99911 .maxtype = IFLA_IPTUN_MAX,
99912 .policy = ipip_policy,
99913 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
99914 index f95b6f9..2ee2097 100644
99915 --- a/net/ipv4/netfilter/arp_tables.c
99916 +++ b/net/ipv4/netfilter/arp_tables.c
99917 @@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
99918 #endif
99919
99920 static int get_info(struct net *net, void __user *user,
99921 - const int *len, int compat)
99922 + int len, int compat)
99923 {
99924 char name[XT_TABLE_MAXNAMELEN];
99925 struct xt_table *t;
99926 int ret;
99927
99928 - if (*len != sizeof(struct arpt_getinfo)) {
99929 - duprintf("length %u != %Zu\n", *len,
99930 + if (len != sizeof(struct arpt_getinfo)) {
99931 + duprintf("length %u != %Zu\n", len,
99932 sizeof(struct arpt_getinfo));
99933 return -EINVAL;
99934 }
99935 @@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
99936 info.size = private->size;
99937 strcpy(info.name, name);
99938
99939 - if (copy_to_user(user, &info, *len) != 0)
99940 + if (copy_to_user(user, &info, len) != 0)
99941 ret = -EFAULT;
99942 else
99943 ret = 0;
99944 @@ -1690,7 +1690,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
99945
99946 switch (cmd) {
99947 case ARPT_SO_GET_INFO:
99948 - ret = get_info(sock_net(sk), user, len, 1);
99949 + ret = get_info(sock_net(sk), user, *len, 1);
99950 break;
99951 case ARPT_SO_GET_ENTRIES:
99952 ret = compat_get_entries(sock_net(sk), user, len);
99953 @@ -1735,7 +1735,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
99954
99955 switch (cmd) {
99956 case ARPT_SO_GET_INFO:
99957 - ret = get_info(sock_net(sk), user, len, 0);
99958 + ret = get_info(sock_net(sk), user, *len, 0);
99959 break;
99960
99961 case ARPT_SO_GET_ENTRIES:
99962 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
99963 index 99e810f..3711b81 100644
99964 --- a/net/ipv4/netfilter/ip_tables.c
99965 +++ b/net/ipv4/netfilter/ip_tables.c
99966 @@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
99967 #endif
99968
99969 static int get_info(struct net *net, void __user *user,
99970 - const int *len, int compat)
99971 + int len, int compat)
99972 {
99973 char name[XT_TABLE_MAXNAMELEN];
99974 struct xt_table *t;
99975 int ret;
99976
99977 - if (*len != sizeof(struct ipt_getinfo)) {
99978 - duprintf("length %u != %zu\n", *len,
99979 + if (len != sizeof(struct ipt_getinfo)) {
99980 + duprintf("length %u != %zu\n", len,
99981 sizeof(struct ipt_getinfo));
99982 return -EINVAL;
99983 }
99984 @@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
99985 info.size = private->size;
99986 strcpy(info.name, name);
99987
99988 - if (copy_to_user(user, &info, *len) != 0)
99989 + if (copy_to_user(user, &info, len) != 0)
99990 ret = -EFAULT;
99991 else
99992 ret = 0;
99993 @@ -1973,7 +1973,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99994
99995 switch (cmd) {
99996 case IPT_SO_GET_INFO:
99997 - ret = get_info(sock_net(sk), user, len, 1);
99998 + ret = get_info(sock_net(sk), user, *len, 1);
99999 break;
100000 case IPT_SO_GET_ENTRIES:
100001 ret = compat_get_entries(sock_net(sk), user, len);
100002 @@ -2020,7 +2020,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
100003
100004 switch (cmd) {
100005 case IPT_SO_GET_INFO:
100006 - ret = get_info(sock_net(sk), user, len, 0);
100007 + ret = get_info(sock_net(sk), user, *len, 0);
100008 break;
100009
100010 case IPT_SO_GET_ENTRIES:
100011 diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
100012 index 2510c02..cfb34fa 100644
100013 --- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
100014 +++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
100015 @@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
100016 spin_lock_init(&cn->lock);
100017
100018 #ifdef CONFIG_PROC_FS
100019 - cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
100020 + cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
100021 if (!cn->procdir) {
100022 pr_err("Unable to proc dir entry\n");
100023 return -ENOMEM;
100024 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
100025 index 044a0dd..e0c1971 100644
100026 --- a/net/ipv4/ping.c
100027 +++ b/net/ipv4/ping.c
100028 @@ -59,7 +59,7 @@ struct ping_table {
100029 };
100030
100031 static struct ping_table ping_table;
100032 -struct pingv6_ops pingv6_ops;
100033 +struct pingv6_ops *pingv6_ops;
100034 EXPORT_SYMBOL_GPL(pingv6_ops);
100035
100036 static u16 ping_port_rover;
100037 @@ -348,7 +348,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
100038 return -ENODEV;
100039 }
100040 }
100041 - has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
100042 + has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
100043 scoped);
100044 rcu_read_unlock();
100045
100046 @@ -556,7 +556,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
100047 }
100048 #if IS_ENABLED(CONFIG_IPV6)
100049 } else if (skb->protocol == htons(ETH_P_IPV6)) {
100050 - harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
100051 + harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
100052 #endif
100053 }
100054
100055 @@ -574,7 +574,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
100056 info, (u8 *)icmph);
100057 #if IS_ENABLED(CONFIG_IPV6)
100058 } else if (family == AF_INET6) {
100059 - pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
100060 + pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
100061 info, (u8 *)icmph);
100062 #endif
100063 }
100064 @@ -844,6 +844,8 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
100065 {
100066 struct inet_sock *isk = inet_sk(sk);
100067 int family = sk->sk_family;
100068 + struct sockaddr_in *sin;
100069 + struct sockaddr_in6 *sin6;
100070 struct sk_buff *skb;
100071 int copied, err;
100072
100073 @@ -853,12 +855,19 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
100074 if (flags & MSG_OOB)
100075 goto out;
100076
100077 + if (addr_len) {
100078 + if (family == AF_INET)
100079 + *addr_len = sizeof(*sin);
100080 + else if (family == AF_INET6 && addr_len)
100081 + *addr_len = sizeof(*sin6);
100082 + }
100083 +
100084 if (flags & MSG_ERRQUEUE) {
100085 if (family == AF_INET) {
100086 return ip_recv_error(sk, msg, len, addr_len);
100087 #if IS_ENABLED(CONFIG_IPV6)
100088 } else if (family == AF_INET6) {
100089 - return pingv6_ops.ipv6_recv_error(sk, msg, len,
100090 + return pingv6_ops->ipv6_recv_error(sk, msg, len,
100091 addr_len);
100092 #endif
100093 }
100094 @@ -890,7 +899,6 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
100095 sin->sin_port = 0 /* skb->h.uh->source */;
100096 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
100097 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
100098 - *addr_len = sizeof(*sin);
100099 }
100100
100101 if (isk->cmsg_flags)
100102 @@ -912,14 +920,13 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
100103 sin6->sin6_scope_id =
100104 ipv6_iface_scope_id(&sin6->sin6_addr,
100105 IP6CB(skb)->iif);
100106 - *addr_len = sizeof(*sin6);
100107 }
100108
100109 if (inet6_sk(sk)->rxopt.all)
100110 - pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
100111 + pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
100112 if (skb->protocol == htons(ETH_P_IPV6) &&
100113 inet6_sk(sk)->rxopt.all)
100114 - pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
100115 + pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
100116 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
100117 ip_cmsg_recv(msg, skb);
100118 #endif
100119 @@ -1111,7 +1118,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
100120 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
100121 0, sock_i_ino(sp),
100122 atomic_read(&sp->sk_refcnt), sp,
100123 - atomic_read(&sp->sk_drops));
100124 + atomic_read_unchecked(&sp->sk_drops));
100125 }
100126
100127 static int ping_v4_seq_show(struct seq_file *seq, void *v)
100128 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
100129 index 2c65160..b54c00e 100644
100130 --- a/net/ipv4/raw.c
100131 +++ b/net/ipv4/raw.c
100132 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
100133 int raw_rcv(struct sock *sk, struct sk_buff *skb)
100134 {
100135 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
100136 - atomic_inc(&sk->sk_drops);
100137 + atomic_inc_unchecked(&sk->sk_drops);
100138 kfree_skb(skb);
100139 return NET_RX_DROP;
100140 }
100141 @@ -696,6 +696,9 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
100142 if (flags & MSG_OOB)
100143 goto out;
100144
100145 + if (addr_len)
100146 + *addr_len = sizeof(*sin);
100147 +
100148 if (flags & MSG_ERRQUEUE) {
100149 err = ip_recv_error(sk, msg, len, addr_len);
100150 goto out;
100151 @@ -723,7 +726,6 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
100152 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
100153 sin->sin_port = 0;
100154 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
100155 - *addr_len = sizeof(*sin);
100156 }
100157 if (inet->cmsg_flags)
100158 ip_cmsg_recv(msg, skb);
100159 @@ -748,16 +750,20 @@ static int raw_init(struct sock *sk)
100160
100161 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
100162 {
100163 + struct icmp_filter filter;
100164 +
100165 if (optlen > sizeof(struct icmp_filter))
100166 optlen = sizeof(struct icmp_filter);
100167 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
100168 + if (copy_from_user(&filter, optval, optlen))
100169 return -EFAULT;
100170 + raw_sk(sk)->filter = filter;
100171 return 0;
100172 }
100173
100174 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
100175 {
100176 int len, ret = -EFAULT;
100177 + struct icmp_filter filter;
100178
100179 if (get_user(len, optlen))
100180 goto out;
100181 @@ -767,8 +773,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
100182 if (len > sizeof(struct icmp_filter))
100183 len = sizeof(struct icmp_filter);
100184 ret = -EFAULT;
100185 - if (put_user(len, optlen) ||
100186 - copy_to_user(optval, &raw_sk(sk)->filter, len))
100187 + filter = raw_sk(sk)->filter;
100188 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
100189 goto out;
100190 ret = 0;
100191 out: return ret;
100192 @@ -997,7 +1003,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
100193 0, 0L, 0,
100194 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
100195 0, sock_i_ino(sp),
100196 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
100197 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
100198 }
100199
100200 static int raw_seq_show(struct seq_file *seq, void *v)
100201 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
100202 index fd618d4..aae0ac9 100644
100203 --- a/net/ipv4/route.c
100204 +++ b/net/ipv4/route.c
100205 @@ -228,7 +228,7 @@ static const struct seq_operations rt_cache_seq_ops = {
100206
100207 static int rt_cache_seq_open(struct inode *inode, struct file *file)
100208 {
100209 - return seq_open(file, &rt_cache_seq_ops);
100210 + return seq_open_restrict(file, &rt_cache_seq_ops);
100211 }
100212
100213 static const struct file_operations rt_cache_seq_fops = {
100214 @@ -319,7 +319,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
100215
100216 static int rt_cpu_seq_open(struct inode *inode, struct file *file)
100217 {
100218 - return seq_open(file, &rt_cpu_seq_ops);
100219 + return seq_open_restrict(file, &rt_cpu_seq_ops);
100220 }
100221
100222 static const struct file_operations rt_cpu_seq_fops = {
100223 @@ -357,7 +357,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
100224
100225 static int rt_acct_proc_open(struct inode *inode, struct file *file)
100226 {
100227 - return single_open(file, rt_acct_proc_show, NULL);
100228 + return single_open_restrict(file, rt_acct_proc_show, NULL);
100229 }
100230
100231 static const struct file_operations rt_acct_proc_fops = {
100232 @@ -459,7 +459,7 @@ static struct neighbour *ipv4_neigh_lookup(const struct dst_entry *dst,
100233
100234 #define IP_IDENTS_SZ 2048u
100235 struct ip_ident_bucket {
100236 - atomic_t id;
100237 + atomic_unchecked_t id;
100238 u32 stamp32;
100239 };
100240
100241 @@ -479,7 +479,7 @@ u32 ip_idents_reserve(u32 hash, int segs)
100242 if (old != now && cmpxchg(&bucket->stamp32, old, now) == old)
100243 delta = prandom_u32_max(now - old);
100244
100245 - return atomic_add_return(segs + delta, &bucket->id) - segs;
100246 + return atomic_add_return_unchecked(segs + delta, &bucket->id) - segs;
100247 }
100248 EXPORT_SYMBOL(ip_idents_reserve);
100249
100250 @@ -2618,34 +2618,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
100251 .maxlen = sizeof(int),
100252 .mode = 0200,
100253 .proc_handler = ipv4_sysctl_rtcache_flush,
100254 + .extra1 = &init_net,
100255 },
100256 { },
100257 };
100258
100259 static __net_init int sysctl_route_net_init(struct net *net)
100260 {
100261 - struct ctl_table *tbl;
100262 + ctl_table_no_const *tbl = NULL;
100263
100264 - tbl = ipv4_route_flush_table;
100265 if (!net_eq(net, &init_net)) {
100266 - tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
100267 + tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
100268 if (tbl == NULL)
100269 goto err_dup;
100270
100271 /* Don't export sysctls to unprivileged users */
100272 if (net->user_ns != &init_user_ns)
100273 tbl[0].procname = NULL;
100274 - }
100275 - tbl[0].extra1 = net;
100276 + tbl[0].extra1 = net;
100277 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
100278 + } else
100279 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
100280
100281 - net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
100282 if (net->ipv4.route_hdr == NULL)
100283 goto err_reg;
100284 return 0;
100285
100286 err_reg:
100287 - if (tbl != ipv4_route_flush_table)
100288 - kfree(tbl);
100289 + kfree(tbl);
100290 err_dup:
100291 return -ENOMEM;
100292 }
100293 @@ -2668,8 +2668,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
100294
100295 static __net_init int rt_genid_init(struct net *net)
100296 {
100297 - atomic_set(&net->ipv4.rt_genid, 0);
100298 - atomic_set(&net->fnhe_genid, 0);
100299 + atomic_set_unchecked(&net->ipv4.rt_genid, 0);
100300 + atomic_set_unchecked(&net->fnhe_genid, 0);
100301 get_random_bytes(&net->ipv4.dev_addr_genid,
100302 sizeof(net->ipv4.dev_addr_genid));
100303 return 0;
100304 diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
100305 index 5cde8f2..5f5684e 100644
100306 --- a/net/ipv4/sysctl_net_ipv4.c
100307 +++ b/net/ipv4/sysctl_net_ipv4.c
100308 @@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
100309 container_of(table->data, struct net, ipv4.ip_local_ports.range);
100310 int ret;
100311 int range[2];
100312 - struct ctl_table tmp = {
100313 + ctl_table_no_const tmp = {
100314 .data = &range,
100315 .maxlen = sizeof(range),
100316 .mode = table->mode,
100317 @@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
100318 int ret;
100319 gid_t urange[2];
100320 kgid_t low, high;
100321 - struct ctl_table tmp = {
100322 + ctl_table_no_const tmp = {
100323 .data = &urange,
100324 .maxlen = sizeof(urange),
100325 .mode = table->mode,
100326 @@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
100327 void __user *buffer, size_t *lenp, loff_t *ppos)
100328 {
100329 char val[TCP_CA_NAME_MAX];
100330 - struct ctl_table tbl = {
100331 + ctl_table_no_const tbl = {
100332 .data = val,
100333 .maxlen = TCP_CA_NAME_MAX,
100334 };
100335 @@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
100336 void __user *buffer, size_t *lenp,
100337 loff_t *ppos)
100338 {
100339 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
100340 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
100341 int ret;
100342
100343 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
100344 @@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
100345 void __user *buffer, size_t *lenp,
100346 loff_t *ppos)
100347 {
100348 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
100349 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
100350 int ret;
100351
100352 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
100353 @@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
100354 void __user *buffer, size_t *lenp,
100355 loff_t *ppos)
100356 {
100357 - struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
100358 + ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
100359 struct tcp_fastopen_context *ctxt;
100360 int ret;
100361 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
100362 @@ -438,7 +438,7 @@ static struct ctl_table ipv4_table[] = {
100363 },
100364 {
100365 .procname = "ip_local_reserved_ports",
100366 - .data = NULL, /* initialized in sysctl_ipv4_init */
100367 + .data = sysctl_local_reserved_ports,
100368 .maxlen = 65536,
100369 .mode = 0644,
100370 .proc_handler = proc_do_large_bitmap,
100371 @@ -843,13 +843,12 @@ static struct ctl_table ipv4_net_table[] = {
100372
100373 static __net_init int ipv4_sysctl_init_net(struct net *net)
100374 {
100375 - struct ctl_table *table;
100376 + ctl_table_no_const *table = NULL;
100377
100378 - table = ipv4_net_table;
100379 if (!net_eq(net, &init_net)) {
100380 int i;
100381
100382 - table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
100383 + table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
100384 if (table == NULL)
100385 goto err_alloc;
100386
100387 @@ -858,15 +857,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
100388 table[i].data += (void *)net - (void *)&init_net;
100389 }
100390
100391 - net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
100392 + if (!net_eq(net, &init_net))
100393 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
100394 + else
100395 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
100396 if (net->ipv4.ipv4_hdr == NULL)
100397 goto err_reg;
100398
100399 return 0;
100400
100401 err_reg:
100402 - if (!net_eq(net, &init_net))
100403 - kfree(table);
100404 + kfree(table);
100405 err_alloc:
100406 return -ENOMEM;
100407 }
100408 @@ -888,16 +889,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
100409 static __init int sysctl_ipv4_init(void)
100410 {
100411 struct ctl_table_header *hdr;
100412 - struct ctl_table *i;
100413 -
100414 - for (i = ipv4_table; i->procname; i++) {
100415 - if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
100416 - i->data = sysctl_local_reserved_ports;
100417 - break;
100418 - }
100419 - }
100420 - if (!i->procname)
100421 - return -EINVAL;
100422
100423 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
100424 if (hdr == NULL)
100425 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
100426 index 09b85cd..df9c266 100644
100427 --- a/net/ipv4/tcp_input.c
100428 +++ b/net/ipv4/tcp_input.c
100429 @@ -754,7 +754,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
100430 * without any lock. We want to make sure compiler wont store
100431 * intermediate values in this location.
100432 */
100433 - ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
100434 + ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
100435 sk->sk_max_pacing_rate);
100436 }
100437
100438 @@ -4478,7 +4478,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
100439 * simplifies code)
100440 */
100441 static void
100442 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
100443 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
100444 struct sk_buff *head, struct sk_buff *tail,
100445 u32 start, u32 end)
100446 {
100447 @@ -5558,6 +5558,7 @@ discard:
100448 tcp_paws_reject(&tp->rx_opt, 0))
100449 goto discard_and_undo;
100450
100451 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
100452 if (th->syn) {
100453 /* We see SYN without ACK. It is attempt of
100454 * simultaneous connect with crossed SYNs.
100455 @@ -5608,6 +5609,7 @@ discard:
100456 goto discard;
100457 #endif
100458 }
100459 +#endif
100460 /* "fifth, if neither of the SYN or RST bits is set then
100461 * drop the segment and return."
100462 */
100463 @@ -5654,7 +5656,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
100464 goto discard;
100465
100466 if (th->syn) {
100467 - if (th->fin)
100468 + if (th->fin || th->urg || th->psh)
100469 goto discard;
100470 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
100471 return 1;
100472 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
100473 index 438f3b9..bc9e1ad 100644
100474 --- a/net/ipv4/tcp_ipv4.c
100475 +++ b/net/ipv4/tcp_ipv4.c
100476 @@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
100477 EXPORT_SYMBOL(sysctl_tcp_low_latency);
100478
100479
100480 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100481 +extern int grsec_enable_blackhole;
100482 +#endif
100483 +
100484 #ifdef CONFIG_TCP_MD5SIG
100485 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
100486 __be32 daddr, __be32 saddr, const struct tcphdr *th);
100487 @@ -1829,6 +1833,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
100488 return 0;
100489
100490 reset:
100491 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100492 + if (!grsec_enable_blackhole)
100493 +#endif
100494 tcp_v4_send_reset(rsk, skb);
100495 discard:
100496 kfree_skb(skb);
100497 @@ -1974,12 +1981,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
100498 TCP_SKB_CB(skb)->sacked = 0;
100499
100500 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
100501 - if (!sk)
100502 + if (!sk) {
100503 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100504 + ret = 1;
100505 +#endif
100506 goto no_tcp_socket;
100507 -
100508 + }
100509 process:
100510 - if (sk->sk_state == TCP_TIME_WAIT)
100511 + if (sk->sk_state == TCP_TIME_WAIT) {
100512 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100513 + ret = 2;
100514 +#endif
100515 goto do_time_wait;
100516 + }
100517
100518 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
100519 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
100520 @@ -2033,6 +2047,10 @@ csum_error:
100521 bad_packet:
100522 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
100523 } else {
100524 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100525 + if (!grsec_enable_blackhole || (ret == 1 &&
100526 + (skb->dev->flags & IFF_LOOPBACK)))
100527 +#endif
100528 tcp_v4_send_reset(NULL, skb);
100529 }
100530
100531 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
100532 index 05c1b15..3e9344b 100644
100533 --- a/net/ipv4/tcp_minisocks.c
100534 +++ b/net/ipv4/tcp_minisocks.c
100535 @@ -27,6 +27,10 @@
100536 #include <net/inet_common.h>
100537 #include <net/xfrm.h>
100538
100539 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100540 +extern int grsec_enable_blackhole;
100541 +#endif
100542 +
100543 int sysctl_tcp_syncookies __read_mostly = 1;
100544 EXPORT_SYMBOL(sysctl_tcp_syncookies);
100545
100546 @@ -709,7 +713,10 @@ embryonic_reset:
100547 * avoid becoming vulnerable to outside attack aiming at
100548 * resetting legit local connections.
100549 */
100550 - req->rsk_ops->send_reset(sk, skb);
100551 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100552 + if (!grsec_enable_blackhole)
100553 +#endif
100554 + req->rsk_ops->send_reset(sk, skb);
100555 } else if (fastopen) { /* received a valid RST pkt */
100556 reqsk_fastopen_remove(sk, req, true);
100557 tcp_reset(sk);
100558 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
100559 index 3b66610..bfbe23a 100644
100560 --- a/net/ipv4/tcp_probe.c
100561 +++ b/net/ipv4/tcp_probe.c
100562 @@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
100563 if (cnt + width >= len)
100564 break;
100565
100566 - if (copy_to_user(buf + cnt, tbuf, width))
100567 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
100568 return -EFAULT;
100569 cnt += width;
100570 }
100571 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
100572 index 286227a..c495a76 100644
100573 --- a/net/ipv4/tcp_timer.c
100574 +++ b/net/ipv4/tcp_timer.c
100575 @@ -22,6 +22,10 @@
100576 #include <linux/gfp.h>
100577 #include <net/tcp.h>
100578
100579 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100580 +extern int grsec_lastack_retries;
100581 +#endif
100582 +
100583 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
100584 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
100585 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
100586 @@ -192,6 +196,13 @@ static int tcp_write_timeout(struct sock *sk)
100587 }
100588 }
100589
100590 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100591 + if ((sk->sk_state == TCP_LAST_ACK) &&
100592 + (grsec_lastack_retries > 0) &&
100593 + (grsec_lastack_retries < retry_until))
100594 + retry_until = grsec_lastack_retries;
100595 +#endif
100596 +
100597 if (retransmits_timed_out(sk, retry_until,
100598 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
100599 /* Has it gone just too far? */
100600 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
100601 index 54a5fe9..78fea00 100644
100602 --- a/net/ipv4/udp.c
100603 +++ b/net/ipv4/udp.c
100604 @@ -87,6 +87,7 @@
100605 #include <linux/types.h>
100606 #include <linux/fcntl.h>
100607 #include <linux/module.h>
100608 +#include <linux/security.h>
100609 #include <linux/socket.h>
100610 #include <linux/sockios.h>
100611 #include <linux/igmp.h>
100612 @@ -113,6 +114,10 @@
100613 #include <net/busy_poll.h>
100614 #include "udp_impl.h"
100615
100616 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100617 +extern int grsec_enable_blackhole;
100618 +#endif
100619 +
100620 struct udp_table udp_table __read_mostly;
100621 EXPORT_SYMBOL(udp_table);
100622
100623 @@ -615,6 +620,9 @@ found:
100624 return s;
100625 }
100626
100627 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
100628 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
100629 +
100630 /*
100631 * This routine is called by the ICMP module when it gets some
100632 * sort of error condition. If err < 0 then the socket should
100633 @@ -914,9 +922,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
100634 dport = usin->sin_port;
100635 if (dport == 0)
100636 return -EINVAL;
100637 +
100638 + err = gr_search_udp_sendmsg(sk, usin);
100639 + if (err)
100640 + return err;
100641 } else {
100642 if (sk->sk_state != TCP_ESTABLISHED)
100643 return -EDESTADDRREQ;
100644 +
100645 + err = gr_search_udp_sendmsg(sk, NULL);
100646 + if (err)
100647 + return err;
100648 +
100649 daddr = inet->inet_daddr;
100650 dport = inet->inet_dport;
100651 /* Open fast path for connected socket.
100652 @@ -1164,7 +1181,7 @@ static unsigned int first_packet_length(struct sock *sk)
100653 IS_UDPLITE(sk));
100654 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
100655 IS_UDPLITE(sk));
100656 - atomic_inc(&sk->sk_drops);
100657 + atomic_inc_unchecked(&sk->sk_drops);
100658 __skb_unlink(skb, rcvq);
100659 __skb_queue_tail(&list_kill, skb);
100660 }
100661 @@ -1235,6 +1252,12 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
100662 int is_udplite = IS_UDPLITE(sk);
100663 bool slow;
100664
100665 + /*
100666 + * Check any passed addresses
100667 + */
100668 + if (addr_len)
100669 + *addr_len = sizeof(*sin);
100670 +
100671 if (flags & MSG_ERRQUEUE)
100672 return ip_recv_error(sk, msg, len, addr_len);
100673
100674 @@ -1244,6 +1267,10 @@ try_again:
100675 if (!skb)
100676 goto out;
100677
100678 + err = gr_search_udp_recvmsg(sk, skb);
100679 + if (err)
100680 + goto out_free;
100681 +
100682 ulen = skb->len - sizeof(struct udphdr);
100683 copied = len;
100684 if (copied > ulen)
100685 @@ -1277,7 +1304,7 @@ try_again:
100686 if (unlikely(err)) {
100687 trace_kfree_skb(skb, udp_recvmsg);
100688 if (!peeked) {
100689 - atomic_inc(&sk->sk_drops);
100690 + atomic_inc_unchecked(&sk->sk_drops);
100691 UDP_INC_STATS_USER(sock_net(sk),
100692 UDP_MIB_INERRORS, is_udplite);
100693 }
100694 @@ -1296,7 +1323,6 @@ try_again:
100695 sin->sin_port = udp_hdr(skb)->source;
100696 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
100697 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
100698 - *addr_len = sizeof(*sin);
100699 }
100700 if (inet->cmsg_flags)
100701 ip_cmsg_recv(msg, skb);
100702 @@ -1567,7 +1593,7 @@ csum_error:
100703 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
100704 drop:
100705 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
100706 - atomic_inc(&sk->sk_drops);
100707 + atomic_inc_unchecked(&sk->sk_drops);
100708 kfree_skb(skb);
100709 return -1;
100710 }
100711 @@ -1586,7 +1612,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
100712 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
100713
100714 if (!skb1) {
100715 - atomic_inc(&sk->sk_drops);
100716 + atomic_inc_unchecked(&sk->sk_drops);
100717 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
100718 IS_UDPLITE(sk));
100719 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
100720 @@ -1787,6 +1813,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
100721 goto csum_error;
100722
100723 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
100724 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100725 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
100726 +#endif
100727 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
100728
100729 /*
100730 @@ -2355,7 +2384,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
100731 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
100732 0, sock_i_ino(sp),
100733 atomic_read(&sp->sk_refcnt), sp,
100734 - atomic_read(&sp->sk_drops));
100735 + atomic_read_unchecked(&sp->sk_drops));
100736 }
100737
100738 int udp4_seq_show(struct seq_file *seq, void *v)
100739 diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
100740 index 6156f68..d6ab46d 100644
100741 --- a/net/ipv4/xfrm4_policy.c
100742 +++ b/net/ipv4/xfrm4_policy.c
100743 @@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
100744 fl4->flowi4_tos = iph->tos;
100745 }
100746
100747 -static inline int xfrm4_garbage_collect(struct dst_ops *ops)
100748 +static int xfrm4_garbage_collect(struct dst_ops *ops)
100749 {
100750 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
100751
100752 - xfrm4_policy_afinfo.garbage_collect(net);
100753 + xfrm_garbage_collect_deferred(net);
100754 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
100755 }
100756
100757 @@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
100758
100759 static int __net_init xfrm4_net_init(struct net *net)
100760 {
100761 - struct ctl_table *table;
100762 + ctl_table_no_const *table = NULL;
100763 struct ctl_table_header *hdr;
100764
100765 - table = xfrm4_policy_table;
100766 if (!net_eq(net, &init_net)) {
100767 - table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
100768 + table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
100769 if (!table)
100770 goto err_alloc;
100771
100772 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
100773 - }
100774 -
100775 - hdr = register_net_sysctl(net, "net/ipv4", table);
100776 + hdr = register_net_sysctl(net, "net/ipv4", table);
100777 + } else
100778 + hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
100779 if (!hdr)
100780 goto err_reg;
100781
100782 @@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
100783 return 0;
100784
100785 err_reg:
100786 - if (!net_eq(net, &init_net))
100787 - kfree(table);
100788 + kfree(table);
100789 err_alloc:
100790 return -ENOMEM;
100791 }
100792 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
100793 index 6c7fa08..8a31430 100644
100794 --- a/net/ipv6/addrconf.c
100795 +++ b/net/ipv6/addrconf.c
100796 @@ -598,7 +598,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
100797 idx = 0;
100798 head = &net->dev_index_head[h];
100799 rcu_read_lock();
100800 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
100801 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
100802 net->dev_base_seq;
100803 hlist_for_each_entry_rcu(dev, head, index_hlist) {
100804 if (idx < s_idx)
100805 @@ -2395,7 +2395,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
100806 p.iph.ihl = 5;
100807 p.iph.protocol = IPPROTO_IPV6;
100808 p.iph.ttl = 64;
100809 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
100810 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
100811
100812 if (ops->ndo_do_ioctl) {
100813 mm_segment_t oldfs = get_fs();
100814 @@ -3528,16 +3528,23 @@ static const struct file_operations if6_fops = {
100815 .release = seq_release_net,
100816 };
100817
100818 +extern void register_ipv6_seq_ops_addr(struct seq_operations *addr);
100819 +extern void unregister_ipv6_seq_ops_addr(void);
100820 +
100821 static int __net_init if6_proc_net_init(struct net *net)
100822 {
100823 - if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops))
100824 + register_ipv6_seq_ops_addr(&if6_seq_ops);
100825 + if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops)) {
100826 + unregister_ipv6_seq_ops_addr();
100827 return -ENOMEM;
100828 + }
100829 return 0;
100830 }
100831
100832 static void __net_exit if6_proc_net_exit(struct net *net)
100833 {
100834 remove_proc_entry("if_inet6", net->proc_net);
100835 + unregister_ipv6_seq_ops_addr();
100836 }
100837
100838 static struct pernet_operations if6_proc_net_ops = {
100839 @@ -4146,7 +4153,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
100840 s_ip_idx = ip_idx = cb->args[2];
100841
100842 rcu_read_lock();
100843 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
100844 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
100845 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
100846 idx = 0;
100847 head = &net->dev_index_head[h];
100848 @@ -4758,7 +4765,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
100849 dst_free(&ifp->rt->dst);
100850 break;
100851 }
100852 - atomic_inc(&net->ipv6.dev_addr_genid);
100853 + atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
100854 rt_genid_bump_ipv6(net);
100855 }
100856
100857 @@ -4779,7 +4786,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
100858 int *valp = ctl->data;
100859 int val = *valp;
100860 loff_t pos = *ppos;
100861 - struct ctl_table lctl;
100862 + ctl_table_no_const lctl;
100863 int ret;
100864
100865 /*
100866 @@ -4864,7 +4871,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
100867 int *valp = ctl->data;
100868 int val = *valp;
100869 loff_t pos = *ppos;
100870 - struct ctl_table lctl;
100871 + ctl_table_no_const lctl;
100872 int ret;
100873
100874 /*
100875 diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
100876 index d935889..2f64330 100644
100877 --- a/net/ipv6/af_inet6.c
100878 +++ b/net/ipv6/af_inet6.c
100879 @@ -776,7 +776,7 @@ static int __net_init inet6_net_init(struct net *net)
100880 net->ipv6.sysctl.bindv6only = 0;
100881 net->ipv6.sysctl.icmpv6_time = 1*HZ;
100882 net->ipv6.sysctl.flowlabel_consistency = 1;
100883 - atomic_set(&net->ipv6.rt_genid, 0);
100884 + atomic_set_unchecked(&net->ipv6.rt_genid, 0);
100885
100886 err = ipv6_init_mibs(net);
100887 if (err)
100888 diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
100889 index c3bf2d2..1f00573 100644
100890 --- a/net/ipv6/datagram.c
100891 +++ b/net/ipv6/datagram.c
100892 @@ -938,5 +938,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
100893 0,
100894 sock_i_ino(sp),
100895 atomic_read(&sp->sk_refcnt), sp,
100896 - atomic_read(&sp->sk_drops));
100897 + atomic_read_unchecked(&sp->sk_drops));
100898 }
100899 diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
100900 index 7b32652..0bc348b 100644
100901 --- a/net/ipv6/icmp.c
100902 +++ b/net/ipv6/icmp.c
100903 @@ -1005,7 +1005,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
100904
100905 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
100906 {
100907 - struct ctl_table *table;
100908 + ctl_table_no_const *table;
100909
100910 table = kmemdup(ipv6_icmp_table_template,
100911 sizeof(ipv6_icmp_table_template),
100912 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
100913 index 9d92146..d986c6a 100644
100914 --- a/net/ipv6/ip6_gre.c
100915 +++ b/net/ipv6/ip6_gre.c
100916 @@ -71,7 +71,7 @@ struct ip6gre_net {
100917 struct net_device *fb_tunnel_dev;
100918 };
100919
100920 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
100921 +static struct rtnl_link_ops ip6gre_link_ops;
100922 static int ip6gre_tunnel_init(struct net_device *dev);
100923 static void ip6gre_tunnel_setup(struct net_device *dev);
100924 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
100925 @@ -1291,7 +1291,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
100926 }
100927
100928
100929 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
100930 +static struct inet6_protocol ip6gre_protocol = {
100931 .handler = ip6gre_rcv,
100932 .err_handler = ip6gre_err,
100933 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
100934 @@ -1636,7 +1636,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
100935 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
100936 };
100937
100938 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
100939 +static struct rtnl_link_ops ip6gre_link_ops = {
100940 .kind = "ip6gre",
100941 .maxtype = IFLA_GRE_MAX,
100942 .policy = ip6gre_policy,
100943 @@ -1650,7 +1650,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
100944 .fill_info = ip6gre_fill_info,
100945 };
100946
100947 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
100948 +static struct rtnl_link_ops ip6gre_tap_ops = {
100949 .kind = "ip6gretap",
100950 .maxtype = IFLA_GRE_MAX,
100951 .policy = ip6gre_policy,
100952 diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
100953 index afa0824..04ba530 100644
100954 --- a/net/ipv6/ip6_tunnel.c
100955 +++ b/net/ipv6/ip6_tunnel.c
100956 @@ -86,7 +86,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
100957
100958 static int ip6_tnl_dev_init(struct net_device *dev);
100959 static void ip6_tnl_dev_setup(struct net_device *dev);
100960 -static struct rtnl_link_ops ip6_link_ops __read_mostly;
100961 +static struct rtnl_link_ops ip6_link_ops;
100962
100963 static int ip6_tnl_net_id __read_mostly;
100964 struct ip6_tnl_net {
100965 @@ -1708,7 +1708,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
100966 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
100967 };
100968
100969 -static struct rtnl_link_ops ip6_link_ops __read_mostly = {
100970 +static struct rtnl_link_ops ip6_link_ops = {
100971 .kind = "ip6tnl",
100972 .maxtype = IFLA_IPTUN_MAX,
100973 .policy = ip6_tnl_policy,
100974 diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
100975 index 6cc9f93..6e5bb7c 100644
100976 --- a/net/ipv6/ip6_vti.c
100977 +++ b/net/ipv6/ip6_vti.c
100978 @@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
100979
100980 static int vti6_dev_init(struct net_device *dev);
100981 static void vti6_dev_setup(struct net_device *dev);
100982 -static struct rtnl_link_ops vti6_link_ops __read_mostly;
100983 +static struct rtnl_link_ops vti6_link_ops;
100984
100985 static int vti6_net_id __read_mostly;
100986 struct vti6_net {
100987 @@ -980,7 +980,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
100988 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
100989 };
100990
100991 -static struct rtnl_link_ops vti6_link_ops __read_mostly = {
100992 +static struct rtnl_link_ops vti6_link_ops = {
100993 .kind = "vti6",
100994 .maxtype = IFLA_VTI_MAX,
100995 .policy = vti6_policy,
100996 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
100997 index edb58af..78de133 100644
100998 --- a/net/ipv6/ipv6_sockglue.c
100999 +++ b/net/ipv6/ipv6_sockglue.c
101000 @@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
101001 if (sk->sk_type != SOCK_STREAM)
101002 return -ENOPROTOOPT;
101003
101004 - msg.msg_control = optval;
101005 + msg.msg_control = (void __force_kernel *)optval;
101006 msg.msg_controllen = len;
101007 msg.msg_flags = flags;
101008
101009 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
101010 index e080fbb..412b3cf 100644
101011 --- a/net/ipv6/netfilter/ip6_tables.c
101012 +++ b/net/ipv6/netfilter/ip6_tables.c
101013 @@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
101014 #endif
101015
101016 static int get_info(struct net *net, void __user *user,
101017 - const int *len, int compat)
101018 + int len, int compat)
101019 {
101020 char name[XT_TABLE_MAXNAMELEN];
101021 struct xt_table *t;
101022 int ret;
101023
101024 - if (*len != sizeof(struct ip6t_getinfo)) {
101025 - duprintf("length %u != %zu\n", *len,
101026 + if (len != sizeof(struct ip6t_getinfo)) {
101027 + duprintf("length %u != %zu\n", len,
101028 sizeof(struct ip6t_getinfo));
101029 return -EINVAL;
101030 }
101031 @@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
101032 info.size = private->size;
101033 strcpy(info.name, name);
101034
101035 - if (copy_to_user(user, &info, *len) != 0)
101036 + if (copy_to_user(user, &info, len) != 0)
101037 ret = -EFAULT;
101038 else
101039 ret = 0;
101040 @@ -1983,7 +1983,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
101041
101042 switch (cmd) {
101043 case IP6T_SO_GET_INFO:
101044 - ret = get_info(sock_net(sk), user, len, 1);
101045 + ret = get_info(sock_net(sk), user, *len, 1);
101046 break;
101047 case IP6T_SO_GET_ENTRIES:
101048 ret = compat_get_entries(sock_net(sk), user, len);
101049 @@ -2030,7 +2030,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
101050
101051 switch (cmd) {
101052 case IP6T_SO_GET_INFO:
101053 - ret = get_info(sock_net(sk), user, len, 0);
101054 + ret = get_info(sock_net(sk), user, *len, 0);
101055 break;
101056
101057 case IP6T_SO_GET_ENTRIES:
101058 diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
101059 index 767ab8d..c5ec70a 100644
101060 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c
101061 +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
101062 @@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
101063
101064 static int nf_ct_frag6_sysctl_register(struct net *net)
101065 {
101066 - struct ctl_table *table;
101067 + ctl_table_no_const *table = NULL;
101068 struct ctl_table_header *hdr;
101069
101070 - table = nf_ct_frag6_sysctl_table;
101071 if (!net_eq(net, &init_net)) {
101072 - table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
101073 + table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
101074 GFP_KERNEL);
101075 if (table == NULL)
101076 goto err_alloc;
101077 @@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
101078 table[0].data = &net->nf_frag.frags.timeout;
101079 table[1].data = &net->nf_frag.frags.low_thresh;
101080 table[2].data = &net->nf_frag.frags.high_thresh;
101081 - }
101082 -
101083 - hdr = register_net_sysctl(net, "net/netfilter", table);
101084 + hdr = register_net_sysctl(net, "net/netfilter", table);
101085 + } else
101086 + hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
101087 if (hdr == NULL)
101088 goto err_reg;
101089
101090 @@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
101091 return 0;
101092
101093 err_reg:
101094 - if (!net_eq(net, &init_net))
101095 - kfree(table);
101096 + kfree(table);
101097 err_alloc:
101098 return -ENOMEM;
101099 }
101100 diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
101101 index 6179ac1..ffa0293 100644
101102 --- a/net/ipv6/output_core.c
101103 +++ b/net/ipv6/output_core.c
101104 @@ -8,7 +8,6 @@
101105 #include <net/addrconf.h>
101106 #include <net/secure_seq.h>
101107
101108 -
101109 int ip6_find_1stfragopt(struct sk_buff *skb, u8 **nexthdr)
101110 {
101111 u16 offset = sizeof(struct ipv6hdr);
101112 diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
101113 index bda7429..469b26b 100644
101114 --- a/net/ipv6/ping.c
101115 +++ b/net/ipv6/ping.c
101116 @@ -246,6 +246,24 @@ static struct pernet_operations ping_v6_net_ops = {
101117 };
101118 #endif
101119
101120 +static struct pingv6_ops real_pingv6_ops = {
101121 + .ipv6_recv_error = ipv6_recv_error,
101122 + .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
101123 + .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
101124 + .icmpv6_err_convert = icmpv6_err_convert,
101125 + .ipv6_icmp_error = ipv6_icmp_error,
101126 + .ipv6_chk_addr = ipv6_chk_addr,
101127 +};
101128 +
101129 +static struct pingv6_ops dummy_pingv6_ops = {
101130 + .ipv6_recv_error = dummy_ipv6_recv_error,
101131 + .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
101132 + .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
101133 + .icmpv6_err_convert = dummy_icmpv6_err_convert,
101134 + .ipv6_icmp_error = dummy_ipv6_icmp_error,
101135 + .ipv6_chk_addr = dummy_ipv6_chk_addr,
101136 +};
101137 +
101138 int __init pingv6_init(void)
101139 {
101140 #ifdef CONFIG_PROC_FS
101141 @@ -253,13 +271,7 @@ int __init pingv6_init(void)
101142 if (ret)
101143 return ret;
101144 #endif
101145 - pingv6_ops.ipv6_recv_error = ipv6_recv_error;
101146 - pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
101147 - pingv6_ops.ip6_datagram_recv_specific_ctl =
101148 - ip6_datagram_recv_specific_ctl;
101149 - pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
101150 - pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
101151 - pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
101152 + pingv6_ops = &real_pingv6_ops;
101153 return inet6_register_protosw(&pingv6_protosw);
101154 }
101155
101156 @@ -268,14 +280,9 @@ int __init pingv6_init(void)
101157 */
101158 void pingv6_exit(void)
101159 {
101160 - pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
101161 - pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
101162 - pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
101163 - pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
101164 - pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
101165 - pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
101166 #ifdef CONFIG_PROC_FS
101167 unregister_pernet_subsys(&ping_v6_net_ops);
101168 #endif
101169 + pingv6_ops = &dummy_pingv6_ops;
101170 inet6_unregister_protosw(&pingv6_protosw);
101171 }
101172 diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
101173 index 091d066..139d410 100644
101174 --- a/net/ipv6/proc.c
101175 +++ b/net/ipv6/proc.c
101176 @@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
101177 if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
101178 goto proc_snmp6_fail;
101179
101180 - net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
101181 + net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
101182 if (!net->mib.proc_net_devsnmp6)
101183 goto proc_dev_snmp6_fail;
101184 return 0;
101185 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
101186 index 1f29996..46fe0c7 100644
101187 --- a/net/ipv6/raw.c
101188 +++ b/net/ipv6/raw.c
101189 @@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
101190 {
101191 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
101192 skb_checksum_complete(skb)) {
101193 - atomic_inc(&sk->sk_drops);
101194 + atomic_inc_unchecked(&sk->sk_drops);
101195 kfree_skb(skb);
101196 return NET_RX_DROP;
101197 }
101198 @@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
101199 struct raw6_sock *rp = raw6_sk(sk);
101200
101201 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
101202 - atomic_inc(&sk->sk_drops);
101203 + atomic_inc_unchecked(&sk->sk_drops);
101204 kfree_skb(skb);
101205 return NET_RX_DROP;
101206 }
101207 @@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
101208
101209 if (inet->hdrincl) {
101210 if (skb_checksum_complete(skb)) {
101211 - atomic_inc(&sk->sk_drops);
101212 + atomic_inc_unchecked(&sk->sk_drops);
101213 kfree_skb(skb);
101214 return NET_RX_DROP;
101215 }
101216 @@ -469,6 +469,9 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
101217 if (flags & MSG_OOB)
101218 return -EOPNOTSUPP;
101219
101220 + if (addr_len)
101221 + *addr_len=sizeof(*sin6);
101222 +
101223 if (flags & MSG_ERRQUEUE)
101224 return ipv6_recv_error(sk, msg, len, addr_len);
101225
101226 @@ -507,7 +510,6 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
101227 sin6->sin6_flowinfo = 0;
101228 sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
101229 IP6CB(skb)->iif);
101230 - *addr_len = sizeof(*sin6);
101231 }
101232
101233 sock_recv_ts_and_drops(msg, sk, skb);
101234 @@ -610,7 +612,7 @@ out:
101235 return err;
101236 }
101237
101238 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
101239 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
101240 struct flowi6 *fl6, struct dst_entry **dstp,
101241 unsigned int flags)
101242 {
101243 @@ -922,12 +924,15 @@ do_confirm:
101244 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
101245 char __user *optval, int optlen)
101246 {
101247 + struct icmp6_filter filter;
101248 +
101249 switch (optname) {
101250 case ICMPV6_FILTER:
101251 if (optlen > sizeof(struct icmp6_filter))
101252 optlen = sizeof(struct icmp6_filter);
101253 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
101254 + if (copy_from_user(&filter, optval, optlen))
101255 return -EFAULT;
101256 + raw6_sk(sk)->filter = filter;
101257 return 0;
101258 default:
101259 return -ENOPROTOOPT;
101260 @@ -940,6 +945,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
101261 char __user *optval, int __user *optlen)
101262 {
101263 int len;
101264 + struct icmp6_filter filter;
101265
101266 switch (optname) {
101267 case ICMPV6_FILTER:
101268 @@ -951,7 +957,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
101269 len = sizeof(struct icmp6_filter);
101270 if (put_user(len, optlen))
101271 return -EFAULT;
101272 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
101273 + filter = raw6_sk(sk)->filter;
101274 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
101275 return -EFAULT;
101276 return 0;
101277 default:
101278 diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
101279 index cc85a9b..526a133 100644
101280 --- a/net/ipv6/reassembly.c
101281 +++ b/net/ipv6/reassembly.c
101282 @@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
101283
101284 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
101285 {
101286 - struct ctl_table *table;
101287 + ctl_table_no_const *table = NULL;
101288 struct ctl_table_header *hdr;
101289
101290 - table = ip6_frags_ns_ctl_table;
101291 if (!net_eq(net, &init_net)) {
101292 - table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
101293 + table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
101294 if (table == NULL)
101295 goto err_alloc;
101296
101297 @@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
101298 /* Don't export sysctls to unprivileged users */
101299 if (net->user_ns != &init_user_ns)
101300 table[0].procname = NULL;
101301 - }
101302 + hdr = register_net_sysctl(net, "net/ipv6", table);
101303 + } else
101304 + hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
101305
101306 - hdr = register_net_sysctl(net, "net/ipv6", table);
101307 if (hdr == NULL)
101308 goto err_reg;
101309
101310 @@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
101311 return 0;
101312
101313 err_reg:
101314 - if (!net_eq(net, &init_net))
101315 - kfree(table);
101316 + kfree(table);
101317 err_alloc:
101318 return -ENOMEM;
101319 }
101320 diff --git a/net/ipv6/route.c b/net/ipv6/route.c
101321 index 6ebdb7b6..f225ab1 100644
101322 --- a/net/ipv6/route.c
101323 +++ b/net/ipv6/route.c
101324 @@ -2971,7 +2971,7 @@ struct ctl_table ipv6_route_table_template[] = {
101325
101326 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
101327 {
101328 - struct ctl_table *table;
101329 + ctl_table_no_const *table;
101330
101331 table = kmemdup(ipv6_route_table_template,
101332 sizeof(ipv6_route_table_template),
101333 diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
101334 index 4f40817..54dcbef 100644
101335 --- a/net/ipv6/sit.c
101336 +++ b/net/ipv6/sit.c
101337 @@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
101338 static void ipip6_dev_free(struct net_device *dev);
101339 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
101340 __be32 *v4dst);
101341 -static struct rtnl_link_ops sit_link_ops __read_mostly;
101342 +static struct rtnl_link_ops sit_link_ops;
101343
101344 static int sit_net_id __read_mostly;
101345 struct sit_net {
101346 @@ -1661,7 +1661,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
101347 unregister_netdevice_queue(dev, head);
101348 }
101349
101350 -static struct rtnl_link_ops sit_link_ops __read_mostly = {
101351 +static struct rtnl_link_ops sit_link_ops = {
101352 .kind = "sit",
101353 .maxtype = IFLA_IPTUN_MAX,
101354 .policy = ipip6_policy,
101355 diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
101356 index 7f405a1..eabef92 100644
101357 --- a/net/ipv6/sysctl_net_ipv6.c
101358 +++ b/net/ipv6/sysctl_net_ipv6.c
101359 @@ -54,7 +54,7 @@ static struct ctl_table ipv6_rotable[] = {
101360
101361 static int __net_init ipv6_sysctl_net_init(struct net *net)
101362 {
101363 - struct ctl_table *ipv6_table;
101364 + ctl_table_no_const *ipv6_table;
101365 struct ctl_table *ipv6_route_table;
101366 struct ctl_table *ipv6_icmp_table;
101367 int err;
101368 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
101369 index e289830..79a5718 100644
101370 --- a/net/ipv6/tcp_ipv6.c
101371 +++ b/net/ipv6/tcp_ipv6.c
101372 @@ -102,6 +102,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
101373 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
101374 }
101375
101376 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101377 +extern int grsec_enable_blackhole;
101378 +#endif
101379 +
101380 static void tcp_v6_hash(struct sock *sk)
101381 {
101382 if (sk->sk_state != TCP_CLOSE) {
101383 @@ -1416,6 +1420,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
101384 return 0;
101385
101386 reset:
101387 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101388 + if (!grsec_enable_blackhole)
101389 +#endif
101390 tcp_v6_send_reset(sk, skb);
101391 discard:
101392 if (opt_skb)
101393 @@ -1500,12 +1507,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
101394 TCP_SKB_CB(skb)->sacked = 0;
101395
101396 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
101397 - if (!sk)
101398 + if (!sk) {
101399 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101400 + ret = 1;
101401 +#endif
101402 goto no_tcp_socket;
101403 + }
101404
101405 process:
101406 - if (sk->sk_state == TCP_TIME_WAIT)
101407 + if (sk->sk_state == TCP_TIME_WAIT) {
101408 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101409 + ret = 2;
101410 +#endif
101411 goto do_time_wait;
101412 + }
101413
101414 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
101415 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
101416 @@ -1557,6 +1572,10 @@ csum_error:
101417 bad_packet:
101418 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
101419 } else {
101420 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101421 + if (!grsec_enable_blackhole || (ret == 1 &&
101422 + (skb->dev->flags & IFF_LOOPBACK)))
101423 +#endif
101424 tcp_v6_send_reset(NULL, skb);
101425 }
101426
101427 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
101428 index 20b63d2..13be908 100644
101429 --- a/net/ipv6/udp.c
101430 +++ b/net/ipv6/udp.c
101431 @@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
101432 udp_ipv6_hash_secret + net_hash_mix(net));
101433 }
101434
101435 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101436 +extern int grsec_enable_blackhole;
101437 +#endif
101438 +
101439 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
101440 {
101441 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
101442 @@ -392,6 +396,9 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
101443 int is_udp4;
101444 bool slow;
101445
101446 + if (addr_len)
101447 + *addr_len = sizeof(struct sockaddr_in6);
101448 +
101449 if (flags & MSG_ERRQUEUE)
101450 return ipv6_recv_error(sk, msg, len, addr_len);
101451
101452 @@ -435,7 +442,7 @@ try_again:
101453 if (unlikely(err)) {
101454 trace_kfree_skb(skb, udpv6_recvmsg);
101455 if (!peeked) {
101456 - atomic_inc(&sk->sk_drops);
101457 + atomic_inc_unchecked(&sk->sk_drops);
101458 if (is_udp4)
101459 UDP_INC_STATS_USER(sock_net(sk),
101460 UDP_MIB_INERRORS,
101461 @@ -475,7 +482,7 @@ try_again:
101462 ipv6_iface_scope_id(&sin6->sin6_addr,
101463 IP6CB(skb)->iif);
101464 }
101465 - *addr_len = sizeof(*sin6);
101466 +
101467 }
101468
101469 if (np->rxopt.all)
101470 @@ -690,7 +697,7 @@ csum_error:
101471 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
101472 drop:
101473 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
101474 - atomic_inc(&sk->sk_drops);
101475 + atomic_inc_unchecked(&sk->sk_drops);
101476 kfree_skb(skb);
101477 return -1;
101478 }
101479 @@ -747,7 +754,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
101480 if (likely(skb1 == NULL))
101481 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
101482 if (!skb1) {
101483 - atomic_inc(&sk->sk_drops);
101484 + atomic_inc_unchecked(&sk->sk_drops);
101485 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
101486 IS_UDPLITE(sk));
101487 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
101488 @@ -886,6 +893,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
101489 goto csum_error;
101490
101491 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
101492 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101493 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
101494 +#endif
101495 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
101496
101497 kfree_skb(skb);
101498 diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
101499 index 2a0bbda..d75ca57 100644
101500 --- a/net/ipv6/xfrm6_policy.c
101501 +++ b/net/ipv6/xfrm6_policy.c
101502 @@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
101503 }
101504 }
101505
101506 -static inline int xfrm6_garbage_collect(struct dst_ops *ops)
101507 +static int xfrm6_garbage_collect(struct dst_ops *ops)
101508 {
101509 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
101510
101511 - xfrm6_policy_afinfo.garbage_collect(net);
101512 + xfrm_garbage_collect_deferred(net);
101513 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
101514 }
101515
101516 @@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
101517
101518 static int __net_init xfrm6_net_init(struct net *net)
101519 {
101520 - struct ctl_table *table;
101521 + ctl_table_no_const *table = NULL;
101522 struct ctl_table_header *hdr;
101523
101524 - table = xfrm6_policy_table;
101525 if (!net_eq(net, &init_net)) {
101526 - table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
101527 + table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
101528 if (!table)
101529 goto err_alloc;
101530
101531 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
101532 - }
101533 + hdr = register_net_sysctl(net, "net/ipv6", table);
101534 + } else
101535 + hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
101536
101537 - hdr = register_net_sysctl(net, "net/ipv6", table);
101538 if (!hdr)
101539 goto err_reg;
101540
101541 @@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
101542 return 0;
101543
101544 err_reg:
101545 - if (!net_eq(net, &init_net))
101546 - kfree(table);
101547 + kfree(table);
101548 err_alloc:
101549 return -ENOMEM;
101550 }
101551 diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
101552 index e15c16a..7cf07aa 100644
101553 --- a/net/ipx/ipx_proc.c
101554 +++ b/net/ipx/ipx_proc.c
101555 @@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
101556 struct proc_dir_entry *p;
101557 int rc = -ENOMEM;
101558
101559 - ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
101560 + ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
101561
101562 if (!ipx_proc_dir)
101563 goto out;
101564 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
101565 index 2ba8b97..6d33010 100644
101566 --- a/net/irda/ircomm/ircomm_tty.c
101567 +++ b/net/irda/ircomm/ircomm_tty.c
101568 @@ -317,11 +317,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
101569 add_wait_queue(&port->open_wait, &wait);
101570
101571 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
101572 - __FILE__, __LINE__, tty->driver->name, port->count);
101573 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
101574
101575 spin_lock_irqsave(&port->lock, flags);
101576 if (!tty_hung_up_p(filp))
101577 - port->count--;
101578 + atomic_dec(&port->count);
101579 port->blocked_open++;
101580 spin_unlock_irqrestore(&port->lock, flags);
101581
101582 @@ -356,7 +356,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
101583 }
101584
101585 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
101586 - __FILE__, __LINE__, tty->driver->name, port->count);
101587 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
101588
101589 schedule();
101590 }
101591 @@ -366,12 +366,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
101592
101593 spin_lock_irqsave(&port->lock, flags);
101594 if (!tty_hung_up_p(filp))
101595 - port->count++;
101596 + atomic_inc(&port->count);
101597 port->blocked_open--;
101598 spin_unlock_irqrestore(&port->lock, flags);
101599
101600 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
101601 - __FILE__, __LINE__, tty->driver->name, port->count);
101602 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
101603
101604 if (!retval)
101605 port->flags |= ASYNC_NORMAL_ACTIVE;
101606 @@ -445,12 +445,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
101607
101608 /* ++ is not atomic, so this should be protected - Jean II */
101609 spin_lock_irqsave(&self->port.lock, flags);
101610 - self->port.count++;
101611 + atomic_inc(&self->port.count);
101612 spin_unlock_irqrestore(&self->port.lock, flags);
101613 tty_port_tty_set(&self->port, tty);
101614
101615 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
101616 - self->line, self->port.count);
101617 + self->line, atomic_read(&self->port.count));
101618
101619 /* Not really used by us, but lets do it anyway */
101620 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
101621 @@ -987,7 +987,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
101622 tty_kref_put(port->tty);
101623 }
101624 port->tty = NULL;
101625 - port->count = 0;
101626 + atomic_set(&port->count, 0);
101627 spin_unlock_irqrestore(&port->lock, flags);
101628
101629 wake_up_interruptible(&port->open_wait);
101630 @@ -1344,7 +1344,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
101631 seq_putc(m, '\n');
101632
101633 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
101634 - seq_printf(m, "Open count: %d\n", self->port.count);
101635 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
101636 seq_printf(m, "Max data size: %d\n", self->max_data_size);
101637 seq_printf(m, "Max header size: %d\n", self->max_header_size);
101638
101639 diff --git a/net/irda/irproc.c b/net/irda/irproc.c
101640 index b9ac598..f88cc56 100644
101641 --- a/net/irda/irproc.c
101642 +++ b/net/irda/irproc.c
101643 @@ -66,7 +66,7 @@ void __init irda_proc_register(void)
101644 {
101645 int i;
101646
101647 - proc_irda = proc_mkdir("irda", init_net.proc_net);
101648 + proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
101649 if (proc_irda == NULL)
101650 return;
101651
101652 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
101653 index 8c9d730..66c6305 100644
101654 --- a/net/iucv/af_iucv.c
101655 +++ b/net/iucv/af_iucv.c
101656 @@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
101657
101658 write_lock_bh(&iucv_sk_list.lock);
101659
101660 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
101661 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
101662 while (__iucv_get_sock_by_name(name)) {
101663 sprintf(name, "%08x",
101664 - atomic_inc_return(&iucv_sk_list.autobind_name));
101665 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
101666 }
101667
101668 write_unlock_bh(&iucv_sk_list.lock);
101669 diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
101670 index da78793..bdd78cf 100644
101671 --- a/net/iucv/iucv.c
101672 +++ b/net/iucv/iucv.c
101673 @@ -702,7 +702,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
101674 return NOTIFY_OK;
101675 }
101676
101677 -static struct notifier_block __refdata iucv_cpu_notifier = {
101678 +static struct notifier_block iucv_cpu_notifier = {
101679 .notifier_call = iucv_cpu_notify,
101680 };
101681
101682 diff --git a/net/key/af_key.c b/net/key/af_key.c
101683 index f3c8307..7127791 100644
101684 --- a/net/key/af_key.c
101685 +++ b/net/key/af_key.c
101686 @@ -3070,10 +3070,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
101687 static u32 get_acqseq(void)
101688 {
101689 u32 res;
101690 - static atomic_t acqseq;
101691 + static atomic_unchecked_t acqseq;
101692
101693 do {
101694 - res = atomic_inc_return(&acqseq);
101695 + res = atomic_inc_return_unchecked(&acqseq);
101696 } while (!res);
101697 return res;
101698 }
101699 diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
101700 index 76125c5..e474828 100644
101701 --- a/net/l2tp/l2tp_eth.c
101702 +++ b/net/l2tp/l2tp_eth.c
101703 @@ -42,12 +42,12 @@ struct l2tp_eth {
101704 struct sock *tunnel_sock;
101705 struct l2tp_session *session;
101706 struct list_head list;
101707 - atomic_long_t tx_bytes;
101708 - atomic_long_t tx_packets;
101709 - atomic_long_t tx_dropped;
101710 - atomic_long_t rx_bytes;
101711 - atomic_long_t rx_packets;
101712 - atomic_long_t rx_errors;
101713 + atomic_long_unchecked_t tx_bytes;
101714 + atomic_long_unchecked_t tx_packets;
101715 + atomic_long_unchecked_t tx_dropped;
101716 + atomic_long_unchecked_t rx_bytes;
101717 + atomic_long_unchecked_t rx_packets;
101718 + atomic_long_unchecked_t rx_errors;
101719 };
101720
101721 /* via l2tp_session_priv() */
101722 @@ -98,10 +98,10 @@ static int l2tp_eth_dev_xmit(struct sk_buff *skb, struct net_device *dev)
101723 int ret = l2tp_xmit_skb(session, skb, session->hdr_len);
101724
101725 if (likely(ret == NET_XMIT_SUCCESS)) {
101726 - atomic_long_add(len, &priv->tx_bytes);
101727 - atomic_long_inc(&priv->tx_packets);
101728 + atomic_long_add_unchecked(len, &priv->tx_bytes);
101729 + atomic_long_inc_unchecked(&priv->tx_packets);
101730 } else {
101731 - atomic_long_inc(&priv->tx_dropped);
101732 + atomic_long_inc_unchecked(&priv->tx_dropped);
101733 }
101734 return NETDEV_TX_OK;
101735 }
101736 @@ -111,12 +111,12 @@ static struct rtnl_link_stats64 *l2tp_eth_get_stats64(struct net_device *dev,
101737 {
101738 struct l2tp_eth *priv = netdev_priv(dev);
101739
101740 - stats->tx_bytes = atomic_long_read(&priv->tx_bytes);
101741 - stats->tx_packets = atomic_long_read(&priv->tx_packets);
101742 - stats->tx_dropped = atomic_long_read(&priv->tx_dropped);
101743 - stats->rx_bytes = atomic_long_read(&priv->rx_bytes);
101744 - stats->rx_packets = atomic_long_read(&priv->rx_packets);
101745 - stats->rx_errors = atomic_long_read(&priv->rx_errors);
101746 + stats->tx_bytes = atomic_long_read_unchecked(&priv->tx_bytes);
101747 + stats->tx_packets = atomic_long_read_unchecked(&priv->tx_packets);
101748 + stats->tx_dropped = atomic_long_read_unchecked(&priv->tx_dropped);
101749 + stats->rx_bytes = atomic_long_read_unchecked(&priv->rx_bytes);
101750 + stats->rx_packets = atomic_long_read_unchecked(&priv->rx_packets);
101751 + stats->rx_errors = atomic_long_read_unchecked(&priv->rx_errors);
101752 return stats;
101753 }
101754
101755 @@ -166,15 +166,15 @@ static void l2tp_eth_dev_recv(struct l2tp_session *session, struct sk_buff *skb,
101756 nf_reset(skb);
101757
101758 if (dev_forward_skb(dev, skb) == NET_RX_SUCCESS) {
101759 - atomic_long_inc(&priv->rx_packets);
101760 - atomic_long_add(data_len, &priv->rx_bytes);
101761 + atomic_long_inc_unchecked(&priv->rx_packets);
101762 + atomic_long_add_unchecked(data_len, &priv->rx_bytes);
101763 } else {
101764 - atomic_long_inc(&priv->rx_errors);
101765 + atomic_long_inc_unchecked(&priv->rx_errors);
101766 }
101767 return;
101768
101769 error:
101770 - atomic_long_inc(&priv->rx_errors);
101771 + atomic_long_inc_unchecked(&priv->rx_errors);
101772 kfree_skb(skb);
101773 }
101774
101775 diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
101776 index 3397fe6..861fd1a 100644
101777 --- a/net/l2tp/l2tp_ip.c
101778 +++ b/net/l2tp/l2tp_ip.c
101779 @@ -518,6 +518,9 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
101780 if (flags & MSG_OOB)
101781 goto out;
101782
101783 + if (addr_len)
101784 + *addr_len = sizeof(*sin);
101785 +
101786 skb = skb_recv_datagram(sk, flags, noblock, &err);
101787 if (!skb)
101788 goto out;
101789 @@ -540,7 +543,6 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
101790 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
101791 sin->sin_port = 0;
101792 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
101793 - *addr_len = sizeof(*sin);
101794 }
101795 if (inet->cmsg_flags)
101796 ip_cmsg_recv(msg, skb);
101797 diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
101798 index 1a3c7e0..80f8b0c 100644
101799 --- a/net/llc/llc_proc.c
101800 +++ b/net/llc/llc_proc.c
101801 @@ -247,7 +247,7 @@ int __init llc_proc_init(void)
101802 int rc = -ENOMEM;
101803 struct proc_dir_entry *p;
101804
101805 - llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
101806 + llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
101807 if (!llc_proc_dir)
101808 goto out;
101809
101810 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
101811 index aaa59d7..21a2c4a 100644
101812 --- a/net/mac80211/cfg.c
101813 +++ b/net/mac80211/cfg.c
101814 @@ -839,7 +839,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
101815 ret = ieee80211_vif_use_channel(sdata, chandef,
101816 IEEE80211_CHANCTX_EXCLUSIVE);
101817 }
101818 - } else if (local->open_count == local->monitors) {
101819 + } else if (local_read(&local->open_count) == local->monitors) {
101820 local->_oper_chandef = *chandef;
101821 ieee80211_hw_config(local, 0);
101822 }
101823 @@ -3440,7 +3440,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
101824 else
101825 local->probe_req_reg--;
101826
101827 - if (!local->open_count)
101828 + if (!local_read(&local->open_count))
101829 break;
101830
101831 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
101832 @@ -3903,8 +3903,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
101833 if (chanctx_conf) {
101834 *chandef = chanctx_conf->def;
101835 ret = 0;
101836 - } else if (local->open_count > 0 &&
101837 - local->open_count == local->monitors &&
101838 + } else if (local_read(&local->open_count) > 0 &&
101839 + local_read(&local->open_count) == local->monitors &&
101840 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
101841 if (local->use_chanctx)
101842 *chandef = local->monitor_chandef;
101843 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
101844 index f169b6e..a5dc4eb 100644
101845 --- a/net/mac80211/ieee80211_i.h
101846 +++ b/net/mac80211/ieee80211_i.h
101847 @@ -28,6 +28,7 @@
101848 #include <net/ieee80211_radiotap.h>
101849 #include <net/cfg80211.h>
101850 #include <net/mac80211.h>
101851 +#include <asm/local.h>
101852 #include "key.h"
101853 #include "sta_info.h"
101854 #include "debug.h"
101855 @@ -999,7 +1000,7 @@ struct ieee80211_local {
101856 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
101857 spinlock_t queue_stop_reason_lock;
101858
101859 - int open_count;
101860 + local_t open_count;
101861 int monitors, cooked_mntrs;
101862 /* number of interfaces with corresponding FIF_ flags */
101863 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
101864 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
101865 index 34799e0..b411290 100644
101866 --- a/net/mac80211/iface.c
101867 +++ b/net/mac80211/iface.c
101868 @@ -524,7 +524,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101869 break;
101870 }
101871
101872 - if (local->open_count == 0) {
101873 + if (local_read(&local->open_count) == 0) {
101874 res = drv_start(local);
101875 if (res)
101876 goto err_del_bss;
101877 @@ -571,7 +571,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101878 res = drv_add_interface(local, sdata);
101879 if (res)
101880 goto err_stop;
101881 - } else if (local->monitors == 0 && local->open_count == 0) {
101882 + } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
101883 res = ieee80211_add_virtual_monitor(local);
101884 if (res)
101885 goto err_stop;
101886 @@ -680,7 +680,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101887 atomic_inc(&local->iff_promiscs);
101888
101889 if (coming_up)
101890 - local->open_count++;
101891 + local_inc(&local->open_count);
101892
101893 if (hw_reconf_flags)
101894 ieee80211_hw_config(local, hw_reconf_flags);
101895 @@ -718,7 +718,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101896 err_del_interface:
101897 drv_remove_interface(local, sdata);
101898 err_stop:
101899 - if (!local->open_count)
101900 + if (!local_read(&local->open_count))
101901 drv_stop(local);
101902 err_del_bss:
101903 sdata->bss = NULL;
101904 @@ -871,7 +871,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101905 }
101906
101907 if (going_down)
101908 - local->open_count--;
101909 + local_dec(&local->open_count);
101910
101911 switch (sdata->vif.type) {
101912 case NL80211_IFTYPE_AP_VLAN:
101913 @@ -930,7 +930,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101914 }
101915 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
101916
101917 - if (local->open_count == 0)
101918 + if (local_read(&local->open_count) == 0)
101919 ieee80211_clear_tx_pending(local);
101920
101921 /*
101922 @@ -970,7 +970,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101923
101924 ieee80211_recalc_ps(local, -1);
101925
101926 - if (local->open_count == 0) {
101927 + if (local_read(&local->open_count) == 0) {
101928 ieee80211_stop_device(local);
101929
101930 /* no reconfiguring after stop! */
101931 @@ -981,7 +981,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101932 ieee80211_configure_filter(local);
101933 ieee80211_hw_config(local, hw_reconf_flags);
101934
101935 - if (local->monitors == local->open_count)
101936 + if (local->monitors == local_read(&local->open_count))
101937 ieee80211_add_virtual_monitor(local);
101938 }
101939
101940 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
101941 index 4c1bf61..00b449b 100644
101942 --- a/net/mac80211/main.c
101943 +++ b/net/mac80211/main.c
101944 @@ -174,7 +174,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
101945 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
101946 IEEE80211_CONF_CHANGE_POWER);
101947
101948 - if (changed && local->open_count) {
101949 + if (changed && local_read(&local->open_count)) {
101950 ret = drv_config(local, changed);
101951 /*
101952 * Goal:
101953 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
101954 index d478b88..8c8d157 100644
101955 --- a/net/mac80211/pm.c
101956 +++ b/net/mac80211/pm.c
101957 @@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101958 struct ieee80211_sub_if_data *sdata;
101959 struct sta_info *sta;
101960
101961 - if (!local->open_count)
101962 + if (!local_read(&local->open_count))
101963 goto suspend;
101964
101965 ieee80211_scan_cancel(local);
101966 @@ -58,7 +58,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101967 cancel_work_sync(&local->dynamic_ps_enable_work);
101968 del_timer_sync(&local->dynamic_ps_timer);
101969
101970 - local->wowlan = wowlan && local->open_count;
101971 + local->wowlan = wowlan && local_read(&local->open_count);
101972 if (local->wowlan) {
101973 int err = drv_suspend(local, wowlan);
101974 if (err < 0) {
101975 @@ -123,7 +123,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101976 WARN_ON(!list_empty(&local->chanctx_list));
101977
101978 /* stop hardware - this must stop RX */
101979 - if (local->open_count)
101980 + if (local_read(&local->open_count))
101981 ieee80211_stop_device(local);
101982
101983 suspend:
101984 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
101985 index 8fdadfd..a4f72b8 100644
101986 --- a/net/mac80211/rate.c
101987 +++ b/net/mac80211/rate.c
101988 @@ -720,7 +720,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
101989
101990 ASSERT_RTNL();
101991
101992 - if (local->open_count)
101993 + if (local_read(&local->open_count))
101994 return -EBUSY;
101995
101996 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
101997 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
101998 index 6ff1346..936ca9a 100644
101999 --- a/net/mac80211/rc80211_pid_debugfs.c
102000 +++ b/net/mac80211/rc80211_pid_debugfs.c
102001 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
102002
102003 spin_unlock_irqrestore(&events->lock, status);
102004
102005 - if (copy_to_user(buf, pb, p))
102006 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
102007 return -EFAULT;
102008
102009 return p;
102010 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
102011 index 3c36583..12887fe 100644
102012 --- a/net/mac80211/util.c
102013 +++ b/net/mac80211/util.c
102014 @@ -1509,7 +1509,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
102015 }
102016 #endif
102017 /* everything else happens only if HW was up & running */
102018 - if (!local->open_count)
102019 + if (!local_read(&local->open_count))
102020 goto wake_up;
102021
102022 /*
102023 @@ -1734,7 +1734,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
102024 local->in_reconfig = false;
102025 barrier();
102026
102027 - if (local->monitors == local->open_count && local->monitors > 0)
102028 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
102029 ieee80211_add_virtual_monitor(local);
102030
102031 /*
102032 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
102033 index e9410d1..77b6378 100644
102034 --- a/net/netfilter/Kconfig
102035 +++ b/net/netfilter/Kconfig
102036 @@ -1081,6 +1081,16 @@ config NETFILTER_XT_MATCH_ESP
102037
102038 To compile it as a module, choose M here. If unsure, say N.
102039
102040 +config NETFILTER_XT_MATCH_GRADM
102041 + tristate '"gradm" match support'
102042 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
102043 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
102044 + ---help---
102045 + The gradm match allows to match on grsecurity RBAC being enabled.
102046 + It is useful when iptables rules are applied early on bootup to
102047 + prevent connections to the machine (except from a trusted host)
102048 + while the RBAC system is disabled.
102049 +
102050 config NETFILTER_XT_MATCH_HASHLIMIT
102051 tristate '"hashlimit" match support'
102052 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
102053 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
102054 index bffdad7..f9317d1 100644
102055 --- a/net/netfilter/Makefile
102056 +++ b/net/netfilter/Makefile
102057 @@ -133,6 +133,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
102058 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
102059 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
102060 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
102061 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
102062 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
102063 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
102064 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
102065 diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
102066 index 1172083..986f1c1 100644
102067 --- a/net/netfilter/ipset/ip_set_core.c
102068 +++ b/net/netfilter/ipset/ip_set_core.c
102069 @@ -1924,7 +1924,7 @@ done:
102070 return ret;
102071 }
102072
102073 -static struct nf_sockopt_ops so_set __read_mostly = {
102074 +static struct nf_sockopt_ops so_set = {
102075 .pf = PF_INET,
102076 .get_optmin = SO_IP_SET,
102077 .get_optmax = SO_IP_SET + 1,
102078 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
102079 index a8eb0a8..86f2de4 100644
102080 --- a/net/netfilter/ipvs/ip_vs_conn.c
102081 +++ b/net/netfilter/ipvs/ip_vs_conn.c
102082 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
102083 /* Increase the refcnt counter of the dest */
102084 ip_vs_dest_hold(dest);
102085
102086 - conn_flags = atomic_read(&dest->conn_flags);
102087 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
102088 if (cp->protocol != IPPROTO_UDP)
102089 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
102090 flags = cp->flags;
102091 @@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
102092
102093 cp->control = NULL;
102094 atomic_set(&cp->n_control, 0);
102095 - atomic_set(&cp->in_pkts, 0);
102096 + atomic_set_unchecked(&cp->in_pkts, 0);
102097
102098 cp->packet_xmit = NULL;
102099 cp->app = NULL;
102100 @@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
102101
102102 /* Don't drop the entry if its number of incoming packets is not
102103 located in [0, 8] */
102104 - i = atomic_read(&cp->in_pkts);
102105 + i = atomic_read_unchecked(&cp->in_pkts);
102106 if (i > 8 || i < 0) return 0;
102107
102108 if (!todrop_rate[i]) return 0;
102109 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
102110 index 3d2d2c8..c87e4d3 100644
102111 --- a/net/netfilter/ipvs/ip_vs_core.c
102112 +++ b/net/netfilter/ipvs/ip_vs_core.c
102113 @@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
102114 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
102115 /* do not touch skb anymore */
102116
102117 - atomic_inc(&cp->in_pkts);
102118 + atomic_inc_unchecked(&cp->in_pkts);
102119 ip_vs_conn_put(cp);
102120 return ret;
102121 }
102122 @@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
102123 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
102124 pkts = sysctl_sync_threshold(ipvs);
102125 else
102126 - pkts = atomic_add_return(1, &cp->in_pkts);
102127 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
102128
102129 if (ipvs->sync_state & IP_VS_STATE_MASTER)
102130 ip_vs_sync_conn(net, cp, pkts);
102131 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
102132 index c42e83d..a6a3f8b 100644
102133 --- a/net/netfilter/ipvs/ip_vs_ctl.c
102134 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
102135 @@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
102136 */
102137 ip_vs_rs_hash(ipvs, dest);
102138 }
102139 - atomic_set(&dest->conn_flags, conn_flags);
102140 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
102141
102142 /* bind the service */
102143 old_svc = rcu_dereference_protected(dest->svc, 1);
102144 @@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
102145 * align with netns init in ip_vs_control_net_init()
102146 */
102147
102148 -static struct ctl_table vs_vars[] = {
102149 +static ctl_table_no_const vs_vars[] __read_only = {
102150 {
102151 .procname = "amemthresh",
102152 .maxlen = sizeof(int),
102153 @@ -2075,7 +2075,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
102154 " %-7s %-6d %-10d %-10d\n",
102155 &dest->addr.in6,
102156 ntohs(dest->port),
102157 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
102158 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
102159 atomic_read(&dest->weight),
102160 atomic_read(&dest->activeconns),
102161 atomic_read(&dest->inactconns));
102162 @@ -2086,7 +2086,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
102163 "%-7s %-6d %-10d %-10d\n",
102164 ntohl(dest->addr.ip),
102165 ntohs(dest->port),
102166 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
102167 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
102168 atomic_read(&dest->weight),
102169 atomic_read(&dest->activeconns),
102170 atomic_read(&dest->inactconns));
102171 @@ -2564,7 +2564,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
102172
102173 entry.addr = dest->addr.ip;
102174 entry.port = dest->port;
102175 - entry.conn_flags = atomic_read(&dest->conn_flags);
102176 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
102177 entry.weight = atomic_read(&dest->weight);
102178 entry.u_threshold = dest->u_threshold;
102179 entry.l_threshold = dest->l_threshold;
102180 @@ -3107,7 +3107,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
102181 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
102182 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
102183 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
102184 - (atomic_read(&dest->conn_flags) &
102185 + (atomic_read_unchecked(&dest->conn_flags) &
102186 IP_VS_CONN_F_FWD_MASK)) ||
102187 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
102188 atomic_read(&dest->weight)) ||
102189 @@ -3697,7 +3697,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
102190 {
102191 int idx;
102192 struct netns_ipvs *ipvs = net_ipvs(net);
102193 - struct ctl_table *tbl;
102194 + ctl_table_no_const *tbl;
102195
102196 atomic_set(&ipvs->dropentry, 0);
102197 spin_lock_init(&ipvs->dropentry_lock);
102198 diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
102199 index 547ff33..c8c8117 100644
102200 --- a/net/netfilter/ipvs/ip_vs_lblc.c
102201 +++ b/net/netfilter/ipvs/ip_vs_lblc.c
102202 @@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
102203 * IPVS LBLC sysctl table
102204 */
102205 #ifdef CONFIG_SYSCTL
102206 -static struct ctl_table vs_vars_table[] = {
102207 +static ctl_table_no_const vs_vars_table[] __read_only = {
102208 {
102209 .procname = "lblc_expiration",
102210 .data = NULL,
102211 diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
102212 index 3f21a2f..a112e85 100644
102213 --- a/net/netfilter/ipvs/ip_vs_lblcr.c
102214 +++ b/net/netfilter/ipvs/ip_vs_lblcr.c
102215 @@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
102216 * IPVS LBLCR sysctl table
102217 */
102218
102219 -static struct ctl_table vs_vars_table[] = {
102220 +static ctl_table_no_const vs_vars_table[] __read_only = {
102221 {
102222 .procname = "lblcr_expiration",
102223 .data = NULL,
102224 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
102225 index db80126..ef7110e 100644
102226 --- a/net/netfilter/ipvs/ip_vs_sync.c
102227 +++ b/net/netfilter/ipvs/ip_vs_sync.c
102228 @@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
102229 cp = cp->control;
102230 if (cp) {
102231 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
102232 - pkts = atomic_add_return(1, &cp->in_pkts);
102233 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
102234 else
102235 pkts = sysctl_sync_threshold(ipvs);
102236 ip_vs_sync_conn(net, cp->control, pkts);
102237 @@ -771,7 +771,7 @@ control:
102238 if (!cp)
102239 return;
102240 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
102241 - pkts = atomic_add_return(1, &cp->in_pkts);
102242 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
102243 else
102244 pkts = sysctl_sync_threshold(ipvs);
102245 goto sloop;
102246 @@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
102247
102248 if (opt)
102249 memcpy(&cp->in_seq, opt, sizeof(*opt));
102250 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
102251 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
102252 cp->state = state;
102253 cp->old_state = cp->state;
102254 /*
102255 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
102256 index 7f0e1cf..e9a86e6 100644
102257 --- a/net/netfilter/ipvs/ip_vs_xmit.c
102258 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
102259 @@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
102260 else
102261 rc = NF_ACCEPT;
102262 /* do not touch skb anymore */
102263 - atomic_inc(&cp->in_pkts);
102264 + atomic_inc_unchecked(&cp->in_pkts);
102265 goto out;
102266 }
102267
102268 @@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
102269 else
102270 rc = NF_ACCEPT;
102271 /* do not touch skb anymore */
102272 - atomic_inc(&cp->in_pkts);
102273 + atomic_inc_unchecked(&cp->in_pkts);
102274 goto out;
102275 }
102276
102277 diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
102278 index a4b5e2a..13b1de3 100644
102279 --- a/net/netfilter/nf_conntrack_acct.c
102280 +++ b/net/netfilter/nf_conntrack_acct.c
102281 @@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
102282 #ifdef CONFIG_SYSCTL
102283 static int nf_conntrack_acct_init_sysctl(struct net *net)
102284 {
102285 - struct ctl_table *table;
102286 + ctl_table_no_const *table;
102287
102288 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
102289 GFP_KERNEL);
102290 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
102291 index 75421f2..0e69621 100644
102292 --- a/net/netfilter/nf_conntrack_core.c
102293 +++ b/net/netfilter/nf_conntrack_core.c
102294 @@ -1789,6 +1789,10 @@ void nf_conntrack_init_end(void)
102295 #define DYING_NULLS_VAL ((1<<30)+1)
102296 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
102297
102298 +#ifdef CONFIG_GRKERNSEC_HIDESYM
102299 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
102300 +#endif
102301 +
102302 int nf_conntrack_init_net(struct net *net)
102303 {
102304 int ret = -ENOMEM;
102305 @@ -1814,7 +1818,11 @@ int nf_conntrack_init_net(struct net *net)
102306 if (!net->ct.stat)
102307 goto err_pcpu_lists;
102308
102309 +#ifdef CONFIG_GRKERNSEC_HIDESYM
102310 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08x", atomic_inc_return_unchecked(&conntrack_cache_id));
102311 +#else
102312 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
102313 +#endif
102314 if (!net->ct.slabname)
102315 goto err_slabname;
102316
102317 diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
102318 index 1df1761..ce8b88a 100644
102319 --- a/net/netfilter/nf_conntrack_ecache.c
102320 +++ b/net/netfilter/nf_conntrack_ecache.c
102321 @@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
102322 #ifdef CONFIG_SYSCTL
102323 static int nf_conntrack_event_init_sysctl(struct net *net)
102324 {
102325 - struct ctl_table *table;
102326 + ctl_table_no_const *table;
102327
102328 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
102329 GFP_KERNEL);
102330 diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
102331 index 5b3eae7..dd4b8fe 100644
102332 --- a/net/netfilter/nf_conntrack_helper.c
102333 +++ b/net/netfilter/nf_conntrack_helper.c
102334 @@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
102335
102336 static int nf_conntrack_helper_init_sysctl(struct net *net)
102337 {
102338 - struct ctl_table *table;
102339 + ctl_table_no_const *table;
102340
102341 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
102342 GFP_KERNEL);
102343 diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
102344 index b65d586..beec902 100644
102345 --- a/net/netfilter/nf_conntrack_proto.c
102346 +++ b/net/netfilter/nf_conntrack_proto.c
102347 @@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
102348
102349 static void
102350 nf_ct_unregister_sysctl(struct ctl_table_header **header,
102351 - struct ctl_table **table,
102352 + ctl_table_no_const **table,
102353 unsigned int users)
102354 {
102355 if (users > 0)
102356 diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
102357 index f641751..d3c5b51 100644
102358 --- a/net/netfilter/nf_conntrack_standalone.c
102359 +++ b/net/netfilter/nf_conntrack_standalone.c
102360 @@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
102361
102362 static int nf_conntrack_standalone_init_sysctl(struct net *net)
102363 {
102364 - struct ctl_table *table;
102365 + ctl_table_no_const *table;
102366
102367 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
102368 GFP_KERNEL);
102369 diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
102370 index 7a394df..bd91a8a 100644
102371 --- a/net/netfilter/nf_conntrack_timestamp.c
102372 +++ b/net/netfilter/nf_conntrack_timestamp.c
102373 @@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
102374 #ifdef CONFIG_SYSCTL
102375 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
102376 {
102377 - struct ctl_table *table;
102378 + ctl_table_no_const *table;
102379
102380 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
102381 GFP_KERNEL);
102382 diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
102383 index 85296d4..8becdec 100644
102384 --- a/net/netfilter/nf_log.c
102385 +++ b/net/netfilter/nf_log.c
102386 @@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
102387
102388 #ifdef CONFIG_SYSCTL
102389 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
102390 -static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
102391 +static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
102392
102393 static int nf_log_proc_dostring(struct ctl_table *table, int write,
102394 void __user *buffer, size_t *lenp, loff_t *ppos)
102395 @@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
102396 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
102397 mutex_unlock(&nf_log_mutex);
102398 } else {
102399 + ctl_table_no_const nf_log_table = *table;
102400 +
102401 mutex_lock(&nf_log_mutex);
102402 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
102403 lockdep_is_held(&nf_log_mutex));
102404 if (!logger)
102405 - table->data = "NONE";
102406 + nf_log_table.data = "NONE";
102407 else
102408 - table->data = logger->name;
102409 - r = proc_dostring(table, write, buffer, lenp, ppos);
102410 + nf_log_table.data = logger->name;
102411 + r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
102412 mutex_unlock(&nf_log_mutex);
102413 }
102414
102415 diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
102416 index f042ae5..30ea486 100644
102417 --- a/net/netfilter/nf_sockopt.c
102418 +++ b/net/netfilter/nf_sockopt.c
102419 @@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
102420 }
102421 }
102422
102423 - list_add(&reg->list, &nf_sockopts);
102424 + pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
102425 out:
102426 mutex_unlock(&nf_sockopt_mutex);
102427 return ret;
102428 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
102429 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
102430 {
102431 mutex_lock(&nf_sockopt_mutex);
102432 - list_del(&reg->list);
102433 + pax_list_del((struct list_head *)&reg->list);
102434 mutex_unlock(&nf_sockopt_mutex);
102435 }
102436 EXPORT_SYMBOL(nf_unregister_sockopt);
102437 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
102438 index d292c8d..9f1e166 100644
102439 --- a/net/netfilter/nfnetlink_log.c
102440 +++ b/net/netfilter/nfnetlink_log.c
102441 @@ -79,7 +79,7 @@ static int nfnl_log_net_id __read_mostly;
102442 struct nfnl_log_net {
102443 spinlock_t instances_lock;
102444 struct hlist_head instance_table[INSTANCE_BUCKETS];
102445 - atomic_t global_seq;
102446 + atomic_unchecked_t global_seq;
102447 };
102448
102449 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
102450 @@ -561,7 +561,7 @@ __build_packet_message(struct nfnl_log_net *log,
102451 /* global sequence number */
102452 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
102453 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
102454 - htonl(atomic_inc_return(&log->global_seq))))
102455 + htonl(atomic_inc_return_unchecked(&log->global_seq))))
102456 goto nla_put_failure;
102457
102458 if (data_len) {
102459 diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
102460 index 8a779be..1551d4c 100644
102461 --- a/net/netfilter/nft_compat.c
102462 +++ b/net/netfilter/nft_compat.c
102463 @@ -216,7 +216,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
102464 /* We want to reuse existing compat_to_user */
102465 old_fs = get_fs();
102466 set_fs(KERNEL_DS);
102467 - t->compat_to_user(out, in);
102468 + t->compat_to_user((void __force_user *)out, in);
102469 set_fs(old_fs);
102470 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
102471 kfree(out);
102472 @@ -403,7 +403,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
102473 /* We want to reuse existing compat_to_user */
102474 old_fs = get_fs();
102475 set_fs(KERNEL_DS);
102476 - m->compat_to_user(out, in);
102477 + m->compat_to_user((void __force_user *)out, in);
102478 set_fs(old_fs);
102479 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
102480 kfree(out);
102481 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
102482 new file mode 100644
102483 index 0000000..c566332
102484 --- /dev/null
102485 +++ b/net/netfilter/xt_gradm.c
102486 @@ -0,0 +1,51 @@
102487 +/*
102488 + * gradm match for netfilter
102489 + * Copyright © Zbigniew Krzystolik, 2010
102490 + *
102491 + * This program is free software; you can redistribute it and/or modify
102492 + * it under the terms of the GNU General Public License; either version
102493 + * 2 or 3 as published by the Free Software Foundation.
102494 + */
102495 +#include <linux/module.h>
102496 +#include <linux/moduleparam.h>
102497 +#include <linux/skbuff.h>
102498 +#include <linux/netfilter/x_tables.h>
102499 +#include <linux/grsecurity.h>
102500 +#include <linux/netfilter/xt_gradm.h>
102501 +
102502 +static bool
102503 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
102504 +{
102505 + const struct xt_gradm_mtinfo *info = par->matchinfo;
102506 + bool retval = false;
102507 + if (gr_acl_is_enabled())
102508 + retval = true;
102509 + return retval ^ info->invflags;
102510 +}
102511 +
102512 +static struct xt_match gradm_mt_reg __read_mostly = {
102513 + .name = "gradm",
102514 + .revision = 0,
102515 + .family = NFPROTO_UNSPEC,
102516 + .match = gradm_mt,
102517 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
102518 + .me = THIS_MODULE,
102519 +};
102520 +
102521 +static int __init gradm_mt_init(void)
102522 +{
102523 + return xt_register_match(&gradm_mt_reg);
102524 +}
102525 +
102526 +static void __exit gradm_mt_exit(void)
102527 +{
102528 + xt_unregister_match(&gradm_mt_reg);
102529 +}
102530 +
102531 +module_init(gradm_mt_init);
102532 +module_exit(gradm_mt_exit);
102533 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
102534 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
102535 +MODULE_LICENSE("GPL");
102536 +MODULE_ALIAS("ipt_gradm");
102537 +MODULE_ALIAS("ip6t_gradm");
102538 diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
102539 index a3910fc..2d2ba14 100644
102540 --- a/net/netfilter/xt_hashlimit.c
102541 +++ b/net/netfilter/xt_hashlimit.c
102542 @@ -870,11 +870,11 @@ static int __net_init hashlimit_proc_net_init(struct net *net)
102543 {
102544 struct hashlimit_net *hashlimit_net = hashlimit_pernet(net);
102545
102546 - hashlimit_net->ipt_hashlimit = proc_mkdir("ipt_hashlimit", net->proc_net);
102547 + hashlimit_net->ipt_hashlimit = proc_mkdir_restrict("ipt_hashlimit", net->proc_net);
102548 if (!hashlimit_net->ipt_hashlimit)
102549 return -ENOMEM;
102550 #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
102551 - hashlimit_net->ip6t_hashlimit = proc_mkdir("ip6t_hashlimit", net->proc_net);
102552 + hashlimit_net->ip6t_hashlimit = proc_mkdir_restrict("ip6t_hashlimit", net->proc_net);
102553 if (!hashlimit_net->ip6t_hashlimit) {
102554 remove_proc_entry("ipt_hashlimit", net->proc_net);
102555 return -ENOMEM;
102556 diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c
102557 index 1e657cf..1eb1c34 100644
102558 --- a/net/netfilter/xt_recent.c
102559 +++ b/net/netfilter/xt_recent.c
102560 @@ -618,7 +618,7 @@ static int __net_init recent_proc_net_init(struct net *net)
102561 {
102562 struct recent_net *recent_net = recent_pernet(net);
102563
102564 - recent_net->xt_recent = proc_mkdir("xt_recent", net->proc_net);
102565 + recent_net->xt_recent = proc_mkdir_restrict("xt_recent", net->proc_net);
102566 if (!recent_net->xt_recent)
102567 return -ENOMEM;
102568 return 0;
102569 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
102570 index 11de55e..f25e448 100644
102571 --- a/net/netfilter/xt_statistic.c
102572 +++ b/net/netfilter/xt_statistic.c
102573 @@ -19,7 +19,7 @@
102574 #include <linux/module.h>
102575
102576 struct xt_statistic_priv {
102577 - atomic_t count;
102578 + atomic_unchecked_t count;
102579 } ____cacheline_aligned_in_smp;
102580
102581 MODULE_LICENSE("GPL");
102582 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
102583 break;
102584 case XT_STATISTIC_MODE_NTH:
102585 do {
102586 - oval = atomic_read(&info->master->count);
102587 + oval = atomic_read_unchecked(&info->master->count);
102588 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
102589 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
102590 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
102591 if (nval == 0)
102592 ret = !ret;
102593 break;
102594 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
102595 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
102596 if (info->master == NULL)
102597 return -ENOMEM;
102598 - atomic_set(&info->master->count, info->u.nth.count);
102599 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
102600
102601 return 0;
102602 }
102603 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
102604 index 6c0fe97..1d852df 100644
102605 --- a/net/netlink/af_netlink.c
102606 +++ b/net/netlink/af_netlink.c
102607 @@ -257,7 +257,7 @@ static void netlink_overrun(struct sock *sk)
102608 sk->sk_error_report(sk);
102609 }
102610 }
102611 - atomic_inc(&sk->sk_drops);
102612 + atomic_inc_unchecked(&sk->sk_drops);
102613 }
102614
102615 static void netlink_rcv_wake(struct sock *sk)
102616 @@ -3028,7 +3028,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
102617 sk_wmem_alloc_get(s),
102618 nlk->cb_running,
102619 atomic_read(&s->sk_refcnt),
102620 - atomic_read(&s->sk_drops),
102621 + atomic_read_unchecked(&s->sk_drops),
102622 sock_i_ino(s)
102623 );
102624
102625 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
102626 index ede50d1..d2468e6 100644
102627 --- a/net/netrom/af_netrom.c
102628 +++ b/net/netrom/af_netrom.c
102629 @@ -850,7 +850,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
102630 *uaddr_len = sizeof(struct full_sockaddr_ax25);
102631 } else {
102632 sax->fsa_ax25.sax25_family = AF_NETROM;
102633 - sax->fsa_ax25.sax25_ndigis = 0;
102634 sax->fsa_ax25.sax25_call = nr->source_addr;
102635 *uaddr_len = sizeof(struct sockaddr_ax25);
102636 }
102637 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
102638 index b85c67c..09705b7 100644
102639 --- a/net/packet/af_packet.c
102640 +++ b/net/packet/af_packet.c
102641 @@ -275,7 +275,7 @@ static int packet_direct_xmit(struct sk_buff *skb)
102642
102643 return ret;
102644 drop:
102645 - atomic_long_inc(&dev->tx_dropped);
102646 + atomic_long_inc_unchecked(&dev->tx_dropped);
102647 kfree_skb(skb);
102648 return NET_XMIT_DROP;
102649 }
102650 @@ -636,6 +636,7 @@ static void init_prb_bdqc(struct packet_sock *po,
102651 p1->tov_in_jiffies = msecs_to_jiffies(p1->retire_blk_tov);
102652 p1->blk_sizeof_priv = req_u->req3.tp_sizeof_priv;
102653
102654 + p1->max_frame_len = p1->kblk_size - BLK_PLUS_PRIV(p1->blk_sizeof_priv);
102655 prb_init_ft_ops(p1, req_u);
102656 prb_setup_retire_blk_timer(po, tx_ring);
102657 prb_open_block(p1, pbd);
102658 @@ -1845,7 +1846,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
102659
102660 spin_lock(&sk->sk_receive_queue.lock);
102661 po->stats.stats1.tp_packets++;
102662 - skb->dropcount = atomic_read(&sk->sk_drops);
102663 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
102664 __skb_queue_tail(&sk->sk_receive_queue, skb);
102665 spin_unlock(&sk->sk_receive_queue.lock);
102666 sk->sk_data_ready(sk);
102667 @@ -1854,7 +1855,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
102668 drop_n_acct:
102669 spin_lock(&sk->sk_receive_queue.lock);
102670 po->stats.stats1.tp_drops++;
102671 - atomic_inc(&sk->sk_drops);
102672 + atomic_inc_unchecked(&sk->sk_drops);
102673 spin_unlock(&sk->sk_receive_queue.lock);
102674
102675 drop_n_restore:
102676 @@ -1946,6 +1947,18 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
102677 if ((int)snaplen < 0)
102678 snaplen = 0;
102679 }
102680 + } else if (unlikely(macoff + snaplen >
102681 + GET_PBDQC_FROM_RB(&po->rx_ring)->max_frame_len)) {
102682 + u32 nval;
102683 +
102684 + nval = GET_PBDQC_FROM_RB(&po->rx_ring)->max_frame_len - macoff;
102685 + pr_err_once("tpacket_rcv: packet too big, clamped from %u to %u. macoff=%u\n",
102686 + snaplen, nval, macoff);
102687 + snaplen = nval;
102688 + if (unlikely((int)snaplen < 0)) {
102689 + snaplen = 0;
102690 + macoff = GET_PBDQC_FROM_RB(&po->rx_ring)->max_frame_len;
102691 + }
102692 }
102693 spin_lock(&sk->sk_receive_queue.lock);
102694 h.raw = packet_current_rx_frame(po, skb,
102695 @@ -3459,7 +3472,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
102696 case PACKET_HDRLEN:
102697 if (len > sizeof(int))
102698 len = sizeof(int);
102699 - if (copy_from_user(&val, optval, len))
102700 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
102701 return -EFAULT;
102702 switch (val) {
102703 case TPACKET_V1:
102704 @@ -3505,7 +3518,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
102705 len = lv;
102706 if (put_user(len, optlen))
102707 return -EFAULT;
102708 - if (copy_to_user(optval, data, len))
102709 + if (len > sizeof(st) || copy_to_user(optval, data, len))
102710 return -EFAULT;
102711 return 0;
102712 }
102713 @@ -3789,6 +3802,10 @@ static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u,
102714 goto out;
102715 if (unlikely(req->tp_block_size & (PAGE_SIZE - 1)))
102716 goto out;
102717 + if (po->tp_version >= TPACKET_V3 &&
102718 + (int)(req->tp_block_size -
102719 + BLK_PLUS_PRIV(req_u->req3.tp_sizeof_priv)) <= 0)
102720 + goto out;
102721 if (unlikely(req->tp_frame_size < po->tp_hdrlen +
102722 po->tp_reserve))
102723 goto out;
102724 diff --git a/net/packet/internal.h b/net/packet/internal.h
102725 index eb9580a..cdddf6a 100644
102726 --- a/net/packet/internal.h
102727 +++ b/net/packet/internal.h
102728 @@ -29,6 +29,7 @@ struct tpacket_kbdq_core {
102729 char *pkblk_start;
102730 char *pkblk_end;
102731 int kblk_size;
102732 + unsigned int max_frame_len;
102733 unsigned int knum_blocks;
102734 uint64_t knxt_seq_num;
102735 char *prev;
102736 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
102737 index 70a547e..23477fe 100644
102738 --- a/net/phonet/pep.c
102739 +++ b/net/phonet/pep.c
102740 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
102741
102742 case PNS_PEP_CTRL_REQ:
102743 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
102744 - atomic_inc(&sk->sk_drops);
102745 + atomic_inc_unchecked(&sk->sk_drops);
102746 break;
102747 }
102748 __skb_pull(skb, 4);
102749 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
102750 }
102751
102752 if (pn->rx_credits == 0) {
102753 - atomic_inc(&sk->sk_drops);
102754 + atomic_inc_unchecked(&sk->sk_drops);
102755 err = -ENOBUFS;
102756 break;
102757 }
102758 @@ -579,7 +579,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
102759 }
102760
102761 if (pn->rx_credits == 0) {
102762 - atomic_inc(&sk->sk_drops);
102763 + atomic_inc_unchecked(&sk->sk_drops);
102764 err = NET_RX_DROP;
102765 break;
102766 }
102767 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
102768 index 008214a..bb68240 100644
102769 --- a/net/phonet/socket.c
102770 +++ b/net/phonet/socket.c
102771 @@ -611,7 +611,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
102772 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
102773 sock_i_ino(sk),
102774 atomic_read(&sk->sk_refcnt), sk,
102775 - atomic_read(&sk->sk_drops));
102776 + atomic_read_unchecked(&sk->sk_drops));
102777 }
102778 seq_pad(seq, '\n');
102779 return 0;
102780 diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
102781 index c02a8c4..3c5b600 100644
102782 --- a/net/phonet/sysctl.c
102783 +++ b/net/phonet/sysctl.c
102784 @@ -67,7 +67,7 @@ static int proc_local_port_range(struct ctl_table *table, int write,
102785 {
102786 int ret;
102787 int range[2] = {local_port_range[0], local_port_range[1]};
102788 - struct ctl_table tmp = {
102789 + ctl_table_no_const tmp = {
102790 .data = &range,
102791 .maxlen = sizeof(range),
102792 .mode = table->mode,
102793 diff --git a/net/rds/cong.c b/net/rds/cong.c
102794 index e5b65ac..f3b6fb7 100644
102795 --- a/net/rds/cong.c
102796 +++ b/net/rds/cong.c
102797 @@ -78,7 +78,7 @@
102798 * finds that the saved generation number is smaller than the global generation
102799 * number, it wakes up the process.
102800 */
102801 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
102802 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
102803
102804 /*
102805 * Congestion monitoring
102806 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
102807 rdsdebug("waking map %p for %pI4\n",
102808 map, &map->m_addr);
102809 rds_stats_inc(s_cong_update_received);
102810 - atomic_inc(&rds_cong_generation);
102811 + atomic_inc_unchecked(&rds_cong_generation);
102812 if (waitqueue_active(&map->m_waitq))
102813 wake_up(&map->m_waitq);
102814 if (waitqueue_active(&rds_poll_waitq))
102815 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
102816
102817 int rds_cong_updated_since(unsigned long *recent)
102818 {
102819 - unsigned long gen = atomic_read(&rds_cong_generation);
102820 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
102821
102822 if (likely(*recent == gen))
102823 return 0;
102824 diff --git a/net/rds/ib.h b/net/rds/ib.h
102825 index 7280ab8..e04f4ea 100644
102826 --- a/net/rds/ib.h
102827 +++ b/net/rds/ib.h
102828 @@ -128,7 +128,7 @@ struct rds_ib_connection {
102829 /* sending acks */
102830 unsigned long i_ack_flags;
102831 #ifdef KERNEL_HAS_ATOMIC64
102832 - atomic64_t i_ack_next; /* next ACK to send */
102833 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
102834 #else
102835 spinlock_t i_ack_lock; /* protect i_ack_next */
102836 u64 i_ack_next; /* next ACK to send */
102837 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
102838 index 31b74f5..dc1fbfa 100644
102839 --- a/net/rds/ib_cm.c
102840 +++ b/net/rds/ib_cm.c
102841 @@ -717,7 +717,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
102842 /* Clear the ACK state */
102843 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
102844 #ifdef KERNEL_HAS_ATOMIC64
102845 - atomic64_set(&ic->i_ack_next, 0);
102846 + atomic64_set_unchecked(&ic->i_ack_next, 0);
102847 #else
102848 ic->i_ack_next = 0;
102849 #endif
102850 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
102851 index b7ebe23..b6352f6 100644
102852 --- a/net/rds/ib_recv.c
102853 +++ b/net/rds/ib_recv.c
102854 @@ -596,7 +596,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
102855 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
102856 int ack_required)
102857 {
102858 - atomic64_set(&ic->i_ack_next, seq);
102859 + atomic64_set_unchecked(&ic->i_ack_next, seq);
102860 if (ack_required) {
102861 smp_mb__before_clear_bit();
102862 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
102863 @@ -608,7 +608,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
102864 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
102865 smp_mb__after_clear_bit();
102866
102867 - return atomic64_read(&ic->i_ack_next);
102868 + return atomic64_read_unchecked(&ic->i_ack_next);
102869 }
102870 #endif
102871
102872 diff --git a/net/rds/iw.h b/net/rds/iw.h
102873 index 04ce3b1..48119a6 100644
102874 --- a/net/rds/iw.h
102875 +++ b/net/rds/iw.h
102876 @@ -134,7 +134,7 @@ struct rds_iw_connection {
102877 /* sending acks */
102878 unsigned long i_ack_flags;
102879 #ifdef KERNEL_HAS_ATOMIC64
102880 - atomic64_t i_ack_next; /* next ACK to send */
102881 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
102882 #else
102883 spinlock_t i_ack_lock; /* protect i_ack_next */
102884 u64 i_ack_next; /* next ACK to send */
102885 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
102886 index a91e1db..cf3053f 100644
102887 --- a/net/rds/iw_cm.c
102888 +++ b/net/rds/iw_cm.c
102889 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
102890 /* Clear the ACK state */
102891 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
102892 #ifdef KERNEL_HAS_ATOMIC64
102893 - atomic64_set(&ic->i_ack_next, 0);
102894 + atomic64_set_unchecked(&ic->i_ack_next, 0);
102895 #else
102896 ic->i_ack_next = 0;
102897 #endif
102898 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
102899 index 4503335..db566b4 100644
102900 --- a/net/rds/iw_recv.c
102901 +++ b/net/rds/iw_recv.c
102902 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
102903 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
102904 int ack_required)
102905 {
102906 - atomic64_set(&ic->i_ack_next, seq);
102907 + atomic64_set_unchecked(&ic->i_ack_next, seq);
102908 if (ack_required) {
102909 smp_mb__before_clear_bit();
102910 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
102911 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
102912 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
102913 smp_mb__after_clear_bit();
102914
102915 - return atomic64_read(&ic->i_ack_next);
102916 + return atomic64_read_unchecked(&ic->i_ack_next);
102917 }
102918 #endif
102919
102920 diff --git a/net/rds/rds.h b/net/rds/rds.h
102921 index 48f8ffc..0ef3eec 100644
102922 --- a/net/rds/rds.h
102923 +++ b/net/rds/rds.h
102924 @@ -449,7 +449,7 @@ struct rds_transport {
102925 void (*sync_mr)(void *trans_private, int direction);
102926 void (*free_mr)(void *trans_private, int invalidate);
102927 void (*flush_mrs)(void);
102928 -};
102929 +} __do_const;
102930
102931 struct rds_sock {
102932 struct sock rs_sk;
102933 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
102934 index edac9ef..16bcb98 100644
102935 --- a/net/rds/tcp.c
102936 +++ b/net/rds/tcp.c
102937 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
102938 int val = 1;
102939
102940 set_fs(KERNEL_DS);
102941 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
102942 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
102943 sizeof(val));
102944 set_fs(oldfs);
102945 }
102946 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
102947 index 81cf5a4..b5826ff 100644
102948 --- a/net/rds/tcp_send.c
102949 +++ b/net/rds/tcp_send.c
102950 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
102951
102952 oldfs = get_fs();
102953 set_fs(KERNEL_DS);
102954 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
102955 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
102956 sizeof(val));
102957 set_fs(oldfs);
102958 }
102959 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
102960 index 7b16704..9628ec6 100644
102961 --- a/net/rxrpc/af_rxrpc.c
102962 +++ b/net/rxrpc/af_rxrpc.c
102963 @@ -40,7 +40,7 @@ static const struct proto_ops rxrpc_rpc_ops;
102964 __be32 rxrpc_epoch;
102965
102966 /* current debugging ID */
102967 -atomic_t rxrpc_debug_id;
102968 +atomic_unchecked_t rxrpc_debug_id;
102969
102970 /* count of skbs currently in use */
102971 atomic_t rxrpc_n_skbs;
102972 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
102973 index c6be17a..2a6200a 100644
102974 --- a/net/rxrpc/ar-ack.c
102975 +++ b/net/rxrpc/ar-ack.c
102976 @@ -223,7 +223,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
102977
102978 _enter("{%d,%d,%d,%d},",
102979 call->acks_hard, call->acks_unacked,
102980 - atomic_read(&call->sequence),
102981 + atomic_read_unchecked(&call->sequence),
102982 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
102983
102984 stop = 0;
102985 @@ -247,7 +247,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
102986
102987 /* each Tx packet has a new serial number */
102988 sp->hdr.serial =
102989 - htonl(atomic_inc_return(&call->conn->serial));
102990 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
102991
102992 hdr = (struct rxrpc_header *) txb->head;
102993 hdr->serial = sp->hdr.serial;
102994 @@ -451,7 +451,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
102995 */
102996 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
102997 {
102998 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
102999 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
103000 }
103001
103002 /*
103003 @@ -677,7 +677,7 @@ process_further:
103004
103005 latest = ntohl(sp->hdr.serial);
103006 hard = ntohl(ack.firstPacket);
103007 - tx = atomic_read(&call->sequence);
103008 + tx = atomic_read_unchecked(&call->sequence);
103009
103010 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
103011 latest,
103012 @@ -1209,7 +1209,7 @@ void rxrpc_process_call(struct work_struct *work)
103013 goto maybe_reschedule;
103014
103015 send_ACK_with_skew:
103016 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
103017 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
103018 ntohl(ack.serial));
103019 send_ACK:
103020 mtu = call->conn->trans->peer->if_mtu;
103021 @@ -1221,7 +1221,7 @@ send_ACK:
103022 ackinfo.rxMTU = htonl(rxrpc_rx_mtu);
103023 ackinfo.jumbo_max = htonl(rxrpc_rx_jumbo_max);
103024
103025 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
103026 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
103027 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
103028 ntohl(hdr.serial),
103029 ntohs(ack.maxSkew),
103030 @@ -1239,7 +1239,7 @@ send_ACK:
103031 send_message:
103032 _debug("send message");
103033
103034 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
103035 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
103036 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
103037 send_message_2:
103038
103039 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
103040 index a9e05db..194e793 100644
103041 --- a/net/rxrpc/ar-call.c
103042 +++ b/net/rxrpc/ar-call.c
103043 @@ -232,7 +232,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
103044 spin_lock_init(&call->lock);
103045 rwlock_init(&call->state_lock);
103046 atomic_set(&call->usage, 1);
103047 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
103048 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
103049 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
103050
103051 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
103052 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
103053 index 6631f4f..bfdf056 100644
103054 --- a/net/rxrpc/ar-connection.c
103055 +++ b/net/rxrpc/ar-connection.c
103056 @@ -210,7 +210,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
103057 rwlock_init(&conn->lock);
103058 spin_lock_init(&conn->state_lock);
103059 atomic_set(&conn->usage, 1);
103060 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
103061 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
103062 conn->avail_calls = RXRPC_MAXCALLS;
103063 conn->size_align = 4;
103064 conn->header_size = sizeof(struct rxrpc_header);
103065 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
103066 index e7ed43a..6afa140 100644
103067 --- a/net/rxrpc/ar-connevent.c
103068 +++ b/net/rxrpc/ar-connevent.c
103069 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
103070
103071 len = iov[0].iov_len + iov[1].iov_len;
103072
103073 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
103074 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
103075 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
103076
103077 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
103078 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
103079 index 63b21e5..330232e 100644
103080 --- a/net/rxrpc/ar-input.c
103081 +++ b/net/rxrpc/ar-input.c
103082 @@ -338,9 +338,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
103083 /* track the latest serial number on this connection for ACK packet
103084 * information */
103085 serial = ntohl(sp->hdr.serial);
103086 - hi_serial = atomic_read(&call->conn->hi_serial);
103087 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
103088 while (serial > hi_serial)
103089 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
103090 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
103091 serial);
103092
103093 /* request ACK generation for any ACK or DATA packet that requests
103094 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
103095 index ba9fd36..9bbfe01 100644
103096 --- a/net/rxrpc/ar-internal.h
103097 +++ b/net/rxrpc/ar-internal.h
103098 @@ -272,8 +272,8 @@ struct rxrpc_connection {
103099 int error; /* error code for local abort */
103100 int debug_id; /* debug ID for printks */
103101 unsigned int call_counter; /* call ID counter */
103102 - atomic_t serial; /* packet serial number counter */
103103 - atomic_t hi_serial; /* highest serial number received */
103104 + atomic_unchecked_t serial; /* packet serial number counter */
103105 + atomic_unchecked_t hi_serial; /* highest serial number received */
103106 u8 avail_calls; /* number of calls available */
103107 u8 size_align; /* data size alignment (for security) */
103108 u8 header_size; /* rxrpc + security header size */
103109 @@ -346,7 +346,7 @@ struct rxrpc_call {
103110 spinlock_t lock;
103111 rwlock_t state_lock; /* lock for state transition */
103112 atomic_t usage;
103113 - atomic_t sequence; /* Tx data packet sequence counter */
103114 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
103115 u32 abort_code; /* local/remote abort code */
103116 enum { /* current state of call */
103117 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
103118 @@ -431,7 +431,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
103119 */
103120 extern atomic_t rxrpc_n_skbs;
103121 extern __be32 rxrpc_epoch;
103122 -extern atomic_t rxrpc_debug_id;
103123 +extern atomic_unchecked_t rxrpc_debug_id;
103124 extern struct workqueue_struct *rxrpc_workqueue;
103125
103126 /*
103127 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
103128 index 87f7135..74d3703 100644
103129 --- a/net/rxrpc/ar-local.c
103130 +++ b/net/rxrpc/ar-local.c
103131 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
103132 spin_lock_init(&local->lock);
103133 rwlock_init(&local->services_lock);
103134 atomic_set(&local->usage, 1);
103135 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
103136 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
103137 memcpy(&local->srx, srx, sizeof(*srx));
103138 }
103139
103140 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
103141 index 0b4b9a7..966ffbb 100644
103142 --- a/net/rxrpc/ar-output.c
103143 +++ b/net/rxrpc/ar-output.c
103144 @@ -682,14 +682,14 @@ static int rxrpc_send_data(struct kiocb *iocb,
103145 memset(skb_put(skb, pad), 0, pad);
103146 }
103147
103148 - seq = atomic_inc_return(&call->sequence);
103149 + seq = atomic_inc_return_unchecked(&call->sequence);
103150
103151 sp->hdr.epoch = conn->epoch;
103152 sp->hdr.cid = call->cid;
103153 sp->hdr.callNumber = call->call_id;
103154 sp->hdr.seq = htonl(seq);
103155 sp->hdr.serial =
103156 - htonl(atomic_inc_return(&conn->serial));
103157 + htonl(atomic_inc_return_unchecked(&conn->serial));
103158 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
103159 sp->hdr.userStatus = 0;
103160 sp->hdr.securityIndex = conn->security_ix;
103161 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
103162 index bebaa43..2644591 100644
103163 --- a/net/rxrpc/ar-peer.c
103164 +++ b/net/rxrpc/ar-peer.c
103165 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
103166 INIT_LIST_HEAD(&peer->error_targets);
103167 spin_lock_init(&peer->lock);
103168 atomic_set(&peer->usage, 1);
103169 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
103170 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
103171 memcpy(&peer->srx, srx, sizeof(*srx));
103172
103173 rxrpc_assess_MTU_size(peer);
103174 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
103175 index 38047f7..9f48511 100644
103176 --- a/net/rxrpc/ar-proc.c
103177 +++ b/net/rxrpc/ar-proc.c
103178 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
103179 atomic_read(&conn->usage),
103180 rxrpc_conn_states[conn->state],
103181 key_serial(conn->key),
103182 - atomic_read(&conn->serial),
103183 - atomic_read(&conn->hi_serial));
103184 + atomic_read_unchecked(&conn->serial),
103185 + atomic_read_unchecked(&conn->hi_serial));
103186
103187 return 0;
103188 }
103189 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
103190 index 1976dec..aa70be5 100644
103191 --- a/net/rxrpc/ar-transport.c
103192 +++ b/net/rxrpc/ar-transport.c
103193 @@ -51,7 +51,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
103194 spin_lock_init(&trans->client_lock);
103195 rwlock_init(&trans->conn_lock);
103196 atomic_set(&trans->usage, 1);
103197 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
103198 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
103199
103200 if (peer->srx.transport.family == AF_INET) {
103201 switch (peer->srx.transport_type) {
103202 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
103203 index f226709..0e735a8 100644
103204 --- a/net/rxrpc/rxkad.c
103205 +++ b/net/rxrpc/rxkad.c
103206 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
103207
103208 len = iov[0].iov_len + iov[1].iov_len;
103209
103210 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
103211 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
103212 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
103213
103214 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
103215 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
103216
103217 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
103218
103219 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
103220 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
103221 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
103222
103223 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
103224 diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
103225 index e1543b0..7ce8bd0 100644
103226 --- a/net/sched/sch_generic.c
103227 +++ b/net/sched/sch_generic.c
103228 @@ -310,7 +310,7 @@ void netif_carrier_on(struct net_device *dev)
103229 if (test_and_clear_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
103230 if (dev->reg_state == NETREG_UNINITIALIZED)
103231 return;
103232 - atomic_inc(&dev->carrier_changes);
103233 + atomic_inc_unchecked(&dev->carrier_changes);
103234 linkwatch_fire_event(dev);
103235 if (netif_running(dev))
103236 __netdev_watchdog_up(dev);
103237 @@ -329,7 +329,7 @@ void netif_carrier_off(struct net_device *dev)
103238 if (!test_and_set_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
103239 if (dev->reg_state == NETREG_UNINITIALIZED)
103240 return;
103241 - atomic_inc(&dev->carrier_changes);
103242 + atomic_inc_unchecked(&dev->carrier_changes);
103243 linkwatch_fire_event(dev);
103244 }
103245 }
103246 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
103247 index 2b1738e..a9d0fc9 100644
103248 --- a/net/sctp/ipv6.c
103249 +++ b/net/sctp/ipv6.c
103250 @@ -966,7 +966,7 @@ static const struct inet6_protocol sctpv6_protocol = {
103251 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
103252 };
103253
103254 -static struct sctp_af sctp_af_inet6 = {
103255 +static struct sctp_af sctp_af_inet6 __read_only = {
103256 .sa_family = AF_INET6,
103257 .sctp_xmit = sctp_v6_xmit,
103258 .setsockopt = ipv6_setsockopt,
103259 @@ -998,7 +998,7 @@ static struct sctp_af sctp_af_inet6 = {
103260 #endif
103261 };
103262
103263 -static struct sctp_pf sctp_pf_inet6 = {
103264 +static struct sctp_pf sctp_pf_inet6 __read_only = {
103265 .event_msgname = sctp_inet6_event_msgname,
103266 .skb_msgname = sctp_inet6_skb_msgname,
103267 .af_supported = sctp_inet6_af_supported,
103268 @@ -1023,7 +1023,7 @@ void sctp_v6_pf_init(void)
103269
103270 void sctp_v6_pf_exit(void)
103271 {
103272 - list_del(&sctp_af_inet6.list);
103273 + pax_list_del(&sctp_af_inet6.list);
103274 }
103275
103276 /* Initialize IPv6 support and register with socket layer. */
103277 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
103278 index 44cbb54..4c5dce6 100644
103279 --- a/net/sctp/protocol.c
103280 +++ b/net/sctp/protocol.c
103281 @@ -836,8 +836,10 @@ int sctp_register_af(struct sctp_af *af)
103282 return 0;
103283 }
103284
103285 + pax_open_kernel();
103286 INIT_LIST_HEAD(&af->list);
103287 - list_add_tail(&af->list, &sctp_address_families);
103288 + pax_close_kernel();
103289 + pax_list_add_tail(&af->list, &sctp_address_families);
103290 return 1;
103291 }
103292
103293 @@ -967,7 +969,7 @@ static inline int sctp_v4_xmit(struct sk_buff *skb,
103294
103295 static struct sctp_af sctp_af_inet;
103296
103297 -static struct sctp_pf sctp_pf_inet = {
103298 +static struct sctp_pf sctp_pf_inet __read_only = {
103299 .event_msgname = sctp_inet_event_msgname,
103300 .skb_msgname = sctp_inet_skb_msgname,
103301 .af_supported = sctp_inet_af_supported,
103302 @@ -1039,7 +1041,7 @@ static const struct net_protocol sctp_protocol = {
103303 };
103304
103305 /* IPv4 address related functions. */
103306 -static struct sctp_af sctp_af_inet = {
103307 +static struct sctp_af sctp_af_inet __read_only = {
103308 .sa_family = AF_INET,
103309 .sctp_xmit = sctp_v4_xmit,
103310 .setsockopt = ip_setsockopt,
103311 @@ -1124,7 +1126,7 @@ static void sctp_v4_pf_init(void)
103312
103313 static void sctp_v4_pf_exit(void)
103314 {
103315 - list_del(&sctp_af_inet.list);
103316 + pax_list_del(&sctp_af_inet.list);
103317 }
103318
103319 static int sctp_v4_protosw_init(void)
103320 diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
103321 index fef2acd..c705c4f 100644
103322 --- a/net/sctp/sm_sideeffect.c
103323 +++ b/net/sctp/sm_sideeffect.c
103324 @@ -439,7 +439,7 @@ static void sctp_generate_sack_event(unsigned long data)
103325 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
103326 }
103327
103328 -sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
103329 +sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
103330 NULL,
103331 sctp_generate_t1_cookie_event,
103332 sctp_generate_t1_init_event,
103333 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
103334 index fee06b9..eabc613 100644
103335 --- a/net/sctp/socket.c
103336 +++ b/net/sctp/socket.c
103337 @@ -2175,11 +2175,13 @@ static int sctp_setsockopt_events(struct sock *sk, char __user *optval,
103338 {
103339 struct sctp_association *asoc;
103340 struct sctp_ulpevent *event;
103341 + struct sctp_event_subscribe subscribe;
103342
103343 if (optlen > sizeof(struct sctp_event_subscribe))
103344 return -EINVAL;
103345 - if (copy_from_user(&sctp_sk(sk)->subscribe, optval, optlen))
103346 + if (copy_from_user(&subscribe, optval, optlen))
103347 return -EFAULT;
103348 + sctp_sk(sk)->subscribe = subscribe;
103349
103350 /*
103351 * At the time when a user app subscribes to SCTP_SENDER_DRY_EVENT,
103352 @@ -4259,13 +4261,16 @@ static int sctp_getsockopt_disable_fragments(struct sock *sk, int len,
103353 static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
103354 int __user *optlen)
103355 {
103356 + struct sctp_event_subscribe subscribe;
103357 +
103358 if (len <= 0)
103359 return -EINVAL;
103360 if (len > sizeof(struct sctp_event_subscribe))
103361 len = sizeof(struct sctp_event_subscribe);
103362 if (put_user(len, optlen))
103363 return -EFAULT;
103364 - if (copy_to_user(optval, &sctp_sk(sk)->subscribe, len))
103365 + subscribe = sctp_sk(sk)->subscribe;
103366 + if (copy_to_user(optval, &subscribe, len))
103367 return -EFAULT;
103368 return 0;
103369 }
103370 @@ -4283,6 +4288,8 @@ static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
103371 */
103372 static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optval, int __user *optlen)
103373 {
103374 + __u32 autoclose;
103375 +
103376 /* Applicable to UDP-style socket only */
103377 if (sctp_style(sk, TCP))
103378 return -EOPNOTSUPP;
103379 @@ -4291,7 +4298,8 @@ static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optv
103380 len = sizeof(int);
103381 if (put_user(len, optlen))
103382 return -EFAULT;
103383 - if (copy_to_user(optval, &sctp_sk(sk)->autoclose, sizeof(int)))
103384 + autoclose = sctp_sk(sk)->autoclose;
103385 + if (copy_to_user(optval, &autoclose, sizeof(int)))
103386 return -EFAULT;
103387 return 0;
103388 }
103389 @@ -4666,12 +4674,15 @@ static int sctp_getsockopt_delayed_ack(struct sock *sk, int len,
103390 */
103391 static int sctp_getsockopt_initmsg(struct sock *sk, int len, char __user *optval, int __user *optlen)
103392 {
103393 + struct sctp_initmsg initmsg;
103394 +
103395 if (len < sizeof(struct sctp_initmsg))
103396 return -EINVAL;
103397 len = sizeof(struct sctp_initmsg);
103398 if (put_user(len, optlen))
103399 return -EFAULT;
103400 - if (copy_to_user(optval, &sctp_sk(sk)->initmsg, len))
103401 + initmsg = sctp_sk(sk)->initmsg;
103402 + if (copy_to_user(optval, &initmsg, len))
103403 return -EFAULT;
103404 return 0;
103405 }
103406 @@ -4712,6 +4723,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
103407 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
103408 if (space_left < addrlen)
103409 return -ENOMEM;
103410 + if (addrlen > sizeof(temp) || addrlen < 0)
103411 + return -EFAULT;
103412 if (copy_to_user(to, &temp, addrlen))
103413 return -EFAULT;
103414 to += addrlen;
103415 diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
103416 index dfa532f..1dcfb44 100644
103417 --- a/net/sctp/sysctl.c
103418 +++ b/net/sctp/sysctl.c
103419 @@ -307,7 +307,7 @@ static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
103420 loff_t *ppos)
103421 {
103422 struct net *net = current->nsproxy->net_ns;
103423 - struct ctl_table tbl;
103424 + ctl_table_no_const tbl;
103425 bool changed = false;
103426 char *none = "none";
103427 char tmp[8];
103428 @@ -355,7 +355,7 @@ static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
103429 struct net *net = current->nsproxy->net_ns;
103430 unsigned int min = *(unsigned int *) ctl->extra1;
103431 unsigned int max = *(unsigned int *) ctl->extra2;
103432 - struct ctl_table tbl;
103433 + ctl_table_no_const tbl;
103434 int ret, new_value;
103435
103436 memset(&tbl, 0, sizeof(struct ctl_table));
103437 @@ -384,7 +384,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
103438 struct net *net = current->nsproxy->net_ns;
103439 unsigned int min = *(unsigned int *) ctl->extra1;
103440 unsigned int max = *(unsigned int *) ctl->extra2;
103441 - struct ctl_table tbl;
103442 + ctl_table_no_const tbl;
103443 int ret, new_value;
103444
103445 memset(&tbl, 0, sizeof(struct ctl_table));
103446 @@ -411,7 +411,7 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
103447 loff_t *ppos)
103448 {
103449 struct net *net = current->nsproxy->net_ns;
103450 - struct ctl_table tbl;
103451 + ctl_table_no_const tbl;
103452 int new_value, ret;
103453
103454 memset(&tbl, 0, sizeof(struct ctl_table));
103455 @@ -438,7 +438,7 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
103456
103457 int sctp_sysctl_net_register(struct net *net)
103458 {
103459 - struct ctl_table *table = sctp_net_table;
103460 + ctl_table_no_const *table = NULL;
103461
103462 if (!net_eq(net, &init_net)) {
103463 int i;
103464 @@ -451,7 +451,10 @@ int sctp_sysctl_net_register(struct net *net)
103465 table[i].data += (char *)(&net->sctp) - (char *)&init_net.sctp;
103466 }
103467
103468 - net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", table);
103469 + if (!net_eq(net, &init_net))
103470 + net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", table);
103471 + else
103472 + net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", sctp_net_table);
103473 return 0;
103474 }
103475
103476 diff --git a/net/socket.c b/net/socket.c
103477 index abf56b2..b8998bc 100644
103478 --- a/net/socket.c
103479 +++ b/net/socket.c
103480 @@ -89,6 +89,7 @@
103481 #include <linux/magic.h>
103482 #include <linux/slab.h>
103483 #include <linux/xattr.h>
103484 +#include <linux/in.h>
103485
103486 #include <asm/uaccess.h>
103487 #include <asm/unistd.h>
103488 @@ -112,6 +113,8 @@ unsigned int sysctl_net_busy_read __read_mostly;
103489 unsigned int sysctl_net_busy_poll __read_mostly;
103490 #endif
103491
103492 +#include <linux/grsock.h>
103493 +
103494 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
103495 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
103496 unsigned long nr_segs, loff_t pos);
103497 @@ -163,7 +166,7 @@ static const struct file_operations socket_file_ops = {
103498 */
103499
103500 static DEFINE_SPINLOCK(net_family_lock);
103501 -static const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
103502 +const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
103503
103504 /*
103505 * Statistics counters of the socket lists
103506 @@ -329,7 +332,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
103507 &sockfs_dentry_operations, SOCKFS_MAGIC);
103508 }
103509
103510 -static struct vfsmount *sock_mnt __read_mostly;
103511 +struct vfsmount *sock_mnt __read_mostly;
103512
103513 static struct file_system_type sock_fs_type = {
103514 .name = "sockfs",
103515 @@ -1257,6 +1260,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
103516 return -EAFNOSUPPORT;
103517 if (type < 0 || type >= SOCK_MAX)
103518 return -EINVAL;
103519 + if (protocol < 0)
103520 + return -EINVAL;
103521
103522 /* Compatibility.
103523
103524 @@ -1277,6 +1282,20 @@ int __sock_create(struct net *net, int family, int type, int protocol,
103525 if (err)
103526 return err;
103527
103528 + if(!kern && !gr_search_socket(family, type, protocol)) {
103529 + if (rcu_access_pointer(net_families[family]) == NULL)
103530 + return -EAFNOSUPPORT;
103531 + else
103532 + return -EACCES;
103533 + }
103534 +
103535 + if (!kern && gr_handle_sock_all(family, type, protocol)) {
103536 + if (rcu_access_pointer(net_families[family]) == NULL)
103537 + return -EAFNOSUPPORT;
103538 + else
103539 + return -EACCES;
103540 + }
103541 +
103542 /*
103543 * Allocate the socket and allow the family to set things up. if
103544 * the protocol is 0, the family is instructed to select an appropriate
103545 @@ -1528,6 +1547,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
103546 if (sock) {
103547 err = move_addr_to_kernel(umyaddr, addrlen, &address);
103548 if (err >= 0) {
103549 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
103550 + err = -EACCES;
103551 + goto error;
103552 + }
103553 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
103554 + if (err)
103555 + goto error;
103556 +
103557 err = security_socket_bind(sock,
103558 (struct sockaddr *)&address,
103559 addrlen);
103560 @@ -1536,6 +1563,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
103561 (struct sockaddr *)
103562 &address, addrlen);
103563 }
103564 +error:
103565 fput_light(sock->file, fput_needed);
103566 }
103567 return err;
103568 @@ -1559,10 +1587,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
103569 if ((unsigned int)backlog > somaxconn)
103570 backlog = somaxconn;
103571
103572 + if (gr_handle_sock_server_other(sock->sk)) {
103573 + err = -EPERM;
103574 + goto error;
103575 + }
103576 +
103577 + err = gr_search_listen(sock);
103578 + if (err)
103579 + goto error;
103580 +
103581 err = security_socket_listen(sock, backlog);
103582 if (!err)
103583 err = sock->ops->listen(sock, backlog);
103584
103585 +error:
103586 fput_light(sock->file, fput_needed);
103587 }
103588 return err;
103589 @@ -1606,6 +1644,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
103590 newsock->type = sock->type;
103591 newsock->ops = sock->ops;
103592
103593 + if (gr_handle_sock_server_other(sock->sk)) {
103594 + err = -EPERM;
103595 + sock_release(newsock);
103596 + goto out_put;
103597 + }
103598 +
103599 + err = gr_search_accept(sock);
103600 + if (err) {
103601 + sock_release(newsock);
103602 + goto out_put;
103603 + }
103604 +
103605 /*
103606 * We don't need try_module_get here, as the listening socket (sock)
103607 * has the protocol module (sock->ops->owner) held.
103608 @@ -1651,6 +1701,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
103609 fd_install(newfd, newfile);
103610 err = newfd;
103611
103612 + gr_attach_curr_ip(newsock->sk);
103613 +
103614 out_put:
103615 fput_light(sock->file, fput_needed);
103616 out:
103617 @@ -1683,6 +1735,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
103618 int, addrlen)
103619 {
103620 struct socket *sock;
103621 + struct sockaddr *sck;
103622 struct sockaddr_storage address;
103623 int err, fput_needed;
103624
103625 @@ -1693,6 +1746,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
103626 if (err < 0)
103627 goto out_put;
103628
103629 + sck = (struct sockaddr *)&address;
103630 +
103631 + if (gr_handle_sock_client(sck)) {
103632 + err = -EACCES;
103633 + goto out_put;
103634 + }
103635 +
103636 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
103637 + if (err)
103638 + goto out_put;
103639 +
103640 err =
103641 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
103642 if (err)
103643 @@ -1774,6 +1838,8 @@ SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr __user *, usockaddr,
103644 * the protocol.
103645 */
103646
103647 +asmlinkage long sys_sendto(int, void __user *, size_t, unsigned, struct sockaddr __user *, int);
103648 +
103649 SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
103650 unsigned int, flags, struct sockaddr __user *, addr,
103651 int, addr_len)
103652 @@ -1840,7 +1906,7 @@ SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, size_t, size,
103653 struct socket *sock;
103654 struct iovec iov;
103655 struct msghdr msg;
103656 - struct sockaddr_storage address;
103657 + struct sockaddr_storage address = { };
103658 int err, err2;
103659 int fput_needed;
103660
103661 @@ -2066,7 +2132,7 @@ static int ___sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
103662 * checking falls down on this.
103663 */
103664 if (copy_from_user(ctl_buf,
103665 - (void __user __force *)msg_sys->msg_control,
103666 + (void __force_user *)msg_sys->msg_control,
103667 ctl_len))
103668 goto out_freectl;
103669 msg_sys->msg_control = ctl_buf;
103670 @@ -2217,7 +2283,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
103671 int err, total_len, len;
103672
103673 /* kernel mode address */
103674 - struct sockaddr_storage addr;
103675 + struct sockaddr_storage addr = { };
103676
103677 /* user mode address pointers */
103678 struct sockaddr __user *uaddr;
103679 @@ -2246,7 +2312,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
103680 /* Save the user-mode address (verify_iovec will change the
103681 * kernel msghdr to use the kernel address space)
103682 */
103683 - uaddr = (__force void __user *)msg_sys->msg_name;
103684 + uaddr = (void __force_user *)msg_sys->msg_name;
103685 uaddr_len = COMPAT_NAMELEN(msg);
103686 if (MSG_CMSG_COMPAT & flags)
103687 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
103688 @@ -2887,7 +2953,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
103689 ifr = compat_alloc_user_space(buf_size);
103690 rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
103691
103692 - if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
103693 + if (copy_in_user(ifr->ifr_name, ifr32->ifr_name, IFNAMSIZ))
103694 return -EFAULT;
103695
103696 if (put_user(convert_in ? rxnfc : compat_ptr(data),
103697 @@ -2998,7 +3064,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
103698 old_fs = get_fs();
103699 set_fs(KERNEL_DS);
103700 err = dev_ioctl(net, cmd,
103701 - (struct ifreq __user __force *) &kifr);
103702 + (struct ifreq __force_user *) &kifr);
103703 set_fs(old_fs);
103704
103705 return err;
103706 @@ -3091,7 +3157,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
103707
103708 old_fs = get_fs();
103709 set_fs(KERNEL_DS);
103710 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
103711 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
103712 set_fs(old_fs);
103713
103714 if (cmd == SIOCGIFMAP && !err) {
103715 @@ -3175,7 +3241,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
103716 ret |= get_user(rtdev, &(ur4->rt_dev));
103717 if (rtdev) {
103718 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
103719 - r4.rt_dev = (char __user __force *)devname;
103720 + r4.rt_dev = (char __force_user *)devname;
103721 devname[15] = 0;
103722 } else
103723 r4.rt_dev = NULL;
103724 @@ -3402,8 +3468,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
103725 int __user *uoptlen;
103726 int err;
103727
103728 - uoptval = (char __user __force *) optval;
103729 - uoptlen = (int __user __force *) optlen;
103730 + uoptval = (char __force_user *) optval;
103731 + uoptlen = (int __force_user *) optlen;
103732
103733 set_fs(KERNEL_DS);
103734 if (level == SOL_SOCKET)
103735 @@ -3423,7 +3489,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
103736 char __user *uoptval;
103737 int err;
103738
103739 - uoptval = (char __user __force *) optval;
103740 + uoptval = (char __force_user *) optval;
103741
103742 set_fs(KERNEL_DS);
103743 if (level == SOL_SOCKET)
103744 diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
103745 index 0f73f45..a96aa52 100644
103746 --- a/net/sunrpc/auth_gss/svcauth_gss.c
103747 +++ b/net/sunrpc/auth_gss/svcauth_gss.c
103748 @@ -1140,7 +1140,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
103749 uint64_t *handle)
103750 {
103751 struct rsc rsci, *rscp = NULL;
103752 - static atomic64_t ctxhctr;
103753 + static atomic64_unchecked_t ctxhctr = ATOMIC64_INIT(0);
103754 long long ctxh;
103755 struct gss_api_mech *gm = NULL;
103756 time_t expiry;
103757 @@ -1151,7 +1151,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
103758 status = -ENOMEM;
103759 /* the handle needs to be just a unique id,
103760 * use a static counter */
103761 - ctxh = atomic64_inc_return(&ctxhctr);
103762 + ctxh = atomic64_inc_return_unchecked(&ctxhctr);
103763
103764 /* make a copy for the caller */
103765 *handle = ctxh;
103766 diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
103767 index ae333c1..18521f0 100644
103768 --- a/net/sunrpc/cache.c
103769 +++ b/net/sunrpc/cache.c
103770 @@ -1609,7 +1609,7 @@ static int create_cache_proc_entries(struct cache_detail *cd, struct net *net)
103771 struct sunrpc_net *sn;
103772
103773 sn = net_generic(net, sunrpc_net_id);
103774 - cd->u.procfs.proc_ent = proc_mkdir(cd->name, sn->proc_net_rpc);
103775 + cd->u.procfs.proc_ent = proc_mkdir_restrict(cd->name, sn->proc_net_rpc);
103776 if (cd->u.procfs.proc_ent == NULL)
103777 goto out_nomem;
103778 cd->u.procfs.channel_ent = NULL;
103779 diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
103780 index 2e6ab10..3170800 100644
103781 --- a/net/sunrpc/clnt.c
103782 +++ b/net/sunrpc/clnt.c
103783 @@ -1425,7 +1425,9 @@ call_start(struct rpc_task *task)
103784 (RPC_IS_ASYNC(task) ? "async" : "sync"));
103785
103786 /* Increment call count */
103787 - task->tk_msg.rpc_proc->p_count++;
103788 + pax_open_kernel();
103789 + (*(unsigned int *)&task->tk_msg.rpc_proc->p_count)++;
103790 + pax_close_kernel();
103791 clnt->cl_stats->rpccnt++;
103792 task->tk_action = call_reserve;
103793 }
103794 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
103795 index 25578af..a29298d 100644
103796 --- a/net/sunrpc/sched.c
103797 +++ b/net/sunrpc/sched.c
103798 @@ -261,9 +261,9 @@ static int rpc_wait_bit_killable(void *word)
103799 #if defined(RPC_DEBUG) || defined(RPC_TRACEPOINTS)
103800 static void rpc_task_set_debuginfo(struct rpc_task *task)
103801 {
103802 - static atomic_t rpc_pid;
103803 + static atomic_unchecked_t rpc_pid;
103804
103805 - task->tk_pid = atomic_inc_return(&rpc_pid);
103806 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
103807 }
103808 #else
103809 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
103810 diff --git a/net/sunrpc/stats.c b/net/sunrpc/stats.c
103811 index 5453049..465669a 100644
103812 --- a/net/sunrpc/stats.c
103813 +++ b/net/sunrpc/stats.c
103814 @@ -267,7 +267,7 @@ int rpc_proc_init(struct net *net)
103815
103816 dprintk("RPC: registering /proc/net/rpc\n");
103817 sn = net_generic(net, sunrpc_net_id);
103818 - sn->proc_net_rpc = proc_mkdir("rpc", net->proc_net);
103819 + sn->proc_net_rpc = proc_mkdir_restrict("rpc", net->proc_net);
103820 if (sn->proc_net_rpc == NULL)
103821 return -ENOMEM;
103822
103823 diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
103824 index 5de6801..b4e330d 100644
103825 --- a/net/sunrpc/svc.c
103826 +++ b/net/sunrpc/svc.c
103827 @@ -1167,7 +1167,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
103828 svc_putnl(resv, RPC_SUCCESS);
103829
103830 /* Bump per-procedure stats counter */
103831 - procp->pc_count++;
103832 + pax_open_kernel();
103833 + (*(unsigned int *)&procp->pc_count)++;
103834 + pax_close_kernel();
103835
103836 /* Initialize storage for argp and resp */
103837 memset(rqstp->rq_argp, 0, procp->pc_argsize);
103838 diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
103839 index 621ca7b..59421dd 100644
103840 --- a/net/sunrpc/svcauth_unix.c
103841 +++ b/net/sunrpc/svcauth_unix.c
103842 @@ -414,7 +414,7 @@ struct unix_gid {
103843 struct group_info *gi;
103844 };
103845
103846 -static int unix_gid_hash(kuid_t uid)
103847 +static int __intentional_overflow(-1) unix_gid_hash(kuid_t uid)
103848 {
103849 return hash_long(from_kuid(&init_user_ns, uid), GID_HASHBITS);
103850 }
103851 @@ -470,7 +470,7 @@ static void unix_gid_request(struct cache_detail *cd,
103852 (*bpp)[-1] = '\n';
103853 }
103854
103855 -static struct unix_gid *unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
103856 +static struct unix_gid * __intentional_overflow(-1) unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
103857
103858 static int unix_gid_parse(struct cache_detail *cd,
103859 char *mesg, int mlen)
103860 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
103861 index c1b6270..05089c1 100644
103862 --- a/net/sunrpc/xprtrdma/svc_rdma.c
103863 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
103864 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
103865 static unsigned int min_max_inline = 4096;
103866 static unsigned int max_max_inline = 65536;
103867
103868 -atomic_t rdma_stat_recv;
103869 -atomic_t rdma_stat_read;
103870 -atomic_t rdma_stat_write;
103871 -atomic_t rdma_stat_sq_starve;
103872 -atomic_t rdma_stat_rq_starve;
103873 -atomic_t rdma_stat_rq_poll;
103874 -atomic_t rdma_stat_rq_prod;
103875 -atomic_t rdma_stat_sq_poll;
103876 -atomic_t rdma_stat_sq_prod;
103877 +atomic_unchecked_t rdma_stat_recv;
103878 +atomic_unchecked_t rdma_stat_read;
103879 +atomic_unchecked_t rdma_stat_write;
103880 +atomic_unchecked_t rdma_stat_sq_starve;
103881 +atomic_unchecked_t rdma_stat_rq_starve;
103882 +atomic_unchecked_t rdma_stat_rq_poll;
103883 +atomic_unchecked_t rdma_stat_rq_prod;
103884 +atomic_unchecked_t rdma_stat_sq_poll;
103885 +atomic_unchecked_t rdma_stat_sq_prod;
103886
103887 /* Temporary NFS request map and context caches */
103888 struct kmem_cache *svc_rdma_map_cachep;
103889 @@ -110,7 +110,7 @@ static int read_reset_stat(struct ctl_table *table, int write,
103890 len -= *ppos;
103891 if (len > *lenp)
103892 len = *lenp;
103893 - if (len && copy_to_user(buffer, str_buf, len))
103894 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
103895 return -EFAULT;
103896 *lenp = len;
103897 *ppos += len;
103898 @@ -151,63 +151,63 @@ static struct ctl_table svcrdma_parm_table[] = {
103899 {
103900 .procname = "rdma_stat_read",
103901 .data = &rdma_stat_read,
103902 - .maxlen = sizeof(atomic_t),
103903 + .maxlen = sizeof(atomic_unchecked_t),
103904 .mode = 0644,
103905 .proc_handler = read_reset_stat,
103906 },
103907 {
103908 .procname = "rdma_stat_recv",
103909 .data = &rdma_stat_recv,
103910 - .maxlen = sizeof(atomic_t),
103911 + .maxlen = sizeof(atomic_unchecked_t),
103912 .mode = 0644,
103913 .proc_handler = read_reset_stat,
103914 },
103915 {
103916 .procname = "rdma_stat_write",
103917 .data = &rdma_stat_write,
103918 - .maxlen = sizeof(atomic_t),
103919 + .maxlen = sizeof(atomic_unchecked_t),
103920 .mode = 0644,
103921 .proc_handler = read_reset_stat,
103922 },
103923 {
103924 .procname = "rdma_stat_sq_starve",
103925 .data = &rdma_stat_sq_starve,
103926 - .maxlen = sizeof(atomic_t),
103927 + .maxlen = sizeof(atomic_unchecked_t),
103928 .mode = 0644,
103929 .proc_handler = read_reset_stat,
103930 },
103931 {
103932 .procname = "rdma_stat_rq_starve",
103933 .data = &rdma_stat_rq_starve,
103934 - .maxlen = sizeof(atomic_t),
103935 + .maxlen = sizeof(atomic_unchecked_t),
103936 .mode = 0644,
103937 .proc_handler = read_reset_stat,
103938 },
103939 {
103940 .procname = "rdma_stat_rq_poll",
103941 .data = &rdma_stat_rq_poll,
103942 - .maxlen = sizeof(atomic_t),
103943 + .maxlen = sizeof(atomic_unchecked_t),
103944 .mode = 0644,
103945 .proc_handler = read_reset_stat,
103946 },
103947 {
103948 .procname = "rdma_stat_rq_prod",
103949 .data = &rdma_stat_rq_prod,
103950 - .maxlen = sizeof(atomic_t),
103951 + .maxlen = sizeof(atomic_unchecked_t),
103952 .mode = 0644,
103953 .proc_handler = read_reset_stat,
103954 },
103955 {
103956 .procname = "rdma_stat_sq_poll",
103957 .data = &rdma_stat_sq_poll,
103958 - .maxlen = sizeof(atomic_t),
103959 + .maxlen = sizeof(atomic_unchecked_t),
103960 .mode = 0644,
103961 .proc_handler = read_reset_stat,
103962 },
103963 {
103964 .procname = "rdma_stat_sq_prod",
103965 .data = &rdma_stat_sq_prod,
103966 - .maxlen = sizeof(atomic_t),
103967 + .maxlen = sizeof(atomic_unchecked_t),
103968 .mode = 0644,
103969 .proc_handler = read_reset_stat,
103970 },
103971 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
103972 index 8d904e4..b2fc727 100644
103973 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
103974 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
103975 @@ -504,7 +504,7 @@ next_sge:
103976 svc_rdma_put_context(ctxt, 0);
103977 goto out;
103978 }
103979 - atomic_inc(&rdma_stat_read);
103980 + atomic_inc_unchecked(&rdma_stat_read);
103981
103982 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
103983 chl_map->ch[ch_no].count -= read_wr.num_sge;
103984 @@ -607,7 +607,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
103985 dto_q);
103986 list_del_init(&ctxt->dto_q);
103987 } else {
103988 - atomic_inc(&rdma_stat_rq_starve);
103989 + atomic_inc_unchecked(&rdma_stat_rq_starve);
103990 clear_bit(XPT_DATA, &xprt->xpt_flags);
103991 ctxt = NULL;
103992 }
103993 @@ -627,7 +627,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
103994 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
103995 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
103996 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
103997 - atomic_inc(&rdma_stat_recv);
103998 + atomic_inc_unchecked(&rdma_stat_recv);
103999
104000 /* Build up the XDR from the receive buffers. */
104001 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
104002 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
104003 index 7e024a5..17f13d3 100644
104004 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
104005 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
104006 @@ -363,7 +363,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
104007 write_wr.wr.rdma.remote_addr = to;
104008
104009 /* Post It */
104010 - atomic_inc(&rdma_stat_write);
104011 + atomic_inc_unchecked(&rdma_stat_write);
104012 if (svc_rdma_send(xprt, &write_wr))
104013 goto err;
104014 return 0;
104015 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
104016 index 25688fa..dc72003 100644
104017 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
104018 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
104019 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
104020 return;
104021
104022 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
104023 - atomic_inc(&rdma_stat_rq_poll);
104024 + atomic_inc_unchecked(&rdma_stat_rq_poll);
104025
104026 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
104027 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
104028 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
104029 }
104030
104031 if (ctxt)
104032 - atomic_inc(&rdma_stat_rq_prod);
104033 + atomic_inc_unchecked(&rdma_stat_rq_prod);
104034
104035 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
104036 /*
104037 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
104038 return;
104039
104040 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
104041 - atomic_inc(&rdma_stat_sq_poll);
104042 + atomic_inc_unchecked(&rdma_stat_sq_poll);
104043 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
104044 if (wc.status != IB_WC_SUCCESS)
104045 /* Close the transport */
104046 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
104047 }
104048
104049 if (ctxt)
104050 - atomic_inc(&rdma_stat_sq_prod);
104051 + atomic_inc_unchecked(&rdma_stat_sq_prod);
104052 }
104053
104054 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
104055 @@ -1261,7 +1261,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
104056 spin_lock_bh(&xprt->sc_lock);
104057 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
104058 spin_unlock_bh(&xprt->sc_lock);
104059 - atomic_inc(&rdma_stat_sq_starve);
104060 + atomic_inc_unchecked(&rdma_stat_sq_starve);
104061
104062 /* See if we can opportunistically reap SQ WR to make room */
104063 sq_cq_reap(xprt);
104064 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
104065 index e7000be..e3b0ba7 100644
104066 --- a/net/sysctl_net.c
104067 +++ b/net/sysctl_net.c
104068 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head,
104069 kgid_t root_gid = make_kgid(net->user_ns, 0);
104070
104071 /* Allow network administrator to have same access as root. */
104072 - if (ns_capable(net->user_ns, CAP_NET_ADMIN) ||
104073 + if (ns_capable_nolog(net->user_ns, CAP_NET_ADMIN) ||
104074 uid_eq(root_uid, current_euid())) {
104075 int mode = (table->mode >> 6) & 7;
104076 return (mode << 6) | (mode << 3) | mode;
104077 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
104078 index 6424372..afd36e9 100644
104079 --- a/net/tipc/subscr.c
104080 +++ b/net/tipc/subscr.c
104081 @@ -97,7 +97,7 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower,
104082 struct tipc_subscriber *subscriber = sub->subscriber;
104083 struct kvec msg_sect;
104084
104085 - msg_sect.iov_base = (void *)&sub->evt;
104086 + msg_sect.iov_base = &sub->evt;
104087 msg_sect.iov_len = sizeof(struct tipc_event);
104088 sub->evt.event = htohl(event, sub->swap);
104089 sub->evt.found_lower = htohl(found_lower, sub->swap);
104090 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
104091 index bb7e8ba..9f444c6 100644
104092 --- a/net/unix/af_unix.c
104093 +++ b/net/unix/af_unix.c
104094 @@ -791,6 +791,12 @@ static struct sock *unix_find_other(struct net *net,
104095 err = -ECONNREFUSED;
104096 if (!S_ISSOCK(inode->i_mode))
104097 goto put_fail;
104098 +
104099 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
104100 + err = -EACCES;
104101 + goto put_fail;
104102 + }
104103 +
104104 u = unix_find_socket_byinode(inode);
104105 if (!u)
104106 goto put_fail;
104107 @@ -811,6 +817,13 @@ static struct sock *unix_find_other(struct net *net,
104108 if (u) {
104109 struct dentry *dentry;
104110 dentry = unix_sk(u)->path.dentry;
104111 +
104112 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
104113 + err = -EPERM;
104114 + sock_put(u);
104115 + goto fail;
104116 + }
104117 +
104118 if (dentry)
104119 touch_atime(&unix_sk(u)->path);
104120 } else
104121 @@ -844,12 +857,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
104122 */
104123 err = security_path_mknod(&path, dentry, mode, 0);
104124 if (!err) {
104125 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
104126 + err = -EACCES;
104127 + goto out;
104128 + }
104129 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
104130 if (!err) {
104131 res->mnt = mntget(path.mnt);
104132 res->dentry = dget(dentry);
104133 + gr_handle_create(dentry, path.mnt);
104134 }
104135 }
104136 +out:
104137 done_path_create(&path, dentry);
104138 return err;
104139 }
104140 @@ -2344,9 +2363,13 @@ static int unix_seq_show(struct seq_file *seq, void *v)
104141 seq_puts(seq, "Num RefCount Protocol Flags Type St "
104142 "Inode Path\n");
104143 else {
104144 - struct sock *s = v;
104145 + struct sock *s = v, *peer;
104146 struct unix_sock *u = unix_sk(s);
104147 unix_state_lock(s);
104148 + peer = unix_peer(s);
104149 + unix_state_unlock(s);
104150 +
104151 + unix_state_double_lock(s, peer);
104152
104153 seq_printf(seq, "%pK: %08X %08X %08X %04X %02X %5lu",
104154 s,
104155 @@ -2373,8 +2396,10 @@ static int unix_seq_show(struct seq_file *seq, void *v)
104156 }
104157 for ( ; i < len; i++)
104158 seq_putc(seq, u->addr->name->sun_path[i]);
104159 - }
104160 - unix_state_unlock(s);
104161 + } else if (peer)
104162 + seq_printf(seq, " P%lu", sock_i_ino(peer));
104163 +
104164 + unix_state_double_unlock(s, peer);
104165 seq_putc(seq, '\n');
104166 }
104167
104168 diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
104169 index b3d5150..ff3a837 100644
104170 --- a/net/unix/sysctl_net_unix.c
104171 +++ b/net/unix/sysctl_net_unix.c
104172 @@ -28,7 +28,7 @@ static struct ctl_table unix_table[] = {
104173
104174 int __net_init unix_sysctl_register(struct net *net)
104175 {
104176 - struct ctl_table *table;
104177 + ctl_table_no_const *table;
104178
104179 table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
104180 if (table == NULL)
104181 diff --git a/net/vmw_vsock/vmci_transport_notify.c b/net/vmw_vsock/vmci_transport_notify.c
104182 index 9b7f207..2596621 100644
104183 --- a/net/vmw_vsock/vmci_transport_notify.c
104184 +++ b/net/vmw_vsock/vmci_transport_notify.c
104185 @@ -662,19 +662,19 @@ static void vmci_transport_notify_pkt_process_negotiate(struct sock *sk)
104186
104187 /* Socket control packet based operations. */
104188 struct vmci_transport_notify_ops vmci_transport_notify_pkt_ops = {
104189 - vmci_transport_notify_pkt_socket_init,
104190 - vmci_transport_notify_pkt_socket_destruct,
104191 - vmci_transport_notify_pkt_poll_in,
104192 - vmci_transport_notify_pkt_poll_out,
104193 - vmci_transport_notify_pkt_handle_pkt,
104194 - vmci_transport_notify_pkt_recv_init,
104195 - vmci_transport_notify_pkt_recv_pre_block,
104196 - vmci_transport_notify_pkt_recv_pre_dequeue,
104197 - vmci_transport_notify_pkt_recv_post_dequeue,
104198 - vmci_transport_notify_pkt_send_init,
104199 - vmci_transport_notify_pkt_send_pre_block,
104200 - vmci_transport_notify_pkt_send_pre_enqueue,
104201 - vmci_transport_notify_pkt_send_post_enqueue,
104202 - vmci_transport_notify_pkt_process_request,
104203 - vmci_transport_notify_pkt_process_negotiate,
104204 + .socket_init = vmci_transport_notify_pkt_socket_init,
104205 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
104206 + .poll_in = vmci_transport_notify_pkt_poll_in,
104207 + .poll_out = vmci_transport_notify_pkt_poll_out,
104208 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
104209 + .recv_init = vmci_transport_notify_pkt_recv_init,
104210 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
104211 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
104212 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
104213 + .send_init = vmci_transport_notify_pkt_send_init,
104214 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
104215 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
104216 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
104217 + .process_request = vmci_transport_notify_pkt_process_request,
104218 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
104219 };
104220 diff --git a/net/vmw_vsock/vmci_transport_notify_qstate.c b/net/vmw_vsock/vmci_transport_notify_qstate.c
104221 index dc9c792..3089de0 100644
104222 --- a/net/vmw_vsock/vmci_transport_notify_qstate.c
104223 +++ b/net/vmw_vsock/vmci_transport_notify_qstate.c
104224 @@ -420,19 +420,19 @@ vmci_transport_notify_pkt_send_pre_enqueue(
104225
104226 /* Socket always on control packet based operations. */
104227 struct vmci_transport_notify_ops vmci_transport_notify_pkt_q_state_ops = {
104228 - vmci_transport_notify_pkt_socket_init,
104229 - vmci_transport_notify_pkt_socket_destruct,
104230 - vmci_transport_notify_pkt_poll_in,
104231 - vmci_transport_notify_pkt_poll_out,
104232 - vmci_transport_notify_pkt_handle_pkt,
104233 - vmci_transport_notify_pkt_recv_init,
104234 - vmci_transport_notify_pkt_recv_pre_block,
104235 - vmci_transport_notify_pkt_recv_pre_dequeue,
104236 - vmci_transport_notify_pkt_recv_post_dequeue,
104237 - vmci_transport_notify_pkt_send_init,
104238 - vmci_transport_notify_pkt_send_pre_block,
104239 - vmci_transport_notify_pkt_send_pre_enqueue,
104240 - vmci_transport_notify_pkt_send_post_enqueue,
104241 - vmci_transport_notify_pkt_process_request,
104242 - vmci_transport_notify_pkt_process_negotiate,
104243 + .socket_init = vmci_transport_notify_pkt_socket_init,
104244 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
104245 + .poll_in = vmci_transport_notify_pkt_poll_in,
104246 + .poll_out = vmci_transport_notify_pkt_poll_out,
104247 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
104248 + .recv_init = vmci_transport_notify_pkt_recv_init,
104249 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
104250 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
104251 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
104252 + .send_init = vmci_transport_notify_pkt_send_init,
104253 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
104254 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
104255 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
104256 + .process_request = vmci_transport_notify_pkt_process_request,
104257 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
104258 };
104259 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
104260 index c8717c1..08539f5 100644
104261 --- a/net/wireless/wext-core.c
104262 +++ b/net/wireless/wext-core.c
104263 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
104264 */
104265
104266 /* Support for very large requests */
104267 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
104268 - (user_length > descr->max_tokens)) {
104269 + if (user_length > descr->max_tokens) {
104270 /* Allow userspace to GET more than max so
104271 * we can support any size GET requests.
104272 * There is still a limit : -ENOMEM.
104273 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
104274 }
104275 }
104276
104277 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
104278 - /*
104279 - * If this is a GET, but not NOMAX, it means that the extra
104280 - * data is not bounded by userspace, but by max_tokens. Thus
104281 - * set the length to max_tokens. This matches the extra data
104282 - * allocation.
104283 - * The driver should fill it with the number of tokens it
104284 - * provided, and it may check iwp->length rather than having
104285 - * knowledge of max_tokens. If the driver doesn't change the
104286 - * iwp->length, this ioctl just copies back max_token tokens
104287 - * filled with zeroes. Hopefully the driver isn't claiming
104288 - * them to be valid data.
104289 - */
104290 - iwp->length = descr->max_tokens;
104291 - }
104292 -
104293 err = handler(dev, info, (union iwreq_data *) iwp, extra);
104294
104295 iwp->length += essid_compat;
104296 diff --git a/net/x25/sysctl_net_x25.c b/net/x25/sysctl_net_x25.c
104297 index 4323952..a06dfe1 100644
104298 --- a/net/x25/sysctl_net_x25.c
104299 +++ b/net/x25/sysctl_net_x25.c
104300 @@ -70,7 +70,7 @@ static struct ctl_table x25_table[] = {
104301 .mode = 0644,
104302 .proc_handler = proc_dointvec,
104303 },
104304 - { 0, },
104305 + { },
104306 };
104307
104308 void __init x25_register_sysctl(void)
104309 diff --git a/net/x25/x25_proc.c b/net/x25/x25_proc.c
104310 index 0917f04..f4e3d8c 100644
104311 --- a/net/x25/x25_proc.c
104312 +++ b/net/x25/x25_proc.c
104313 @@ -209,7 +209,7 @@ static const struct file_operations x25_seq_forward_fops = {
104314
104315 int __init x25_proc_init(void)
104316 {
104317 - if (!proc_mkdir("x25", init_net.proc_net))
104318 + if (!proc_mkdir_restrict("x25", init_net.proc_net))
104319 return -ENOMEM;
104320
104321 if (!proc_create("x25/route", S_IRUGO, init_net.proc_net,
104322 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
104323 index ed60843..311e7c7 100644
104324 --- a/net/xfrm/xfrm_policy.c
104325 +++ b/net/xfrm/xfrm_policy.c
104326 @@ -325,7 +325,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
104327 {
104328 policy->walk.dead = 1;
104329
104330 - atomic_inc(&policy->genid);
104331 + atomic_inc_unchecked(&policy->genid);
104332
104333 if (del_timer(&policy->polq.hold_timer))
104334 xfrm_pol_put(policy);
104335 @@ -659,7 +659,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
104336 hlist_add_head(&policy->bydst, chain);
104337 xfrm_pol_hold(policy);
104338 net->xfrm.policy_count[dir]++;
104339 - atomic_inc(&net->xfrm.flow_cache_genid);
104340 + atomic_inc_unchecked(&net->xfrm.flow_cache_genid);
104341
104342 /* After previous checking, family can either be AF_INET or AF_INET6 */
104343 if (policy->family == AF_INET)
104344 @@ -1759,7 +1759,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
104345
104346 xdst->num_pols = num_pols;
104347 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy *) * num_pols);
104348 - xdst->policy_genid = atomic_read(&pols[0]->genid);
104349 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
104350
104351 return xdst;
104352 }
104353 @@ -2548,10 +2548,11 @@ void xfrm_garbage_collect(struct net *net)
104354 }
104355 EXPORT_SYMBOL(xfrm_garbage_collect);
104356
104357 -static void xfrm_garbage_collect_deferred(struct net *net)
104358 +void xfrm_garbage_collect_deferred(struct net *net)
104359 {
104360 flow_cache_flush_deferred(net);
104361 }
104362 +EXPORT_SYMBOL(xfrm_garbage_collect_deferred);
104363
104364 static void xfrm_init_pmtu(struct dst_entry *dst)
104365 {
104366 @@ -2601,7 +2602,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
104367 if (xdst->xfrm_genid != dst->xfrm->genid)
104368 return 0;
104369 if (xdst->num_pols > 0 &&
104370 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
104371 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
104372 return 0;
104373
104374 mtu = dst_mtu(dst->child);
104375 @@ -2689,8 +2690,6 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
104376 dst_ops->link_failure = xfrm_link_failure;
104377 if (likely(dst_ops->neigh_lookup == NULL))
104378 dst_ops->neigh_lookup = xfrm_neigh_lookup;
104379 - if (likely(afinfo->garbage_collect == NULL))
104380 - afinfo->garbage_collect = xfrm_garbage_collect_deferred;
104381 rcu_assign_pointer(xfrm_policy_afinfo[afinfo->family], afinfo);
104382 }
104383 spin_unlock(&xfrm_policy_afinfo_lock);
104384 @@ -2744,7 +2743,6 @@ int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo)
104385 dst_ops->check = NULL;
104386 dst_ops->negative_advice = NULL;
104387 dst_ops->link_failure = NULL;
104388 - afinfo->garbage_collect = NULL;
104389 }
104390 return err;
104391 }
104392 @@ -3139,7 +3137,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
104393 sizeof(pol->xfrm_vec[i].saddr));
104394 pol->xfrm_vec[i].encap_family = mp->new_family;
104395 /* flush bundles */
104396 - atomic_inc(&pol->genid);
104397 + atomic_inc_unchecked(&pol->genid);
104398 }
104399 }
104400
104401 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
104402 index 8e9c781..3972135 100644
104403 --- a/net/xfrm/xfrm_state.c
104404 +++ b/net/xfrm/xfrm_state.c
104405 @@ -173,12 +173,14 @@ int xfrm_register_type(const struct xfrm_type *type, unsigned short family)
104406
104407 if (unlikely(afinfo == NULL))
104408 return -EAFNOSUPPORT;
104409 - typemap = afinfo->type_map;
104410 + typemap = (const struct xfrm_type **)afinfo->type_map;
104411 spin_lock_bh(&xfrm_type_lock);
104412
104413 - if (likely(typemap[type->proto] == NULL))
104414 + if (likely(typemap[type->proto] == NULL)) {
104415 + pax_open_kernel();
104416 typemap[type->proto] = type;
104417 - else
104418 + pax_close_kernel();
104419 + } else
104420 err = -EEXIST;
104421 spin_unlock_bh(&xfrm_type_lock);
104422 xfrm_state_put_afinfo(afinfo);
104423 @@ -194,13 +196,16 @@ int xfrm_unregister_type(const struct xfrm_type *type, unsigned short family)
104424
104425 if (unlikely(afinfo == NULL))
104426 return -EAFNOSUPPORT;
104427 - typemap = afinfo->type_map;
104428 + typemap = (const struct xfrm_type **)afinfo->type_map;
104429 spin_lock_bh(&xfrm_type_lock);
104430
104431 if (unlikely(typemap[type->proto] != type))
104432 err = -ENOENT;
104433 - else
104434 + else {
104435 + pax_open_kernel();
104436 typemap[type->proto] = NULL;
104437 + pax_close_kernel();
104438 + }
104439 spin_unlock_bh(&xfrm_type_lock);
104440 xfrm_state_put_afinfo(afinfo);
104441 return err;
104442 @@ -210,7 +215,6 @@ EXPORT_SYMBOL(xfrm_unregister_type);
104443 static const struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
104444 {
104445 struct xfrm_state_afinfo *afinfo;
104446 - const struct xfrm_type **typemap;
104447 const struct xfrm_type *type;
104448 int modload_attempted = 0;
104449
104450 @@ -218,9 +222,8 @@ retry:
104451 afinfo = xfrm_state_get_afinfo(family);
104452 if (unlikely(afinfo == NULL))
104453 return NULL;
104454 - typemap = afinfo->type_map;
104455
104456 - type = typemap[proto];
104457 + type = afinfo->type_map[proto];
104458 if (unlikely(type && !try_module_get(type->owner)))
104459 type = NULL;
104460 if (!type && !modload_attempted) {
104461 @@ -254,7 +257,7 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
104462 return -EAFNOSUPPORT;
104463
104464 err = -EEXIST;
104465 - modemap = afinfo->mode_map;
104466 + modemap = (struct xfrm_mode **)afinfo->mode_map;
104467 spin_lock_bh(&xfrm_mode_lock);
104468 if (modemap[mode->encap])
104469 goto out;
104470 @@ -263,8 +266,10 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
104471 if (!try_module_get(afinfo->owner))
104472 goto out;
104473
104474 - mode->afinfo = afinfo;
104475 + pax_open_kernel();
104476 + *(const void **)&mode->afinfo = afinfo;
104477 modemap[mode->encap] = mode;
104478 + pax_close_kernel();
104479 err = 0;
104480
104481 out:
104482 @@ -288,10 +293,12 @@ int xfrm_unregister_mode(struct xfrm_mode *mode, int family)
104483 return -EAFNOSUPPORT;
104484
104485 err = -ENOENT;
104486 - modemap = afinfo->mode_map;
104487 + modemap = (struct xfrm_mode **)afinfo->mode_map;
104488 spin_lock_bh(&xfrm_mode_lock);
104489 if (likely(modemap[mode->encap] == mode)) {
104490 + pax_open_kernel();
104491 modemap[mode->encap] = NULL;
104492 + pax_close_kernel();
104493 module_put(mode->afinfo->owner);
104494 err = 0;
104495 }
104496 @@ -1519,10 +1526,10 @@ EXPORT_SYMBOL(xfrm_find_acq_byseq);
104497 u32 xfrm_get_acqseq(void)
104498 {
104499 u32 res;
104500 - static atomic_t acqseq;
104501 + static atomic_unchecked_t acqseq;
104502
104503 do {
104504 - res = atomic_inc_return(&acqseq);
104505 + res = atomic_inc_return_unchecked(&acqseq);
104506 } while (!res);
104507
104508 return res;
104509 diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c
104510 index 05a6e3d..6716ec9 100644
104511 --- a/net/xfrm/xfrm_sysctl.c
104512 +++ b/net/xfrm/xfrm_sysctl.c
104513 @@ -42,7 +42,7 @@ static struct ctl_table xfrm_table[] = {
104514
104515 int __net_init xfrm_sysctl_init(struct net *net)
104516 {
104517 - struct ctl_table *table;
104518 + ctl_table_no_const *table;
104519
104520 __xfrm_sysctl_init(net);
104521
104522 diff --git a/scripts/Makefile b/scripts/Makefile
104523 index 1d07860..f16fc22 100644
104524 --- a/scripts/Makefile
104525 +++ b/scripts/Makefile
104526 @@ -40,3 +40,5 @@ subdir-$(CONFIG_DTC) += dtc
104527
104528 # Let clean descend into subdirs
104529 subdir- += basic kconfig package selinux
104530 +
104531 +clean-files := randstruct.seed
104532 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
104533 index 003bc26..d5f02b0 100644
104534 --- a/scripts/Makefile.build
104535 +++ b/scripts/Makefile.build
104536 @@ -121,7 +121,7 @@ endif
104537 endif
104538
104539 # Do not include host rules unless needed
104540 -ifneq ($(hostprogs-y)$(hostprogs-m),)
104541 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
104542 include scripts/Makefile.host
104543 endif
104544
104545 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
104546 index 686cb0d..9d653bf 100644
104547 --- a/scripts/Makefile.clean
104548 +++ b/scripts/Makefile.clean
104549 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
104550 __clean-files := $(extra-y) $(always) \
104551 $(targets) $(clean-files) \
104552 $(host-progs) \
104553 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
104554 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
104555 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
104556
104557 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
104558
104559 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
104560 index 1ac414f..38575f7 100644
104561 --- a/scripts/Makefile.host
104562 +++ b/scripts/Makefile.host
104563 @@ -31,6 +31,8 @@
104564 # Note: Shared libraries consisting of C++ files are not supported
104565
104566 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
104567 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
104568 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
104569
104570 # C code
104571 # Executables compiled from a single .c file
104572 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
104573 # Shared libaries (only .c supported)
104574 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
104575 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
104576 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
104577 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
104578 # Remove .so files from "xxx-objs"
104579 host-cobjs := $(filter-out %.so,$(host-cobjs))
104580 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
104581
104582 -#Object (.o) files used by the shared libaries
104583 +# Object (.o) files used by the shared libaries
104584 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
104585 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
104586
104587 # output directory for programs/.o files
104588 # hostprogs-y := tools/build may have been specified. Retrieve directory
104589 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
104590 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
104591 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
104592 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
104593 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
104594 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
104595 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
104596 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
104597
104598 obj-dirs += $(host-objdirs)
104599 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
104600 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
104601 $(call if_changed_dep,host-cshobjs)
104602
104603 +# Compile .c file, create position independent .o file
104604 +# host-cxxshobjs -> .o
104605 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
104606 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
104607 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
104608 + $(call if_changed_dep,host-cxxshobjs)
104609 +
104610 # Link a shared library, based on position independent .o files
104611 # *.o -> .so shared library (host-cshlib)
104612 quiet_cmd_host-cshlib = HOSTLLD -shared $@
104613 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
104614 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
104615 $(call if_changed,host-cshlib)
104616
104617 +# Link a shared library, based on position independent .o files
104618 +# *.o -> .so shared library (host-cxxshlib)
104619 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
104620 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
104621 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
104622 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
104623 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
104624 + $(call if_changed,host-cxxshlib)
104625 +
104626 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
104627 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
104628 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
104629
104630 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
104631 index 078fe1d..fbdb363 100644
104632 --- a/scripts/basic/fixdep.c
104633 +++ b/scripts/basic/fixdep.c
104634 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
104635 /*
104636 * Lookup a value in the configuration string.
104637 */
104638 -static int is_defined_config(const char *name, int len, unsigned int hash)
104639 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
104640 {
104641 struct item *aux;
104642
104643 @@ -211,10 +211,10 @@ static void clear_config(void)
104644 /*
104645 * Record the use of a CONFIG_* word.
104646 */
104647 -static void use_config(const char *m, int slen)
104648 +static void use_config(const char *m, unsigned int slen)
104649 {
104650 unsigned int hash = strhash(m, slen);
104651 - int c, i;
104652 + unsigned int c, i;
104653
104654 if (is_defined_config(m, slen, hash))
104655 return;
104656 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
104657
104658 static void parse_config_file(const char *map, size_t len)
104659 {
104660 - const int *end = (const int *) (map + len);
104661 + const unsigned int *end = (const unsigned int *) (map + len);
104662 /* start at +1, so that p can never be < map */
104663 - const int *m = (const int *) map + 1;
104664 + const unsigned int *m = (const unsigned int *) map + 1;
104665 const char *p, *q;
104666
104667 for (; m < end; m++) {
104668 @@ -435,7 +435,7 @@ static void print_deps(void)
104669 static void traps(void)
104670 {
104671 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
104672 - int *p = (int *)test;
104673 + unsigned int *p = (unsigned int *)test;
104674
104675 if (*p != INT_CONF) {
104676 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianness? %#x\n",
104677 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
104678 new file mode 100644
104679 index 0000000..3fd3699
104680 --- /dev/null
104681 +++ b/scripts/gcc-plugin.sh
104682 @@ -0,0 +1,43 @@
104683 +#!/bin/bash
104684 +srctree=$(dirname "$0")
104685 +gccplugins_dir=$($3 -print-file-name=plugin)
104686 +plugincc=$($1 -E - -o /dev/null -I${srctree}/../tools/gcc -I${gccplugins_dir}/include 2>&1 <<EOF
104687 +#include "gcc-common.h"
104688 +#if BUILDING_GCC_VERSION >= 4008 || defined(ENABLE_BUILD_WITH_CXX)
104689 +#warning $2 CXX
104690 +#else
104691 +#warning $1 CC
104692 +#endif
104693 +EOF
104694 +)
104695 +
104696 +if [ $? -ne 0 ]
104697 +then
104698 + exit 1
104699 +fi
104700 +
104701 +if [[ "$plugincc" =~ "$1 CC" ]]
104702 +then
104703 + echo "$1"
104704 + exit 0
104705 +fi
104706 +
104707 +if [[ "$plugincc" =~ "$2 CXX" ]]
104708 +then
104709 +plugincc=$($1 -c -x c++ -std=gnu++98 - -o /dev/null -I${srctree}/../tools/gcc -I${gccplugins_dir}/include 2>&1 <<EOF
104710 +#include "gcc-common.h"
104711 +class test {
104712 +public:
104713 + int test;
104714 +} test = {
104715 + .test = 1
104716 +};
104717 +EOF
104718 +)
104719 +if [ $? -eq 0 ]
104720 +then
104721 + echo "$2"
104722 + exit 0
104723 +fi
104724 +fi
104725 +exit 1
104726 diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh
104727 index 5de5660..d3deb89 100644
104728 --- a/scripts/headers_install.sh
104729 +++ b/scripts/headers_install.sh
104730 @@ -32,6 +32,7 @@ do
104731 FILE="$(basename "$i")"
104732 sed -r \
104733 -e 's/([ \t(])(__user|__force|__iomem)[ \t]/\1/g' \
104734 + -e 's/__intentional_overflow\([- \t,0-9]*\)//g' \
104735 -e 's/__attribute_const__([ \t]|$)/\1/g' \
104736 -e 's@^#include <linux/compiler.h>@@' \
104737 -e 's/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g' \
104738 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
104739 index 86a4fe7..99e91f9 100644
104740 --- a/scripts/link-vmlinux.sh
104741 +++ b/scripts/link-vmlinux.sh
104742 @@ -166,7 +166,7 @@ else
104743 fi;
104744
104745 # final build of init/
104746 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
104747 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
104748
104749 kallsymso=""
104750 kallsyms_vmlinux=""
104751 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
104752 index 1924990..3de7363 100644
104753 --- a/scripts/mod/file2alias.c
104754 +++ b/scripts/mod/file2alias.c
104755 @@ -142,7 +142,7 @@ static void device_id_check(const char *modname, const char *device_id,
104756 unsigned long size, unsigned long id_size,
104757 void *symval)
104758 {
104759 - int i;
104760 + unsigned int i;
104761
104762 if (size % id_size || size < id_size) {
104763 fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
104764 @@ -171,7 +171,7 @@ static void device_id_check(const char *modname, const char *device_id,
104765 /* USB is special because the bcdDevice can be matched against a numeric range */
104766 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
104767 static void do_usb_entry(void *symval,
104768 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
104769 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
104770 unsigned char range_lo, unsigned char range_hi,
104771 unsigned char max, struct module *mod)
104772 {
104773 @@ -281,7 +281,7 @@ static void do_usb_entry_multi(void *symval, struct module *mod)
104774 {
104775 unsigned int devlo, devhi;
104776 unsigned char chi, clo, max;
104777 - int ndigits;
104778 + unsigned int ndigits;
104779
104780 DEF_FIELD(symval, usb_device_id, match_flags);
104781 DEF_FIELD(symval, usb_device_id, idVendor);
104782 @@ -534,7 +534,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
104783 for (i = 0; i < count; i++) {
104784 DEF_FIELD_ADDR(symval + i*id_size, pnp_device_id, id);
104785 char acpi_id[sizeof(*id)];
104786 - int j;
104787 + unsigned int j;
104788
104789 buf_printf(&mod->dev_table_buf,
104790 "MODULE_ALIAS(\"pnp:d%s*\");\n", *id);
104791 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
104792
104793 for (j = 0; j < PNP_MAX_DEVICES; j++) {
104794 const char *id = (char *)(*devs)[j].id;
104795 - int i2, j2;
104796 + unsigned int i2, j2;
104797 int dup = 0;
104798
104799 if (!id[0])
104800 @@ -589,7 +589,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
104801 /* add an individual alias for every device entry */
104802 if (!dup) {
104803 char acpi_id[PNP_ID_LEN];
104804 - int k;
104805 + unsigned int k;
104806
104807 buf_printf(&mod->dev_table_buf,
104808 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
104809 @@ -941,7 +941,7 @@ static void dmi_ascii_filter(char *d, const char *s)
104810 static int do_dmi_entry(const char *filename, void *symval,
104811 char *alias)
104812 {
104813 - int i, j;
104814 + unsigned int i, j;
104815 DEF_FIELD_ADDR(symval, dmi_system_id, matches);
104816 sprintf(alias, "dmi*");
104817
104818 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
104819 index 0663556..d9494f0 100644
104820 --- a/scripts/mod/modpost.c
104821 +++ b/scripts/mod/modpost.c
104822 @@ -949,6 +949,7 @@ enum mismatch {
104823 ANY_INIT_TO_ANY_EXIT,
104824 ANY_EXIT_TO_ANY_INIT,
104825 EXPORT_TO_INIT_EXIT,
104826 + DATA_TO_TEXT
104827 };
104828
104829 struct sectioncheck {
104830 @@ -1035,6 +1036,12 @@ const struct sectioncheck sectioncheck[] = {
104831 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
104832 .mismatch = EXPORT_TO_INIT_EXIT,
104833 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
104834 +},
104835 +/* Do not reference code from writable data */
104836 +{
104837 + .fromsec = { DATA_SECTIONS, NULL },
104838 + .tosec = { TEXT_SECTIONS, NULL },
104839 + .mismatch = DATA_TO_TEXT
104840 }
104841 };
104842
104843 @@ -1155,10 +1162,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
104844 continue;
104845 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
104846 continue;
104847 - if (sym->st_value == addr)
104848 - return sym;
104849 /* Find a symbol nearby - addr are maybe negative */
104850 d = sym->st_value - addr;
104851 + if (d == 0)
104852 + return sym;
104853 if (d < 0)
104854 d = addr - sym->st_value;
104855 if (d < distance) {
104856 @@ -1436,6 +1443,14 @@ static void report_sec_mismatch(const char *modname,
104857 tosym, prl_to, prl_to, tosym);
104858 free(prl_to);
104859 break;
104860 + case DATA_TO_TEXT:
104861 +#if 0
104862 + fprintf(stderr,
104863 + "The %s %s:%s references\n"
104864 + "the %s %s:%s%s\n",
104865 + from, fromsec, fromsym, to, tosec, tosym, to_p);
104866 +#endif
104867 + break;
104868 }
104869 fprintf(stderr, "\n");
104870 }
104871 @@ -1687,7 +1702,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
104872 static void check_sec_ref(struct module *mod, const char *modname,
104873 struct elf_info *elf)
104874 {
104875 - int i;
104876 + unsigned int i;
104877 Elf_Shdr *sechdrs = elf->sechdrs;
104878
104879 /* Walk through all sections */
104880 @@ -1819,7 +1834,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
104881 va_end(ap);
104882 }
104883
104884 -void buf_write(struct buffer *buf, const char *s, int len)
104885 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
104886 {
104887 if (buf->size - buf->pos < len) {
104888 buf->size += len + SZ;
104889 @@ -2038,7 +2053,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
104890 if (fstat(fileno(file), &st) < 0)
104891 goto close_write;
104892
104893 - if (st.st_size != b->pos)
104894 + if (st.st_size != (off_t)b->pos)
104895 goto close_write;
104896
104897 tmp = NOFAIL(malloc(b->pos));
104898 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
104899 index 168b43d..77914bf 100644
104900 --- a/scripts/mod/modpost.h
104901 +++ b/scripts/mod/modpost.h
104902 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
104903
104904 struct buffer {
104905 char *p;
104906 - int pos;
104907 - int size;
104908 + unsigned int pos;
104909 + unsigned int size;
104910 };
104911
104912 void __attribute__((format(printf, 2, 3)))
104913 buf_printf(struct buffer *buf, const char *fmt, ...);
104914
104915 void
104916 -buf_write(struct buffer *buf, const char *s, int len);
104917 +buf_write(struct buffer *buf, const char *s, unsigned int len);
104918
104919 struct module {
104920 struct module *next;
104921 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
104922 index deb2994..af4f63e 100644
104923 --- a/scripts/mod/sumversion.c
104924 +++ b/scripts/mod/sumversion.c
104925 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
104926 goto out;
104927 }
104928
104929 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
104930 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
104931 warn("writing sum in %s failed: %s\n",
104932 filename, strerror(errno));
104933 goto out;
104934 diff --git a/scripts/module-common.lds b/scripts/module-common.lds
104935 index 0865b3e..7235dd4 100644
104936 --- a/scripts/module-common.lds
104937 +++ b/scripts/module-common.lds
104938 @@ -6,6 +6,10 @@
104939 SECTIONS {
104940 /DISCARD/ : { *(.discard) }
104941
104942 + .rodata : {
104943 + *(.rodata) *(.rodata.*)
104944 + *(.data..read_only)
104945 + }
104946 __ksymtab : { *(SORT(___ksymtab+*)) }
104947 __ksymtab_gpl : { *(SORT(___ksymtab_gpl+*)) }
104948 __ksymtab_unused : { *(SORT(___ksymtab_unused+*)) }
104949 diff --git a/scripts/package/builddeb b/scripts/package/builddeb
104950 index 152d4d2..791684c 100644
104951 --- a/scripts/package/builddeb
104952 +++ b/scripts/package/builddeb
104953 @@ -291,6 +291,7 @@ fi
104954 (cd $srctree; find . -name Makefile\* -o -name Kconfig\* -o -name \*.pl > "$objtree/debian/hdrsrcfiles")
104955 (cd $srctree; find arch/$SRCARCH/include include scripts -type f >> "$objtree/debian/hdrsrcfiles")
104956 (cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f >> "$objtree/debian/hdrobjfiles")
104957 +(cd $objtree; find tools/gcc -name \*.so >> "$objtree/debian/hdrobjfiles")
104958 destdir=$kernel_headers_dir/usr/src/linux-headers-$version
104959 mkdir -p "$destdir"
104960 (cd $srctree; tar -c -f - -T "$objtree/debian/hdrsrcfiles") | (cd $destdir; tar -xf -)
104961 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
104962 index 68bb4ef..2f419e1 100644
104963 --- a/scripts/pnmtologo.c
104964 +++ b/scripts/pnmtologo.c
104965 @@ -244,14 +244,14 @@ static void write_header(void)
104966 fprintf(out, " * Linux logo %s\n", logoname);
104967 fputs(" */\n\n", out);
104968 fputs("#include <linux/linux_logo.h>\n\n", out);
104969 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
104970 + fprintf(out, "static unsigned char %s_data[] = {\n",
104971 logoname);
104972 }
104973
104974 static void write_footer(void)
104975 {
104976 fputs("\n};\n\n", out);
104977 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
104978 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
104979 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
104980 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
104981 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
104982 @@ -381,7 +381,7 @@ static void write_logo_clut224(void)
104983 fputs("\n};\n\n", out);
104984
104985 /* write logo clut */
104986 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
104987 + fprintf(out, "static unsigned char %s_clut[] = {\n",
104988 logoname);
104989 write_hex_cnt = 0;
104990 for (i = 0; i < logo_clutsize; i++) {
104991 diff --git a/scripts/sortextable.h b/scripts/sortextable.h
104992 index 8fac3fd..32ff38d 100644
104993 --- a/scripts/sortextable.h
104994 +++ b/scripts/sortextable.h
104995 @@ -108,9 +108,9 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
104996 const char *secstrtab;
104997 const char *strtab;
104998 char *extab_image;
104999 - int extab_index = 0;
105000 - int i;
105001 - int idx;
105002 + unsigned int extab_index = 0;
105003 + unsigned int i;
105004 + unsigned int idx;
105005 unsigned int num_sections;
105006 unsigned int secindex_strings;
105007
105008 diff --git a/security/Kconfig b/security/Kconfig
105009 index beb86b5..40b1edb 100644
105010 --- a/security/Kconfig
105011 +++ b/security/Kconfig
105012 @@ -4,6 +4,957 @@
105013
105014 menu "Security options"
105015
105016 +menu "Grsecurity"
105017 +
105018 + config ARCH_TRACK_EXEC_LIMIT
105019 + bool
105020 +
105021 + config PAX_KERNEXEC_PLUGIN
105022 + bool
105023 +
105024 + config PAX_PER_CPU_PGD
105025 + bool
105026 +
105027 + config TASK_SIZE_MAX_SHIFT
105028 + int
105029 + depends on X86_64
105030 + default 47 if !PAX_PER_CPU_PGD
105031 + default 42 if PAX_PER_CPU_PGD
105032 +
105033 + config PAX_ENABLE_PAE
105034 + bool
105035 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
105036 +
105037 + config PAX_USERCOPY_SLABS
105038 + bool
105039 +
105040 +config GRKERNSEC
105041 + bool "Grsecurity"
105042 + select CRYPTO
105043 + select CRYPTO_SHA256
105044 + select PROC_FS
105045 + select STOP_MACHINE
105046 + select TTY
105047 + select DEBUG_KERNEL
105048 + select DEBUG_LIST
105049 + help
105050 + If you say Y here, you will be able to configure many features
105051 + that will enhance the security of your system. It is highly
105052 + recommended that you say Y here and read through the help
105053 + for each option so that you fully understand the features and
105054 + can evaluate their usefulness for your machine.
105055 +
105056 +choice
105057 + prompt "Configuration Method"
105058 + depends on GRKERNSEC
105059 + default GRKERNSEC_CONFIG_CUSTOM
105060 + help
105061 +
105062 +config GRKERNSEC_CONFIG_AUTO
105063 + bool "Automatic"
105064 + help
105065 + If you choose this configuration method, you'll be able to answer a small
105066 + number of simple questions about how you plan to use this kernel.
105067 + The settings of grsecurity and PaX will be automatically configured for
105068 + the highest commonly-used settings within the provided constraints.
105069 +
105070 + If you require additional configuration, custom changes can still be made
105071 + from the "custom configuration" menu.
105072 +
105073 +config GRKERNSEC_CONFIG_CUSTOM
105074 + bool "Custom"
105075 + help
105076 + If you choose this configuration method, you'll be able to configure all
105077 + grsecurity and PaX settings manually. Via this method, no options are
105078 + automatically enabled.
105079 +
105080 +endchoice
105081 +
105082 +choice
105083 + prompt "Usage Type"
105084 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
105085 + default GRKERNSEC_CONFIG_SERVER
105086 + help
105087 +
105088 +config GRKERNSEC_CONFIG_SERVER
105089 + bool "Server"
105090 + help
105091 + Choose this option if you plan to use this kernel on a server.
105092 +
105093 +config GRKERNSEC_CONFIG_DESKTOP
105094 + bool "Desktop"
105095 + help
105096 + Choose this option if you plan to use this kernel on a desktop.
105097 +
105098 +endchoice
105099 +
105100 +choice
105101 + prompt "Virtualization Type"
105102 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
105103 + default GRKERNSEC_CONFIG_VIRT_NONE
105104 + help
105105 +
105106 +config GRKERNSEC_CONFIG_VIRT_NONE
105107 + bool "None"
105108 + help
105109 + Choose this option if this kernel will be run on bare metal.
105110 +
105111 +config GRKERNSEC_CONFIG_VIRT_GUEST
105112 + bool "Guest"
105113 + help
105114 + Choose this option if this kernel will be run as a VM guest.
105115 +
105116 +config GRKERNSEC_CONFIG_VIRT_HOST
105117 + bool "Host"
105118 + help
105119 + Choose this option if this kernel will be run as a VM host.
105120 +
105121 +endchoice
105122 +
105123 +choice
105124 + prompt "Virtualization Hardware"
105125 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
105126 + help
105127 +
105128 +config GRKERNSEC_CONFIG_VIRT_EPT
105129 + bool "EPT/RVI Processor Support"
105130 + depends on X86
105131 + help
105132 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
105133 + hardware virtualization. This allows for additional kernel hardening protections
105134 + to operate without additional performance impact.
105135 +
105136 + To see if your Intel processor supports EPT, see:
105137 + http://ark.intel.com/Products/VirtualizationTechnology
105138 + (Most Core i3/5/7 support EPT)
105139 +
105140 + To see if your AMD processor supports RVI, see:
105141 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
105142 +
105143 +config GRKERNSEC_CONFIG_VIRT_SOFT
105144 + bool "First-gen/No Hardware Virtualization"
105145 + help
105146 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
105147 + support hardware virtualization or doesn't support the EPT/RVI extensions.
105148 +
105149 +endchoice
105150 +
105151 +choice
105152 + prompt "Virtualization Software"
105153 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
105154 + help
105155 +
105156 +config GRKERNSEC_CONFIG_VIRT_XEN
105157 + bool "Xen"
105158 + help
105159 + Choose this option if this kernel is running as a Xen guest or host.
105160 +
105161 +config GRKERNSEC_CONFIG_VIRT_VMWARE
105162 + bool "VMWare"
105163 + help
105164 + Choose this option if this kernel is running as a VMWare guest or host.
105165 +
105166 +config GRKERNSEC_CONFIG_VIRT_KVM
105167 + bool "KVM"
105168 + help
105169 + Choose this option if this kernel is running as a KVM guest or host.
105170 +
105171 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
105172 + bool "VirtualBox"
105173 + help
105174 + Choose this option if this kernel is running as a VirtualBox guest or host.
105175 +
105176 +endchoice
105177 +
105178 +choice
105179 + prompt "Required Priorities"
105180 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
105181 + default GRKERNSEC_CONFIG_PRIORITY_PERF
105182 + help
105183 +
105184 +config GRKERNSEC_CONFIG_PRIORITY_PERF
105185 + bool "Performance"
105186 + help
105187 + Choose this option if performance is of highest priority for this deployment
105188 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
105189 + clearing of structures intended for userland, and freed memory sanitizing will
105190 + be disabled.
105191 +
105192 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
105193 + bool "Security"
105194 + help
105195 + Choose this option if security is of highest priority for this deployment of
105196 + grsecurity. UDEREF, kernel stack clearing, clearing of structures intended
105197 + for userland, and freed memory sanitizing will be enabled for this kernel.
105198 + In a worst-case scenario, these features can introduce a 20% performance hit
105199 + (UDEREF on x64 contributing half of this hit).
105200 +
105201 +endchoice
105202 +
105203 +menu "Default Special Groups"
105204 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
105205 +
105206 +config GRKERNSEC_PROC_GID
105207 + int "GID exempted from /proc restrictions"
105208 + default 1001
105209 + help
105210 + Setting this GID determines which group will be exempted from
105211 + grsecurity's /proc restrictions, allowing users of the specified
105212 + group to view network statistics and the existence of other users'
105213 + processes on the system. This GID may also be chosen at boot time
105214 + via "grsec_proc_gid=" on the kernel commandline.
105215 +
105216 +config GRKERNSEC_TPE_UNTRUSTED_GID
105217 + int "GID for TPE-untrusted users"
105218 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
105219 + default 1005
105220 + help
105221 + Setting this GID determines which group untrusted users should
105222 + be added to. These users will be placed under grsecurity's Trusted Path
105223 + Execution mechanism, preventing them from executing their own binaries.
105224 + The users will only be able to execute binaries in directories owned and
105225 + writable only by the root user. If the sysctl option is enabled, a sysctl
105226 + option with name "tpe_gid" is created.
105227 +
105228 +config GRKERNSEC_TPE_TRUSTED_GID
105229 + int "GID for TPE-trusted users"
105230 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
105231 + default 1005
105232 + help
105233 + Setting this GID determines what group TPE restrictions will be
105234 + *disabled* for. If the sysctl option is enabled, a sysctl option
105235 + with name "tpe_gid" is created.
105236 +
105237 +config GRKERNSEC_SYMLINKOWN_GID
105238 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
105239 + depends on GRKERNSEC_CONFIG_SERVER
105240 + default 1006
105241 + help
105242 + Setting this GID determines what group kernel-enforced
105243 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
105244 + is enabled, a sysctl option with name "symlinkown_gid" is created.
105245 +
105246 +
105247 +endmenu
105248 +
105249 +menu "Customize Configuration"
105250 +depends on GRKERNSEC
105251 +
105252 +menu "PaX"
105253 +
105254 +config PAX
105255 + bool "Enable various PaX features"
105256 + default y if GRKERNSEC_CONFIG_AUTO
105257 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
105258 + help
105259 + This allows you to enable various PaX features. PaX adds
105260 + intrusion prevention mechanisms to the kernel that reduce
105261 + the risks posed by exploitable memory corruption bugs.
105262 +
105263 +menu "PaX Control"
105264 + depends on PAX
105265 +
105266 +config PAX_SOFTMODE
105267 + bool 'Support soft mode'
105268 + help
105269 + Enabling this option will allow you to run PaX in soft mode, that
105270 + is, PaX features will not be enforced by default, only on executables
105271 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
105272 + support as they are the only way to mark executables for soft mode use.
105273 +
105274 + Soft mode can be activated by using the "pax_softmode=1" kernel command
105275 + line option on boot. Furthermore you can control various PaX features
105276 + at runtime via the entries in /proc/sys/kernel/pax.
105277 +
105278 +config PAX_EI_PAX
105279 + bool 'Use legacy ELF header marking'
105280 + default y if GRKERNSEC_CONFIG_AUTO
105281 + help
105282 + Enabling this option will allow you to control PaX features on
105283 + a per executable basis via the 'chpax' utility available at
105284 + http://pax.grsecurity.net/. The control flags will be read from
105285 + an otherwise reserved part of the ELF header. This marking has
105286 + numerous drawbacks (no support for soft-mode, toolchain does not
105287 + know about the non-standard use of the ELF header) therefore it
105288 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
105289 + support.
105290 +
105291 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
105292 + support as well, they will override the legacy EI_PAX marks.
105293 +
105294 + If you enable none of the marking options then all applications
105295 + will run with PaX enabled on them by default.
105296 +
105297 +config PAX_PT_PAX_FLAGS
105298 + bool 'Use ELF program header marking'
105299 + default y if GRKERNSEC_CONFIG_AUTO
105300 + help
105301 + Enabling this option will allow you to control PaX features on
105302 + a per executable basis via the 'paxctl' utility available at
105303 + http://pax.grsecurity.net/. The control flags will be read from
105304 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
105305 + has the benefits of supporting both soft mode and being fully
105306 + integrated into the toolchain (the binutils patch is available
105307 + from http://pax.grsecurity.net).
105308 +
105309 + Note that if you enable the legacy EI_PAX marking support as well,
105310 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
105311 +
105312 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
105313 + must make sure that the marks are the same if a binary has both marks.
105314 +
105315 + If you enable none of the marking options then all applications
105316 + will run with PaX enabled on them by default.
105317 +
105318 +config PAX_XATTR_PAX_FLAGS
105319 + bool 'Use filesystem extended attributes marking'
105320 + default y if GRKERNSEC_CONFIG_AUTO
105321 + select CIFS_XATTR if CIFS
105322 + select F2FS_FS_XATTR if F2FS_FS
105323 + select EXT2_FS_XATTR if EXT2_FS
105324 + select EXT3_FS_XATTR if EXT3_FS
105325 + select JFFS2_FS_XATTR if JFFS2_FS
105326 + select REISERFS_FS_XATTR if REISERFS_FS
105327 + select SQUASHFS_XATTR if SQUASHFS
105328 + select TMPFS_XATTR if TMPFS
105329 + help
105330 + Enabling this option will allow you to control PaX features on
105331 + a per executable basis via the 'setfattr' utility. The control
105332 + flags will be read from the user.pax.flags extended attribute of
105333 + the file. This marking has the benefit of supporting binary-only
105334 + applications that self-check themselves (e.g., skype) and would
105335 + not tolerate chpax/paxctl changes. The main drawback is that
105336 + extended attributes are not supported by some filesystems (e.g.,
105337 + isofs, udf, vfat) so copying files through such filesystems will
105338 + lose the extended attributes and these PaX markings.
105339 +
105340 + Note that if you enable the legacy EI_PAX marking support as well,
105341 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
105342 +
105343 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
105344 + must make sure that the marks are the same if a binary has both marks.
105345 +
105346 + If you enable none of the marking options then all applications
105347 + will run with PaX enabled on them by default.
105348 +
105349 +choice
105350 + prompt 'MAC system integration'
105351 + default PAX_HAVE_ACL_FLAGS
105352 + help
105353 + Mandatory Access Control systems have the option of controlling
105354 + PaX flags on a per executable basis, choose the method supported
105355 + by your particular system.
105356 +
105357 + - "none": if your MAC system does not interact with PaX,
105358 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
105359 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
105360 +
105361 + NOTE: this option is for developers/integrators only.
105362 +
105363 + config PAX_NO_ACL_FLAGS
105364 + bool 'none'
105365 +
105366 + config PAX_HAVE_ACL_FLAGS
105367 + bool 'direct'
105368 +
105369 + config PAX_HOOK_ACL_FLAGS
105370 + bool 'hook'
105371 +endchoice
105372 +
105373 +endmenu
105374 +
105375 +menu "Non-executable pages"
105376 + depends on PAX
105377 +
105378 +config PAX_NOEXEC
105379 + bool "Enforce non-executable pages"
105380 + default y if GRKERNSEC_CONFIG_AUTO
105381 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
105382 + help
105383 + By design some architectures do not allow for protecting memory
105384 + pages against execution or even if they do, Linux does not make
105385 + use of this feature. In practice this means that if a page is
105386 + readable (such as the stack or heap) it is also executable.
105387 +
105388 + There is a well known exploit technique that makes use of this
105389 + fact and a common programming mistake where an attacker can
105390 + introduce code of his choice somewhere in the attacked program's
105391 + memory (typically the stack or the heap) and then execute it.
105392 +
105393 + If the attacked program was running with different (typically
105394 + higher) privileges than that of the attacker, then he can elevate
105395 + his own privilege level (e.g. get a root shell, write to files for
105396 + which he does not have write access to, etc).
105397 +
105398 + Enabling this option will let you choose from various features
105399 + that prevent the injection and execution of 'foreign' code in
105400 + a program.
105401 +
105402 + This will also break programs that rely on the old behaviour and
105403 + expect that dynamically allocated memory via the malloc() family
105404 + of functions is executable (which it is not). Notable examples
105405 + are the XFree86 4.x server, the java runtime and wine.
105406 +
105407 +config PAX_PAGEEXEC
105408 + bool "Paging based non-executable pages"
105409 + default y if GRKERNSEC_CONFIG_AUTO
105410 + 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)
105411 + select ARCH_TRACK_EXEC_LIMIT if X86_32
105412 + help
105413 + This implementation is based on the paging feature of the CPU.
105414 + On i386 without hardware non-executable bit support there is a
105415 + variable but usually low performance impact, however on Intel's
105416 + P4 core based CPUs it is very high so you should not enable this
105417 + for kernels meant to be used on such CPUs.
105418 +
105419 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
105420 + with hardware non-executable bit support there is no performance
105421 + impact, on ppc the impact is negligible.
105422 +
105423 + Note that several architectures require various emulations due to
105424 + badly designed userland ABIs, this will cause a performance impact
105425 + but will disappear as soon as userland is fixed. For example, ppc
105426 + userland MUST have been built with secure-plt by a recent toolchain.
105427 +
105428 +config PAX_SEGMEXEC
105429 + bool "Segmentation based non-executable pages"
105430 + default y if GRKERNSEC_CONFIG_AUTO
105431 + depends on PAX_NOEXEC && X86_32
105432 + help
105433 + This implementation is based on the segmentation feature of the
105434 + CPU and has a very small performance impact, however applications
105435 + will be limited to a 1.5 GB address space instead of the normal
105436 + 3 GB.
105437 +
105438 +config PAX_EMUTRAMP
105439 + bool "Emulate trampolines"
105440 + default y if PARISC || GRKERNSEC_CONFIG_AUTO
105441 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
105442 + help
105443 + There are some programs and libraries that for one reason or
105444 + another attempt to execute special small code snippets from
105445 + non-executable memory pages. Most notable examples are the
105446 + signal handler return code generated by the kernel itself and
105447 + the GCC trampolines.
105448 +
105449 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
105450 + such programs will no longer work under your kernel.
105451 +
105452 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
105453 + utilities to enable trampoline emulation for the affected programs
105454 + yet still have the protection provided by the non-executable pages.
105455 +
105456 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
105457 + your system will not even boot.
105458 +
105459 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
105460 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
105461 + for the affected files.
105462 +
105463 + NOTE: enabling this feature *may* open up a loophole in the
105464 + protection provided by non-executable pages that an attacker
105465 + could abuse. Therefore the best solution is to not have any
105466 + files on your system that would require this option. This can
105467 + be achieved by not using libc5 (which relies on the kernel
105468 + signal handler return code) and not using or rewriting programs
105469 + that make use of the nested function implementation of GCC.
105470 + Skilled users can just fix GCC itself so that it implements
105471 + nested function calls in a way that does not interfere with PaX.
105472 +
105473 +config PAX_EMUSIGRT
105474 + bool "Automatically emulate sigreturn trampolines"
105475 + depends on PAX_EMUTRAMP && PARISC
105476 + default y
105477 + help
105478 + Enabling this option will have the kernel automatically detect
105479 + and emulate signal return trampolines executing on the stack
105480 + that would otherwise lead to task termination.
105481 +
105482 + This solution is intended as a temporary one for users with
105483 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
105484 + Modula-3 runtime, etc) or executables linked to such, basically
105485 + everything that does not specify its own SA_RESTORER function in
105486 + normal executable memory like glibc 2.1+ does.
105487 +
105488 + On parisc you MUST enable this option, otherwise your system will
105489 + not even boot.
105490 +
105491 + NOTE: this feature cannot be disabled on a per executable basis
105492 + and since it *does* open up a loophole in the protection provided
105493 + by non-executable pages, the best solution is to not have any
105494 + files on your system that would require this option.
105495 +
105496 +config PAX_MPROTECT
105497 + bool "Restrict mprotect()"
105498 + default y if GRKERNSEC_CONFIG_AUTO
105499 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
105500 + help
105501 + Enabling this option will prevent programs from
105502 + - changing the executable status of memory pages that were
105503 + not originally created as executable,
105504 + - making read-only executable pages writable again,
105505 + - creating executable pages from anonymous memory,
105506 + - making read-only-after-relocations (RELRO) data pages writable again.
105507 +
105508 + You should say Y here to complete the protection provided by
105509 + the enforcement of non-executable pages.
105510 +
105511 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
105512 + this feature on a per file basis.
105513 +
105514 +config PAX_MPROTECT_COMPAT
105515 + bool "Use legacy/compat protection demoting (read help)"
105516 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
105517 + depends on PAX_MPROTECT
105518 + help
105519 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
105520 + by sending the proper error code to the application. For some broken
105521 + userland, this can cause problems with Python or other applications. The
105522 + current implementation however allows for applications like clamav to
105523 + detect if JIT compilation/execution is allowed and to fall back gracefully
105524 + to an interpreter-based mode if it does not. While we encourage everyone
105525 + to use the current implementation as-is and push upstream to fix broken
105526 + userland (note that the RWX logging option can assist with this), in some
105527 + environments this may not be possible. Having to disable MPROTECT
105528 + completely on certain binaries reduces the security benefit of PaX,
105529 + so this option is provided for those environments to revert to the old
105530 + behavior.
105531 +
105532 +config PAX_ELFRELOCS
105533 + bool "Allow ELF text relocations (read help)"
105534 + depends on PAX_MPROTECT
105535 + default n
105536 + help
105537 + Non-executable pages and mprotect() restrictions are effective
105538 + in preventing the introduction of new executable code into an
105539 + attacked task's address space. There remain only two venues
105540 + for this kind of attack: if the attacker can execute already
105541 + existing code in the attacked task then he can either have it
105542 + create and mmap() a file containing his code or have it mmap()
105543 + an already existing ELF library that does not have position
105544 + independent code in it and use mprotect() on it to make it
105545 + writable and copy his code there. While protecting against
105546 + the former approach is beyond PaX, the latter can be prevented
105547 + by having only PIC ELF libraries on one's system (which do not
105548 + need to relocate their code). If you are sure this is your case,
105549 + as is the case with all modern Linux distributions, then leave
105550 + this option disabled. You should say 'n' here.
105551 +
105552 +config PAX_ETEXECRELOCS
105553 + bool "Allow ELF ET_EXEC text relocations"
105554 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
105555 + select PAX_ELFRELOCS
105556 + default y
105557 + help
105558 + On some architectures there are incorrectly created applications
105559 + that require text relocations and would not work without enabling
105560 + this option. If you are an alpha, ia64 or parisc user, you should
105561 + enable this option and disable it once you have made sure that
105562 + none of your applications need it.
105563 +
105564 +config PAX_EMUPLT
105565 + bool "Automatically emulate ELF PLT"
105566 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
105567 + default y
105568 + help
105569 + Enabling this option will have the kernel automatically detect
105570 + and emulate the Procedure Linkage Table entries in ELF files.
105571 + On some architectures such entries are in writable memory, and
105572 + become non-executable leading to task termination. Therefore
105573 + it is mandatory that you enable this option on alpha, parisc,
105574 + sparc and sparc64, otherwise your system would not even boot.
105575 +
105576 + NOTE: this feature *does* open up a loophole in the protection
105577 + provided by the non-executable pages, therefore the proper
105578 + solution is to modify the toolchain to produce a PLT that does
105579 + not need to be writable.
105580 +
105581 +config PAX_DLRESOLVE
105582 + bool 'Emulate old glibc resolver stub'
105583 + depends on PAX_EMUPLT && SPARC
105584 + default n
105585 + help
105586 + This option is needed if userland has an old glibc (before 2.4)
105587 + that puts a 'save' instruction into the runtime generated resolver
105588 + stub that needs special emulation.
105589 +
105590 +config PAX_KERNEXEC
105591 + bool "Enforce non-executable kernel pages"
105592 + 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))
105593 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !(ARM_LPAE && MODULES))) && !XEN
105594 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
105595 + select PAX_KERNEXEC_PLUGIN if X86_64
105596 + help
105597 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
105598 + that is, enabling this option will make it harder to inject
105599 + and execute 'foreign' code in kernel memory itself.
105600 +
105601 +choice
105602 + prompt "Return Address Instrumentation Method"
105603 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
105604 + depends on PAX_KERNEXEC_PLUGIN
105605 + help
105606 + Select the method used to instrument function pointer dereferences.
105607 + Note that binary modules cannot be instrumented by this approach.
105608 +
105609 + Note that the implementation requires a gcc with plugin support,
105610 + i.e., gcc 4.5 or newer. You may need to install the supporting
105611 + headers explicitly in addition to the normal gcc package.
105612 +
105613 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
105614 + bool "bts"
105615 + help
105616 + This method is compatible with binary only modules but has
105617 + a higher runtime overhead.
105618 +
105619 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
105620 + bool "or"
105621 + depends on !PARAVIRT
105622 + help
105623 + This method is incompatible with binary only modules but has
105624 + a lower runtime overhead.
105625 +endchoice
105626 +
105627 +config PAX_KERNEXEC_PLUGIN_METHOD
105628 + string
105629 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
105630 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
105631 + default ""
105632 +
105633 +config PAX_KERNEXEC_MODULE_TEXT
105634 + int "Minimum amount of memory reserved for module code"
105635 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
105636 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
105637 + depends on PAX_KERNEXEC && X86_32
105638 + help
105639 + Due to implementation details the kernel must reserve a fixed
105640 + amount of memory for runtime allocated code (such as modules)
105641 + at compile time that cannot be changed at runtime. Here you
105642 + can specify the minimum amount in MB that will be reserved.
105643 + Due to the same implementation details this size will always
105644 + be rounded up to the next 2/4 MB boundary (depends on PAE) so
105645 + the actually available memory for runtime allocated code will
105646 + usually be more than this minimum.
105647 +
105648 + The default 4 MB should be enough for most users but if you have
105649 + an excessive number of modules (e.g., most distribution configs
105650 + compile many drivers as modules) or use huge modules such as
105651 + nvidia's kernel driver, you will need to adjust this amount.
105652 + A good rule of thumb is to look at your currently loaded kernel
105653 + modules and add up their sizes.
105654 +
105655 +endmenu
105656 +
105657 +menu "Address Space Layout Randomization"
105658 + depends on PAX
105659 +
105660 +config PAX_ASLR
105661 + bool "Address Space Layout Randomization"
105662 + default y if GRKERNSEC_CONFIG_AUTO
105663 + help
105664 + Many if not most exploit techniques rely on the knowledge of
105665 + certain addresses in the attacked program. The following options
105666 + will allow the kernel to apply a certain amount of randomization
105667 + to specific parts of the program thereby forcing an attacker to
105668 + guess them in most cases. Any failed guess will most likely crash
105669 + the attacked program which allows the kernel to detect such attempts
105670 + and react on them. PaX itself provides no reaction mechanisms,
105671 + instead it is strongly encouraged that you make use of grsecurity's
105672 + (http://www.grsecurity.net/) built-in crash detection features or
105673 + develop one yourself.
105674 +
105675 + By saying Y here you can choose to randomize the following areas:
105676 + - top of the task's kernel stack
105677 + - top of the task's userland stack
105678 + - base address for mmap() requests that do not specify one
105679 + (this includes all libraries)
105680 + - base address of the main executable
105681 +
105682 + It is strongly recommended to say Y here as address space layout
105683 + randomization has negligible impact on performance yet it provides
105684 + a very effective protection.
105685 +
105686 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
105687 + this feature on a per file basis.
105688 +
105689 +config PAX_RANDKSTACK
105690 + bool "Randomize kernel stack base"
105691 + default y if GRKERNSEC_CONFIG_AUTO && !(GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_VIRTUALBOX)
105692 + depends on X86_TSC && X86
105693 + help
105694 + By saying Y here the kernel will randomize every task's kernel
105695 + stack on every system call. This will not only force an attacker
105696 + to guess it but also prevent him from making use of possible
105697 + leaked information about it.
105698 +
105699 + Since the kernel stack is a rather scarce resource, randomization
105700 + may cause unexpected stack overflows, therefore you should very
105701 + carefully test your system. Note that once enabled in the kernel
105702 + configuration, this feature cannot be disabled on a per file basis.
105703 +
105704 +config PAX_RANDUSTACK
105705 + bool
105706 +
105707 +config PAX_RANDMMAP
105708 + bool "Randomize user stack and mmap() bases"
105709 + default y if GRKERNSEC_CONFIG_AUTO
105710 + depends on PAX_ASLR
105711 + select PAX_RANDUSTACK
105712 + help
105713 + By saying Y here the kernel will randomize every task's userland
105714 + stack and use a randomized base address for mmap() requests that
105715 + do not specify one themselves.
105716 +
105717 + The stack randomization is done in two steps where the second
105718 + one may apply a big amount of shift to the top of the stack and
105719 + cause problems for programs that want to use lots of memory (more
105720 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
105721 +
105722 + As a result of mmap randomization all dynamically loaded libraries
105723 + will appear at random addresses and therefore be harder to exploit
105724 + by a technique where an attacker attempts to execute library code
105725 + for his purposes (e.g. spawn a shell from an exploited program that
105726 + is running at an elevated privilege level).
105727 +
105728 + Furthermore, if a program is relinked as a dynamic ELF file, its
105729 + base address will be randomized as well, completing the full
105730 + randomization of the address space layout. Attacking such programs
105731 + becomes a guess game. You can find an example of doing this at
105732 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
105733 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
105734 +
105735 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
105736 + feature on a per file basis.
105737 +
105738 +endmenu
105739 +
105740 +menu "Miscellaneous hardening features"
105741 +
105742 +config PAX_MEMORY_SANITIZE
105743 + bool "Sanitize all freed memory"
105744 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
105745 + help
105746 + By saying Y here the kernel will erase memory pages and slab objects
105747 + as soon as they are freed. This in turn reduces the lifetime of data
105748 + stored in them, making it less likely that sensitive information such
105749 + as passwords, cryptographic secrets, etc stay in memory for too long.
105750 +
105751 + This is especially useful for programs whose runtime is short, long
105752 + lived processes and the kernel itself benefit from this as long as
105753 + they ensure timely freeing of memory that may hold sensitive
105754 + information.
105755 +
105756 + A nice side effect of the sanitization of slab objects is the
105757 + reduction of possible info leaks caused by padding bytes within the
105758 + leaky structures. Use-after-free bugs for structures containing
105759 + pointers can also be detected as dereferencing the sanitized pointer
105760 + will generate an access violation.
105761 +
105762 + The tradeoff is performance impact, on a single CPU system kernel
105763 + compilation sees a 3% slowdown, other systems and workloads may vary
105764 + and you are advised to test this feature on your expected workload
105765 + before deploying it.
105766 +
105767 + To reduce the performance penalty by sanitizing pages only, albeit
105768 + limiting the effectiveness of this feature at the same time, slab
105769 + sanitization can be disabled with the kernel commandline parameter
105770 + "pax_sanitize_slab=0".
105771 +
105772 + Note that this feature does not protect data stored in live pages,
105773 + e.g., process memory swapped to disk may stay there for a long time.
105774 +
105775 +config PAX_MEMORY_STACKLEAK
105776 + bool "Sanitize kernel stack"
105777 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
105778 + depends on X86
105779 + help
105780 + By saying Y here the kernel will erase the kernel stack before it
105781 + returns from a system call. This in turn reduces the information
105782 + that a kernel stack leak bug can reveal.
105783 +
105784 + Note that such a bug can still leak information that was put on
105785 + the stack by the current system call (the one eventually triggering
105786 + the bug) but traces of earlier system calls on the kernel stack
105787 + cannot leak anymore.
105788 +
105789 + The tradeoff is performance impact: on a single CPU system kernel
105790 + compilation sees a 1% slowdown, other systems and workloads may vary
105791 + and you are advised to test this feature on your expected workload
105792 + before deploying it.
105793 +
105794 + Note that the full feature requires a gcc with plugin support,
105795 + i.e., gcc 4.5 or newer. You may need to install the supporting
105796 + headers explicitly in addition to the normal gcc package. Using
105797 + older gcc versions means that functions with large enough stack
105798 + frames may leave uninitialized memory behind that may be exposed
105799 + to a later syscall leaking the stack.
105800 +
105801 +config PAX_MEMORY_STRUCTLEAK
105802 + bool "Forcibly initialize local variables copied to userland"
105803 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
105804 + help
105805 + By saying Y here the kernel will zero initialize some local
105806 + variables that are going to be copied to userland. This in
105807 + turn prevents unintended information leakage from the kernel
105808 + stack should later code forget to explicitly set all parts of
105809 + the copied variable.
105810 +
105811 + The tradeoff is less performance impact than PAX_MEMORY_STACKLEAK
105812 + at a much smaller coverage.
105813 +
105814 + Note that the implementation requires a gcc with plugin support,
105815 + i.e., gcc 4.5 or newer. You may need to install the supporting
105816 + headers explicitly in addition to the normal gcc package.
105817 +
105818 +config PAX_MEMORY_UDEREF
105819 + bool "Prevent invalid userland pointer dereference"
105820 + default y if GRKERNSEC_CONFIG_AUTO && !(X86_64 && GRKERNSEC_CONFIG_PRIORITY_PERF) && (!X86 || GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
105821 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !ARM_LPAE)) && !UML_X86 && !XEN
105822 + select PAX_PER_CPU_PGD if X86_64
105823 + help
105824 + By saying Y here the kernel will be prevented from dereferencing
105825 + userland pointers in contexts where the kernel expects only kernel
105826 + pointers. This is both a useful runtime debugging feature and a
105827 + security measure that prevents exploiting a class of kernel bugs.
105828 +
105829 + The tradeoff is that some virtualization solutions may experience
105830 + a huge slowdown and therefore you should not enable this feature
105831 + for kernels meant to run in such environments. Whether a given VM
105832 + solution is affected or not is best determined by simply trying it
105833 + out, the performance impact will be obvious right on boot as this
105834 + mechanism engages from very early on. A good rule of thumb is that
105835 + VMs running on CPUs without hardware virtualization support (i.e.,
105836 + the majority of IA-32 CPUs) will likely experience the slowdown.
105837 +
105838 + On X86_64 the kernel will make use of PCID support when available
105839 + (Intel's Westmere, Sandy Bridge, etc) for better security (default)
105840 + or performance impact. Pass pax_weakuderef on the kernel command
105841 + line to choose the latter.
105842 +
105843 +config PAX_REFCOUNT
105844 + bool "Prevent various kernel object reference counter overflows"
105845 + default y if GRKERNSEC_CONFIG_AUTO
105846 + depends on GRKERNSEC && ((ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || MIPS || SPARC64 || X86)
105847 + help
105848 + By saying Y here the kernel will detect and prevent overflowing
105849 + various (but not all) kinds of object reference counters. Such
105850 + overflows can normally occur due to bugs only and are often, if
105851 + not always, exploitable.
105852 +
105853 + The tradeoff is that data structures protected by an overflowed
105854 + refcount will never be freed and therefore will leak memory. Note
105855 + that this leak also happens even without this protection but in
105856 + that case the overflow can eventually trigger the freeing of the
105857 + data structure while it is still being used elsewhere, resulting
105858 + in the exploitable situation that this feature prevents.
105859 +
105860 + Since this has a negligible performance impact, you should enable
105861 + this feature.
105862 +
105863 +config PAX_CONSTIFY_PLUGIN
105864 + bool "Automatically constify eligible structures"
105865 + default y
105866 + depends on !UML && PAX_KERNEXEC
105867 + help
105868 + By saying Y here the compiler will automatically constify a class
105869 + of types that contain only function pointers. This reduces the
105870 + kernel's attack surface and also produces a better memory layout.
105871 +
105872 + Note that the implementation requires a gcc with plugin support,
105873 + i.e., gcc 4.5 or newer. You may need to install the supporting
105874 + headers explicitly in addition to the normal gcc package.
105875 +
105876 + Note that if some code really has to modify constified variables
105877 + then the source code will have to be patched to allow it. Examples
105878 + can be found in PaX itself (the no_const attribute) and for some
105879 + out-of-tree modules at http://www.grsecurity.net/~paxguy1/ .
105880 +
105881 +config PAX_USERCOPY
105882 + bool "Harden heap object copies between kernel and userland"
105883 + default y if GRKERNSEC_CONFIG_AUTO
105884 + depends on ARM || IA64 || PPC || SPARC || X86
105885 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
105886 + select PAX_USERCOPY_SLABS
105887 + help
105888 + By saying Y here the kernel will enforce the size of heap objects
105889 + when they are copied in either direction between the kernel and
105890 + userland, even if only a part of the heap object is copied.
105891 +
105892 + Specifically, this checking prevents information leaking from the
105893 + kernel heap during kernel to userland copies (if the kernel heap
105894 + object is otherwise fully initialized) and prevents kernel heap
105895 + overflows during userland to kernel copies.
105896 +
105897 + Note that the current implementation provides the strictest bounds
105898 + checks for the SLUB allocator.
105899 +
105900 + Enabling this option also enables per-slab cache protection against
105901 + data in a given cache being copied into/out of via userland
105902 + accessors. Though the whitelist of regions will be reduced over
105903 + time, it notably protects important data structures like task structs.
105904 +
105905 + If frame pointers are enabled on x86, this option will also restrict
105906 + copies into and out of the kernel stack to local variables within a
105907 + single frame.
105908 +
105909 + Since this has a negligible performance impact, you should enable
105910 + this feature.
105911 +
105912 +config PAX_USERCOPY_DEBUG
105913 + bool
105914 + depends on X86 && PAX_USERCOPY
105915 + default n
105916 +
105917 +config PAX_SIZE_OVERFLOW
105918 + bool "Prevent various integer overflows in function size parameters"
105919 + default y if GRKERNSEC_CONFIG_AUTO
105920 + depends on X86
105921 + help
105922 + By saying Y here the kernel recomputes expressions of function
105923 + arguments marked by a size_overflow attribute with double integer
105924 + precision (DImode/TImode for 32/64 bit integer types).
105925 +
105926 + The recomputed argument is checked against TYPE_MAX and an event
105927 + is logged on overflow and the triggering process is killed.
105928 +
105929 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
105930 +
105931 + Note that the implementation requires a gcc with plugin support,
105932 + i.e., gcc 4.5 or newer. You may need to install the supporting
105933 + headers explicitly in addition to the normal gcc package.
105934 +
105935 +config PAX_LATENT_ENTROPY
105936 + bool "Generate some entropy during boot and runtime"
105937 + default y if GRKERNSEC_CONFIG_AUTO
105938 + help
105939 + By saying Y here the kernel will instrument some kernel code to
105940 + extract some entropy from both original and artificially created
105941 + program state. This will help especially embedded systems where
105942 + there is little 'natural' source of entropy normally. The cost
105943 + is some slowdown of the boot process and fork and irq processing.
105944 +
105945 + When pax_extra_latent_entropy is passed on the kernel command line,
105946 + entropy will be extracted from up to the first 4GB of RAM while the
105947 + runtime memory allocator is being initialized. This costs even more
105948 + slowdown of the boot process.
105949 +
105950 + Note that the implementation requires a gcc with plugin support,
105951 + i.e., gcc 4.5 or newer. You may need to install the supporting
105952 + headers explicitly in addition to the normal gcc package.
105953 +
105954 + Note that entropy extracted this way is not cryptographically
105955 + secure!
105956 +
105957 +endmenu
105958 +
105959 +endmenu
105960 +
105961 +source grsecurity/Kconfig
105962 +
105963 +endmenu
105964 +
105965 +endmenu
105966 +
105967 source security/keys/Kconfig
105968
105969 config SECURITY_DMESG_RESTRICT
105970 @@ -103,7 +1054,7 @@ config INTEL_TXT
105971 config LSM_MMAP_MIN_ADDR
105972 int "Low address space for LSM to protect from user allocation"
105973 depends on SECURITY && SECURITY_SELINUX
105974 - default 32768 if ARM || (ARM64 && COMPAT)
105975 + default 32768 if ALPHA || ARM || (ARM64 && COMPAT) || PARISC || SPARC32
105976 default 65536
105977 help
105978 This is the portion of low virtual memory which should be protected
105979 diff --git a/security/apparmor/file.c b/security/apparmor/file.c
105980 index fdaa50c..2761dcb 100644
105981 --- a/security/apparmor/file.c
105982 +++ b/security/apparmor/file.c
105983 @@ -348,8 +348,8 @@ static inline bool xindex_is_subset(u32 link, u32 target)
105984 int aa_path_link(struct aa_profile *profile, struct dentry *old_dentry,
105985 struct path *new_dir, struct dentry *new_dentry)
105986 {
105987 - struct path link = { new_dir->mnt, new_dentry };
105988 - struct path target = { new_dir->mnt, old_dentry };
105989 + struct path link = { .mnt = new_dir->mnt, .dentry = new_dentry };
105990 + struct path target = { .mnt = new_dir->mnt, .dentry = old_dentry };
105991 struct path_cond cond = {
105992 old_dentry->d_inode->i_uid,
105993 old_dentry->d_inode->i_mode
105994 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
105995 index 9981000..eb21356 100644
105996 --- a/security/apparmor/lsm.c
105997 +++ b/security/apparmor/lsm.c
105998 @@ -186,7 +186,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
105999 struct dentry *dentry, u32 mask,
106000 struct path_cond *cond)
106001 {
106002 - struct path path = { dir->mnt, dentry };
106003 + struct path path = { .mnt = dir->mnt, .dentry = dentry };
106004
106005 return common_perm(op, &path, mask, cond);
106006 }
106007 @@ -203,7 +203,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
106008 static int common_perm_mnt_dentry(int op, struct vfsmount *mnt,
106009 struct dentry *dentry, u32 mask)
106010 {
106011 - struct path path = { mnt, dentry };
106012 + struct path path = { .mnt = mnt, .dentry = dentry };
106013 struct path_cond cond = { dentry->d_inode->i_uid,
106014 dentry->d_inode->i_mode
106015 };
106016 @@ -325,8 +325,8 @@ static int apparmor_path_rename(struct path *old_dir, struct dentry *old_dentry,
106017
106018 profile = aa_current_profile();
106019 if (!unconfined(profile)) {
106020 - struct path old_path = { old_dir->mnt, old_dentry };
106021 - struct path new_path = { new_dir->mnt, new_dentry };
106022 + struct path old_path = { .mnt = old_dir->mnt, .dentry = old_dentry };
106023 + struct path new_path = { .mnt = new_dir->mnt, .dentry = new_dentry };
106024 struct path_cond cond = { old_dentry->d_inode->i_uid,
106025 old_dentry->d_inode->i_mode
106026 };
106027 @@ -615,7 +615,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
106028 return error;
106029 }
106030
106031 -static struct security_operations apparmor_ops = {
106032 +static struct security_operations apparmor_ops __read_only = {
106033 .name = "apparmor",
106034
106035 .ptrace_access_check = apparmor_ptrace_access_check,
106036 diff --git a/security/commoncap.c b/security/commoncap.c
106037 index b9d613e..f68305c 100644
106038 --- a/security/commoncap.c
106039 +++ b/security/commoncap.c
106040 @@ -424,6 +424,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
106041 return 0;
106042 }
106043
106044 +/* returns:
106045 + 1 for suid privilege
106046 + 2 for sgid privilege
106047 + 3 for fscap privilege
106048 +*/
106049 +int is_privileged_binary(const struct dentry *dentry)
106050 +{
106051 + struct cpu_vfs_cap_data capdata;
106052 + struct inode *inode = dentry->d_inode;
106053 +
106054 + if (!inode || S_ISDIR(inode->i_mode))
106055 + return 0;
106056 +
106057 + if (inode->i_mode & S_ISUID)
106058 + return 1;
106059 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
106060 + return 2;
106061 +
106062 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
106063 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
106064 + return 3;
106065 + }
106066 +
106067 + return 0;
106068 +}
106069 +
106070 /*
106071 * Attempt to get the on-exec apply capability sets for an executable file from
106072 * its xattrs and, if present, apply them to the proposed credentials being
106073 @@ -592,6 +618,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
106074 const struct cred *cred = current_cred();
106075 kuid_t root_uid = make_kuid(cred->user_ns, 0);
106076
106077 + if (gr_acl_enable_at_secure())
106078 + return 1;
106079 +
106080 if (!uid_eq(cred->uid, root_uid)) {
106081 if (bprm->cap_effective)
106082 return 1;
106083 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
106084 index f79fa8b..6161868 100644
106085 --- a/security/integrity/ima/ima.h
106086 +++ b/security/integrity/ima/ima.h
106087 @@ -118,8 +118,8 @@ int ima_init_template(void);
106088 extern spinlock_t ima_queue_lock;
106089
106090 struct ima_h_table {
106091 - atomic_long_t len; /* number of stored measurements in the list */
106092 - atomic_long_t violations;
106093 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
106094 + atomic_long_unchecked_t violations;
106095 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
106096 };
106097 extern struct ima_h_table ima_htable;
106098 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
106099 index d9cd5ce..c5c29ac 100644
106100 --- a/security/integrity/ima/ima_api.c
106101 +++ b/security/integrity/ima/ima_api.c
106102 @@ -137,7 +137,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename,
106103 int result;
106104
106105 /* can overflow, only indicator */
106106 - atomic_long_inc(&ima_htable.violations);
106107 + atomic_long_inc_unchecked(&ima_htable.violations);
106108
106109 result = ima_alloc_init_template(NULL, file, filename,
106110 NULL, 0, &entry);
106111 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
106112 index da92fcc..8a5d390 100644
106113 --- a/security/integrity/ima/ima_fs.c
106114 +++ b/security/integrity/ima/ima_fs.c
106115 @@ -28,12 +28,12 @@
106116 static int valid_policy = 1;
106117 #define TMPBUFLEN 12
106118 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
106119 - loff_t *ppos, atomic_long_t *val)
106120 + loff_t *ppos, atomic_long_unchecked_t *val)
106121 {
106122 char tmpbuf[TMPBUFLEN];
106123 ssize_t len;
106124
106125 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
106126 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
106127 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
106128 }
106129
106130 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
106131 index 552705d..9920f4fb 100644
106132 --- a/security/integrity/ima/ima_queue.c
106133 +++ b/security/integrity/ima/ima_queue.c
106134 @@ -83,7 +83,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
106135 INIT_LIST_HEAD(&qe->later);
106136 list_add_tail_rcu(&qe->later, &ima_measurements);
106137
106138 - atomic_long_inc(&ima_htable.len);
106139 + atomic_long_inc_unchecked(&ima_htable.len);
106140 key = ima_hash_key(entry->digest);
106141 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
106142 return 0;
106143 diff --git a/security/keys/compat.c b/security/keys/compat.c
106144 index 3478965..ec7bb9e 100644
106145 --- a/security/keys/compat.c
106146 +++ b/security/keys/compat.c
106147 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
106148 if (ret == 0)
106149 goto no_payload_free;
106150
106151 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
106152 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
106153 err:
106154 if (iov != iovstack)
106155 kfree(iov);
106156 diff --git a/security/keys/internal.h b/security/keys/internal.h
106157 index 80b2aac..bb7ee65 100644
106158 --- a/security/keys/internal.h
106159 +++ b/security/keys/internal.h
106160 @@ -253,7 +253,7 @@ extern long keyctl_instantiate_key_iov(key_serial_t,
106161 extern long keyctl_invalidate_key(key_serial_t);
106162
106163 extern long keyctl_instantiate_key_common(key_serial_t,
106164 - const struct iovec *,
106165 + const struct iovec __user *,
106166 unsigned, size_t, key_serial_t);
106167 #ifdef CONFIG_PERSISTENT_KEYRINGS
106168 extern long keyctl_get_persistent(uid_t, key_serial_t);
106169 diff --git a/security/keys/key.c b/security/keys/key.c
106170 index 6e21c11..9ed67ca 100644
106171 --- a/security/keys/key.c
106172 +++ b/security/keys/key.c
106173 @@ -285,7 +285,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
106174
106175 atomic_set(&key->usage, 1);
106176 init_rwsem(&key->sem);
106177 - lockdep_set_class(&key->sem, &type->lock_class);
106178 + lockdep_set_class(&key->sem, (struct lock_class_key *)&type->lock_class);
106179 key->index_key.type = type;
106180 key->user = user;
106181 key->quotalen = quotalen;
106182 @@ -1036,7 +1036,9 @@ int register_key_type(struct key_type *ktype)
106183 struct key_type *p;
106184 int ret;
106185
106186 - memset(&ktype->lock_class, 0, sizeof(ktype->lock_class));
106187 + pax_open_kernel();
106188 + memset((void *)&ktype->lock_class, 0, sizeof(ktype->lock_class));
106189 + pax_close_kernel();
106190
106191 ret = -EEXIST;
106192 down_write(&key_types_sem);
106193 @@ -1048,7 +1050,7 @@ int register_key_type(struct key_type *ktype)
106194 }
106195
106196 /* store the type */
106197 - list_add(&ktype->link, &key_types_list);
106198 + pax_list_add((struct list_head *)&ktype->link, &key_types_list);
106199
106200 pr_notice("Key type %s registered\n", ktype->name);
106201 ret = 0;
106202 @@ -1070,7 +1072,7 @@ EXPORT_SYMBOL(register_key_type);
106203 void unregister_key_type(struct key_type *ktype)
106204 {
106205 down_write(&key_types_sem);
106206 - list_del_init(&ktype->link);
106207 + pax_list_del_init((struct list_head *)&ktype->link);
106208 downgrade_write(&key_types_sem);
106209 key_gc_keytype(ktype);
106210 pr_notice("Key type %s unregistered\n", ktype->name);
106211 @@ -1088,10 +1090,10 @@ void __init key_init(void)
106212 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
106213
106214 /* add the special key types */
106215 - list_add_tail(&key_type_keyring.link, &key_types_list);
106216 - list_add_tail(&key_type_dead.link, &key_types_list);
106217 - list_add_tail(&key_type_user.link, &key_types_list);
106218 - list_add_tail(&key_type_logon.link, &key_types_list);
106219 + pax_list_add_tail((struct list_head *)&key_type_keyring.link, &key_types_list);
106220 + pax_list_add_tail((struct list_head *)&key_type_dead.link, &key_types_list);
106221 + pax_list_add_tail((struct list_head *)&key_type_user.link, &key_types_list);
106222 + pax_list_add_tail((struct list_head *)&key_type_logon.link, &key_types_list);
106223
106224 /* record the root user tracking */
106225 rb_link_node(&root_key_user.node,
106226 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
106227 index cee72ce..e46074a 100644
106228 --- a/security/keys/keyctl.c
106229 +++ b/security/keys/keyctl.c
106230 @@ -987,7 +987,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
106231 /*
106232 * Copy the iovec data from userspace
106233 */
106234 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
106235 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
106236 unsigned ioc)
106237 {
106238 for (; ioc > 0; ioc--) {
106239 @@ -1009,7 +1009,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
106240 * If successful, 0 will be returned.
106241 */
106242 long keyctl_instantiate_key_common(key_serial_t id,
106243 - const struct iovec *payload_iov,
106244 + const struct iovec __user *payload_iov,
106245 unsigned ioc,
106246 size_t plen,
106247 key_serial_t ringid)
106248 @@ -1104,7 +1104,7 @@ long keyctl_instantiate_key(key_serial_t id,
106249 [0].iov_len = plen
106250 };
106251
106252 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
106253 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
106254 }
106255
106256 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
106257 @@ -1137,7 +1137,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
106258 if (ret == 0)
106259 goto no_payload_free;
106260
106261 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
106262 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
106263 err:
106264 if (iov != iovstack)
106265 kfree(iov);
106266 diff --git a/security/min_addr.c b/security/min_addr.c
106267 index f728728..6457a0c 100644
106268 --- a/security/min_addr.c
106269 +++ b/security/min_addr.c
106270 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
106271 */
106272 static void update_mmap_min_addr(void)
106273 {
106274 +#ifndef SPARC
106275 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
106276 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
106277 mmap_min_addr = dac_mmap_min_addr;
106278 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
106279 #else
106280 mmap_min_addr = dac_mmap_min_addr;
106281 #endif
106282 +#endif
106283 }
106284
106285 /*
106286 diff --git a/security/security.c b/security/security.c
106287 index 8b774f3..a396233 100644
106288 --- a/security/security.c
106289 +++ b/security/security.c
106290 @@ -33,8 +33,8 @@
106291 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
106292 CONFIG_DEFAULT_SECURITY;
106293
106294 -static struct security_operations *security_ops;
106295 -static struct security_operations default_security_ops = {
106296 +struct security_operations *security_ops __read_only;
106297 +struct security_operations default_security_ops __read_only = {
106298 .name = "default",
106299 };
106300
106301 @@ -73,11 +73,6 @@ int __init security_init(void)
106302 return 0;
106303 }
106304
106305 -void reset_security_ops(void)
106306 -{
106307 - security_ops = &default_security_ops;
106308 -}
106309 -
106310 /* Save user chosen LSM */
106311 static int __init choose_lsm(char *str)
106312 {
106313 diff --git a/security/selinux/avc.c b/security/selinux/avc.c
106314 index fc3e662..7844c60 100644
106315 --- a/security/selinux/avc.c
106316 +++ b/security/selinux/avc.c
106317 @@ -59,7 +59,7 @@ struct avc_node {
106318 struct avc_cache {
106319 struct hlist_head slots[AVC_CACHE_SLOTS]; /* head for avc_node->list */
106320 spinlock_t slots_lock[AVC_CACHE_SLOTS]; /* lock for writes */
106321 - atomic_t lru_hint; /* LRU hint for reclaim scan */
106322 + atomic_unchecked_t lru_hint; /* LRU hint for reclaim scan */
106323 atomic_t active_nodes;
106324 u32 latest_notif; /* latest revocation notification */
106325 };
106326 @@ -167,7 +167,7 @@ void __init avc_init(void)
106327 spin_lock_init(&avc_cache.slots_lock[i]);
106328 }
106329 atomic_set(&avc_cache.active_nodes, 0);
106330 - atomic_set(&avc_cache.lru_hint, 0);
106331 + atomic_set_unchecked(&avc_cache.lru_hint, 0);
106332
106333 avc_node_cachep = kmem_cache_create("avc_node", sizeof(struct avc_node),
106334 0, SLAB_PANIC, NULL);
106335 @@ -242,7 +242,7 @@ static inline int avc_reclaim_node(void)
106336 spinlock_t *lock;
106337
106338 for (try = 0, ecx = 0; try < AVC_CACHE_SLOTS; try++) {
106339 - hvalue = atomic_inc_return(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
106340 + hvalue = atomic_inc_return_unchecked(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
106341 head = &avc_cache.slots[hvalue];
106342 lock = &avc_cache.slots_lock[hvalue];
106343
106344 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
106345 index 2c7341d..1da068e 100644
106346 --- a/security/selinux/hooks.c
106347 +++ b/security/selinux/hooks.c
106348 @@ -95,8 +95,6 @@
106349 #include "audit.h"
106350 #include "avc_ss.h"
106351
106352 -extern struct security_operations *security_ops;
106353 -
106354 /* SECMARK reference count */
106355 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
106356
106357 @@ -5758,7 +5756,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
106358
106359 #endif
106360
106361 -static struct security_operations selinux_ops = {
106362 +static struct security_operations selinux_ops __read_only = {
106363 .name = "selinux",
106364
106365 .ptrace_access_check = selinux_ptrace_access_check,
106366 @@ -6111,6 +6109,9 @@ static void selinux_nf_ip_exit(void)
106367 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
106368 static int selinux_disabled;
106369
106370 +extern struct security_operations *security_ops;
106371 +extern struct security_operations default_security_ops;
106372 +
106373 int selinux_disable(void)
106374 {
106375 if (ss_initialized) {
106376 @@ -6128,7 +6129,9 @@ int selinux_disable(void)
106377 selinux_disabled = 1;
106378 selinux_enabled = 0;
106379
106380 - reset_security_ops();
106381 + pax_open_kernel();
106382 + security_ops = &default_security_ops;
106383 + pax_close_kernel();
106384
106385 /* Try to destroy the avc node cache */
106386 avc_disable();
106387 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
106388 index 1450f85..a91e0bc 100644
106389 --- a/security/selinux/include/xfrm.h
106390 +++ b/security/selinux/include/xfrm.h
106391 @@ -48,7 +48,7 @@ static inline void selinux_xfrm_notify_policyload(void)
106392
106393 rtnl_lock();
106394 for_each_net(net) {
106395 - atomic_inc(&net->xfrm.flow_cache_genid);
106396 + atomic_inc_unchecked(&net->xfrm.flow_cache_genid);
106397 rt_genid_bump_all(net);
106398 }
106399 rtnl_unlock();
106400 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
106401 index 14f52be..7352368 100644
106402 --- a/security/smack/smack_lsm.c
106403 +++ b/security/smack/smack_lsm.c
106404 @@ -3726,7 +3726,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
106405 return 0;
106406 }
106407
106408 -struct security_operations smack_ops = {
106409 +struct security_operations smack_ops __read_only = {
106410 .name = "smack",
106411
106412 .ptrace_access_check = smack_ptrace_access_check,
106413 diff --git a/security/tomoyo/file.c b/security/tomoyo/file.c
106414 index 4003907..13a2b55 100644
106415 --- a/security/tomoyo/file.c
106416 +++ b/security/tomoyo/file.c
106417 @@ -692,7 +692,7 @@ int tomoyo_path_number_perm(const u8 type, struct path *path,
106418 {
106419 struct tomoyo_request_info r;
106420 struct tomoyo_obj_info obj = {
106421 - .path1 = *path,
106422 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
106423 };
106424 int error = -ENOMEM;
106425 struct tomoyo_path_info buf;
106426 @@ -740,7 +740,7 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
106427 struct tomoyo_path_info buf;
106428 struct tomoyo_request_info r;
106429 struct tomoyo_obj_info obj = {
106430 - .path1 = *path,
106431 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
106432 };
106433 int idx;
106434
106435 @@ -786,7 +786,7 @@ int tomoyo_path_perm(const u8 operation, struct path *path, const char *target)
106436 {
106437 struct tomoyo_request_info r;
106438 struct tomoyo_obj_info obj = {
106439 - .path1 = *path,
106440 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
106441 };
106442 int error;
106443 struct tomoyo_path_info buf;
106444 @@ -843,7 +843,7 @@ int tomoyo_mkdev_perm(const u8 operation, struct path *path,
106445 {
106446 struct tomoyo_request_info r;
106447 struct tomoyo_obj_info obj = {
106448 - .path1 = *path,
106449 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
106450 };
106451 int error = -ENOMEM;
106452 struct tomoyo_path_info buf;
106453 @@ -890,8 +890,8 @@ int tomoyo_path2_perm(const u8 operation, struct path *path1,
106454 struct tomoyo_path_info buf2;
106455 struct tomoyo_request_info r;
106456 struct tomoyo_obj_info obj = {
106457 - .path1 = *path1,
106458 - .path2 = *path2,
106459 + .path1 = { .mnt = path1->mnt, .dentry = path1->dentry },
106460 + .path2 = { .mnt = path2->mnt, .dentry = path2->dentry }
106461 };
106462 int idx;
106463
106464 diff --git a/security/tomoyo/mount.c b/security/tomoyo/mount.c
106465 index 390c646..f2f8db3 100644
106466 --- a/security/tomoyo/mount.c
106467 +++ b/security/tomoyo/mount.c
106468 @@ -118,6 +118,10 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r,
106469 type == tomoyo_mounts[TOMOYO_MOUNT_MOVE]) {
106470 need_dev = -1; /* dev_name is a directory */
106471 } else {
106472 + if (!capable(CAP_SYS_ADMIN)) {
106473 + error = -EPERM;
106474 + goto out;
106475 + }
106476 fstype = get_fs_type(type);
106477 if (!fstype) {
106478 error = -ENODEV;
106479 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
106480 index f0b756e..8aa497b 100644
106481 --- a/security/tomoyo/tomoyo.c
106482 +++ b/security/tomoyo/tomoyo.c
106483 @@ -146,7 +146,7 @@ static int tomoyo_bprm_check_security(struct linux_binprm *bprm)
106484 */
106485 static int tomoyo_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
106486 {
106487 - struct path path = { mnt, dentry };
106488 + struct path path = { .mnt = mnt, .dentry = dentry };
106489 return tomoyo_path_perm(TOMOYO_TYPE_GETATTR, &path, NULL);
106490 }
106491
106492 @@ -172,7 +172,7 @@ static int tomoyo_path_truncate(struct path *path)
106493 */
106494 static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
106495 {
106496 - struct path path = { parent->mnt, dentry };
106497 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
106498 return tomoyo_path_perm(TOMOYO_TYPE_UNLINK, &path, NULL);
106499 }
106500
106501 @@ -188,7 +188,7 @@ static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
106502 static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
106503 umode_t mode)
106504 {
106505 - struct path path = { parent->mnt, dentry };
106506 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
106507 return tomoyo_path_number_perm(TOMOYO_TYPE_MKDIR, &path,
106508 mode & S_IALLUGO);
106509 }
106510 @@ -203,7 +203,7 @@ static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
106511 */
106512 static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
106513 {
106514 - struct path path = { parent->mnt, dentry };
106515 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
106516 return tomoyo_path_perm(TOMOYO_TYPE_RMDIR, &path, NULL);
106517 }
106518
106519 @@ -219,7 +219,7 @@ static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
106520 static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
106521 const char *old_name)
106522 {
106523 - struct path path = { parent->mnt, dentry };
106524 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
106525 return tomoyo_path_perm(TOMOYO_TYPE_SYMLINK, &path, old_name);
106526 }
106527
106528 @@ -236,7 +236,7 @@ static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
106529 static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
106530 umode_t mode, unsigned int dev)
106531 {
106532 - struct path path = { parent->mnt, dentry };
106533 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
106534 int type = TOMOYO_TYPE_CREATE;
106535 const unsigned int perm = mode & S_IALLUGO;
106536
106537 @@ -275,8 +275,8 @@ static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
106538 static int tomoyo_path_link(struct dentry *old_dentry, struct path *new_dir,
106539 struct dentry *new_dentry)
106540 {
106541 - struct path path1 = { new_dir->mnt, old_dentry };
106542 - struct path path2 = { new_dir->mnt, new_dentry };
106543 + struct path path1 = { .mnt = new_dir->mnt, .dentry = old_dentry };
106544 + struct path path2 = { .mnt = new_dir->mnt, .dentry = new_dentry };
106545 return tomoyo_path2_perm(TOMOYO_TYPE_LINK, &path1, &path2);
106546 }
106547
106548 @@ -295,8 +295,8 @@ static int tomoyo_path_rename(struct path *old_parent,
106549 struct path *new_parent,
106550 struct dentry *new_dentry)
106551 {
106552 - struct path path1 = { old_parent->mnt, old_dentry };
106553 - struct path path2 = { new_parent->mnt, new_dentry };
106554 + struct path path1 = { .mnt = old_parent->mnt, .dentry = old_dentry };
106555 + struct path path2 = { .mnt = new_parent->mnt, .dentry = new_dentry };
106556 return tomoyo_path2_perm(TOMOYO_TYPE_RENAME, &path1, &path2);
106557 }
106558
106559 @@ -424,7 +424,7 @@ static int tomoyo_sb_mount(const char *dev_name, struct path *path,
106560 */
106561 static int tomoyo_sb_umount(struct vfsmount *mnt, int flags)
106562 {
106563 - struct path path = { mnt, mnt->mnt_root };
106564 + struct path path = { .mnt = mnt, .dentry = mnt->mnt_root };
106565 return tomoyo_path_perm(TOMOYO_TYPE_UMOUNT, &path, NULL);
106566 }
106567
106568 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
106569 * tomoyo_security_ops is a "struct security_operations" which is used for
106570 * registering TOMOYO.
106571 */
106572 -static struct security_operations tomoyo_security_ops = {
106573 +static struct security_operations tomoyo_security_ops __read_only = {
106574 .name = "tomoyo",
106575 .cred_alloc_blank = tomoyo_cred_alloc_blank,
106576 .cred_prepare = tomoyo_cred_prepare,
106577 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
106578 index 20ef514..4182bed 100644
106579 --- a/security/yama/Kconfig
106580 +++ b/security/yama/Kconfig
106581 @@ -1,6 +1,6 @@
106582 config SECURITY_YAMA
106583 bool "Yama support"
106584 - depends on SECURITY
106585 + depends on SECURITY && !GRKERNSEC
106586 select SECURITYFS
106587 select SECURITY_PATH
106588 default n
106589 diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
106590 index 13c88fbc..f8c115e 100644
106591 --- a/security/yama/yama_lsm.c
106592 +++ b/security/yama/yama_lsm.c
106593 @@ -365,7 +365,7 @@ int yama_ptrace_traceme(struct task_struct *parent)
106594 }
106595
106596 #ifndef CONFIG_SECURITY_YAMA_STACKED
106597 -static struct security_operations yama_ops = {
106598 +static struct security_operations yama_ops __read_only = {
106599 .name = "yama",
106600
106601 .ptrace_access_check = yama_ptrace_access_check,
106602 @@ -376,28 +376,24 @@ static struct security_operations yama_ops = {
106603 #endif
106604
106605 #ifdef CONFIG_SYSCTL
106606 +static int zero __read_only;
106607 +static int max_scope __read_only = YAMA_SCOPE_NO_ATTACH;
106608 +
106609 static int yama_dointvec_minmax(struct ctl_table *table, int write,
106610 void __user *buffer, size_t *lenp, loff_t *ppos)
106611 {
106612 - int rc;
106613 + ctl_table_no_const yama_table;
106614
106615 if (write && !capable(CAP_SYS_PTRACE))
106616 return -EPERM;
106617
106618 - rc = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
106619 - if (rc)
106620 - return rc;
106621 -
106622 + yama_table = *table;
106623 /* Lock the max value if it ever gets set. */
106624 - if (write && *(int *)table->data == *(int *)table->extra2)
106625 - table->extra1 = table->extra2;
106626 -
106627 - return rc;
106628 + if (ptrace_scope == max_scope)
106629 + yama_table.extra1 = &max_scope;
106630 + return proc_dointvec_minmax(&yama_table, write, buffer, lenp, ppos);
106631 }
106632
106633 -static int zero;
106634 -static int max_scope = YAMA_SCOPE_NO_ATTACH;
106635 -
106636 struct ctl_path yama_sysctl_path[] = {
106637 { .procname = "kernel", },
106638 { .procname = "yama", },
106639 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
106640 index f01bffb..bdda392 100644
106641 --- a/sound/aoa/codecs/onyx.c
106642 +++ b/sound/aoa/codecs/onyx.c
106643 @@ -54,7 +54,7 @@ struct onyx {
106644 spdif_locked:1,
106645 analog_locked:1,
106646 original_mute:2;
106647 - int open_count;
106648 + local_t open_count;
106649 struct codec_info *codec_info;
106650
106651 /* mutex serializes concurrent access to the device
106652 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
106653 struct onyx *onyx = cii->codec_data;
106654
106655 mutex_lock(&onyx->mutex);
106656 - onyx->open_count++;
106657 + local_inc(&onyx->open_count);
106658 mutex_unlock(&onyx->mutex);
106659
106660 return 0;
106661 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
106662 struct onyx *onyx = cii->codec_data;
106663
106664 mutex_lock(&onyx->mutex);
106665 - onyx->open_count--;
106666 - if (!onyx->open_count)
106667 + if (local_dec_and_test(&onyx->open_count))
106668 onyx->spdif_locked = onyx->analog_locked = 0;
106669 mutex_unlock(&onyx->mutex);
106670
106671 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
106672 index ffd2025..df062c9 100644
106673 --- a/sound/aoa/codecs/onyx.h
106674 +++ b/sound/aoa/codecs/onyx.h
106675 @@ -11,6 +11,7 @@
106676 #include <linux/i2c.h>
106677 #include <asm/pmac_low_i2c.h>
106678 #include <asm/prom.h>
106679 +#include <asm/local.h>
106680
106681 /* PCM3052 register definitions */
106682
106683 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
106684 index ada69d7..5f65386 100644
106685 --- a/sound/core/oss/pcm_oss.c
106686 +++ b/sound/core/oss/pcm_oss.c
106687 @@ -1190,10 +1190,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
106688 if (in_kernel) {
106689 mm_segment_t fs;
106690 fs = snd_enter_user();
106691 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
106692 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
106693 snd_leave_user(fs);
106694 } else {
106695 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
106696 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
106697 }
106698 if (ret != -EPIPE && ret != -ESTRPIPE)
106699 break;
106700 @@ -1233,10 +1233,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
106701 if (in_kernel) {
106702 mm_segment_t fs;
106703 fs = snd_enter_user();
106704 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
106705 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
106706 snd_leave_user(fs);
106707 } else {
106708 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
106709 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
106710 }
106711 if (ret == -EPIPE) {
106712 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
106713 @@ -1332,7 +1332,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
106714 struct snd_pcm_plugin_channel *channels;
106715 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
106716 if (!in_kernel) {
106717 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
106718 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
106719 return -EFAULT;
106720 buf = runtime->oss.buffer;
106721 }
106722 @@ -1402,7 +1402,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
106723 }
106724 } else {
106725 tmp = snd_pcm_oss_write2(substream,
106726 - (const char __force *)buf,
106727 + (const char __force_kernel *)buf,
106728 runtime->oss.period_bytes, 0);
106729 if (tmp <= 0)
106730 goto err;
106731 @@ -1428,7 +1428,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
106732 struct snd_pcm_runtime *runtime = substream->runtime;
106733 snd_pcm_sframes_t frames, frames1;
106734 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
106735 - char __user *final_dst = (char __force __user *)buf;
106736 + char __user *final_dst = (char __force_user *)buf;
106737 if (runtime->oss.plugin_first) {
106738 struct snd_pcm_plugin_channel *channels;
106739 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
106740 @@ -1490,7 +1490,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
106741 xfer += tmp;
106742 runtime->oss.buffer_used -= tmp;
106743 } else {
106744 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
106745 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
106746 runtime->oss.period_bytes, 0);
106747 if (tmp <= 0)
106748 goto err;
106749 @@ -1659,7 +1659,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
106750 size1);
106751 size1 /= runtime->channels; /* frames */
106752 fs = snd_enter_user();
106753 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
106754 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
106755 snd_leave_user(fs);
106756 }
106757 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
106758 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
106759 index af49721..e85058e 100644
106760 --- a/sound/core/pcm_compat.c
106761 +++ b/sound/core/pcm_compat.c
106762 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
106763 int err;
106764
106765 fs = snd_enter_user();
106766 - err = snd_pcm_delay(substream, &delay);
106767 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
106768 snd_leave_user(fs);
106769 if (err < 0)
106770 return err;
106771 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
106772 index b653ab0..a4738e3 100644
106773 --- a/sound/core/pcm_native.c
106774 +++ b/sound/core/pcm_native.c
106775 @@ -2812,11 +2812,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
106776 switch (substream->stream) {
106777 case SNDRV_PCM_STREAM_PLAYBACK:
106778 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
106779 - (void __user *)arg);
106780 + (void __force_user *)arg);
106781 break;
106782 case SNDRV_PCM_STREAM_CAPTURE:
106783 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
106784 - (void __user *)arg);
106785 + (void __force_user *)arg);
106786 break;
106787 default:
106788 result = -EINVAL;
106789 diff --git a/sound/core/seq/oss/seq_oss.c b/sound/core/seq/oss/seq_oss.c
106790 index 16d4267..fe8b49b 100644
106791 --- a/sound/core/seq/oss/seq_oss.c
106792 +++ b/sound/core/seq/oss/seq_oss.c
106793 @@ -69,8 +69,8 @@ static int __init alsa_seq_oss_init(void)
106794 {
106795 int rc;
106796 static struct snd_seq_dev_ops ops = {
106797 - snd_seq_oss_synth_register,
106798 - snd_seq_oss_synth_unregister,
106799 + .init_device = snd_seq_oss_synth_register,
106800 + .free_device = snd_seq_oss_synth_unregister,
106801 };
106802
106803 snd_seq_autoload_lock();
106804 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
106805 index 91a786a..4c07ed4 100644
106806 --- a/sound/core/seq/seq_device.c
106807 +++ b/sound/core/seq/seq_device.c
106808 @@ -64,7 +64,7 @@ struct ops_list {
106809 int argsize; /* argument size */
106810
106811 /* operators */
106812 - struct snd_seq_dev_ops ops;
106813 + struct snd_seq_dev_ops *ops;
106814
106815 /* registered devices */
106816 struct list_head dev_list; /* list of devices */
106817 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
106818
106819 mutex_lock(&ops->reg_mutex);
106820 /* copy driver operators */
106821 - ops->ops = *entry;
106822 + ops->ops = entry;
106823 ops->driver |= DRIVER_LOADED;
106824 ops->argsize = argsize;
106825
106826 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
106827 dev->name, ops->id, ops->argsize, dev->argsize);
106828 return -EINVAL;
106829 }
106830 - if (ops->ops.init_device(dev) >= 0) {
106831 + if (ops->ops->init_device(dev) >= 0) {
106832 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
106833 ops->num_init_devices++;
106834 } else {
106835 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
106836 dev->name, ops->id, ops->argsize, dev->argsize);
106837 return -EINVAL;
106838 }
106839 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
106840 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
106841 dev->status = SNDRV_SEQ_DEVICE_FREE;
106842 dev->driver_data = NULL;
106843 ops->num_init_devices--;
106844 diff --git a/sound/core/seq/seq_midi.c b/sound/core/seq/seq_midi.c
106845 index 3e05c55..0f02efc 100644
106846 --- a/sound/core/seq/seq_midi.c
106847 +++ b/sound/core/seq/seq_midi.c
106848 @@ -462,8 +462,8 @@ snd_seq_midisynth_unregister_port(struct snd_seq_device *dev)
106849 static int __init alsa_seq_midi_init(void)
106850 {
106851 static struct snd_seq_dev_ops ops = {
106852 - snd_seq_midisynth_register_port,
106853 - snd_seq_midisynth_unregister_port,
106854 + .init_device = snd_seq_midisynth_register_port,
106855 + .free_device = snd_seq_midisynth_unregister_port,
106856 };
106857 memset(&synths, 0, sizeof(synths));
106858 snd_seq_autoload_lock();
106859 diff --git a/sound/core/sound.c b/sound/core/sound.c
106860 index 38ad1a0..5010a40 100644
106861 --- a/sound/core/sound.c
106862 +++ b/sound/core/sound.c
106863 @@ -86,7 +86,7 @@ static void snd_request_other(int minor)
106864 case SNDRV_MINOR_TIMER: str = "snd-timer"; break;
106865 default: return;
106866 }
106867 - request_module(str);
106868 + request_module("%s", str);
106869 }
106870
106871 #endif /* modular kernel */
106872 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
106873 index f5fd448..6ae276da 100644
106874 --- a/sound/drivers/mts64.c
106875 +++ b/sound/drivers/mts64.c
106876 @@ -29,6 +29,7 @@
106877 #include <sound/initval.h>
106878 #include <sound/rawmidi.h>
106879 #include <sound/control.h>
106880 +#include <asm/local.h>
106881
106882 #define CARD_NAME "Miditerminal 4140"
106883 #define DRIVER_NAME "MTS64"
106884 @@ -67,7 +68,7 @@ struct mts64 {
106885 struct pardevice *pardev;
106886 int pardev_claimed;
106887
106888 - int open_count;
106889 + local_t open_count;
106890 int current_midi_output_port;
106891 int current_midi_input_port;
106892 u8 mode[MTS64_NUM_INPUT_PORTS];
106893 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
106894 {
106895 struct mts64 *mts = substream->rmidi->private_data;
106896
106897 - if (mts->open_count == 0) {
106898 + if (local_read(&mts->open_count) == 0) {
106899 /* We don't need a spinlock here, because this is just called
106900 if the device has not been opened before.
106901 So there aren't any IRQs from the device */
106902 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
106903
106904 msleep(50);
106905 }
106906 - ++(mts->open_count);
106907 + local_inc(&mts->open_count);
106908
106909 return 0;
106910 }
106911 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
106912 struct mts64 *mts = substream->rmidi->private_data;
106913 unsigned long flags;
106914
106915 - --(mts->open_count);
106916 - if (mts->open_count == 0) {
106917 + if (local_dec_return(&mts->open_count) == 0) {
106918 /* We need the spinlock_irqsave here because we can still
106919 have IRQs at this point */
106920 spin_lock_irqsave(&mts->lock, flags);
106921 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
106922
106923 msleep(500);
106924
106925 - } else if (mts->open_count < 0)
106926 - mts->open_count = 0;
106927 + } else if (local_read(&mts->open_count) < 0)
106928 + local_set(&mts->open_count, 0);
106929
106930 return 0;
106931 }
106932 diff --git a/sound/drivers/opl3/opl3_seq.c b/sound/drivers/opl3/opl3_seq.c
106933 index 6839953..7a0f4b9 100644
106934 --- a/sound/drivers/opl3/opl3_seq.c
106935 +++ b/sound/drivers/opl3/opl3_seq.c
106936 @@ -281,8 +281,8 @@ static int __init alsa_opl3_seq_init(void)
106937 {
106938 static struct snd_seq_dev_ops ops =
106939 {
106940 - snd_opl3_seq_new_device,
106941 - snd_opl3_seq_delete_device
106942 + .init_device = snd_opl3_seq_new_device,
106943 + .free_device = snd_opl3_seq_delete_device
106944 };
106945
106946 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL3, &ops,
106947 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
106948 index b953fb4..1999c01 100644
106949 --- a/sound/drivers/opl4/opl4_lib.c
106950 +++ b/sound/drivers/opl4/opl4_lib.c
106951 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
106952 MODULE_DESCRIPTION("OPL4 driver");
106953 MODULE_LICENSE("GPL");
106954
106955 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
106956 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
106957 {
106958 int timeout = 10;
106959 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
106960 diff --git a/sound/drivers/opl4/opl4_seq.c b/sound/drivers/opl4/opl4_seq.c
106961 index 9919769..d7de36c 100644
106962 --- a/sound/drivers/opl4/opl4_seq.c
106963 +++ b/sound/drivers/opl4/opl4_seq.c
106964 @@ -198,8 +198,8 @@ static int snd_opl4_seq_delete_device(struct snd_seq_device *dev)
106965 static int __init alsa_opl4_synth_init(void)
106966 {
106967 static struct snd_seq_dev_ops ops = {
106968 - snd_opl4_seq_new_device,
106969 - snd_opl4_seq_delete_device
106970 + .init_device = snd_opl4_seq_new_device,
106971 + .free_device = snd_opl4_seq_delete_device
106972 };
106973
106974 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL4, &ops,
106975 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
106976 index 78ccfa4..7a0857b 100644
106977 --- a/sound/drivers/portman2x4.c
106978 +++ b/sound/drivers/portman2x4.c
106979 @@ -48,6 +48,7 @@
106980 #include <sound/initval.h>
106981 #include <sound/rawmidi.h>
106982 #include <sound/control.h>
106983 +#include <asm/local.h>
106984
106985 #define CARD_NAME "Portman 2x4"
106986 #define DRIVER_NAME "portman"
106987 @@ -85,7 +86,7 @@ struct portman {
106988 struct pardevice *pardev;
106989 int pardev_claimed;
106990
106991 - int open_count;
106992 + local_t open_count;
106993 int mode[PORTMAN_NUM_INPUT_PORTS];
106994 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
106995 };
106996 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
106997 index 9048777..2d8b1fc 100644
106998 --- a/sound/firewire/amdtp.c
106999 +++ b/sound/firewire/amdtp.c
107000 @@ -488,7 +488,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
107001 ptr = s->pcm_buffer_pointer + data_blocks;
107002 if (ptr >= pcm->runtime->buffer_size)
107003 ptr -= pcm->runtime->buffer_size;
107004 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
107005 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
107006
107007 s->pcm_period_pointer += data_blocks;
107008 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
107009 @@ -655,7 +655,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
107010 */
107011 void amdtp_out_stream_update(struct amdtp_out_stream *s)
107012 {
107013 - ACCESS_ONCE(s->source_node_id_field) =
107014 + ACCESS_ONCE_RW(s->source_node_id_field) =
107015 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
107016 }
107017 EXPORT_SYMBOL(amdtp_out_stream_update);
107018 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
107019 index 2746ecd..c35dedd 100644
107020 --- a/sound/firewire/amdtp.h
107021 +++ b/sound/firewire/amdtp.h
107022 @@ -135,7 +135,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
107023 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
107024 struct snd_pcm_substream *pcm)
107025 {
107026 - ACCESS_ONCE(s->pcm) = pcm;
107027 + ACCESS_ONCE_RW(s->pcm) = pcm;
107028 }
107029
107030 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
107031 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
107032 index 7ac9443..0ec6274 100644
107033 --- a/sound/firewire/isight.c
107034 +++ b/sound/firewire/isight.c
107035 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
107036 ptr += count;
107037 if (ptr >= runtime->buffer_size)
107038 ptr -= runtime->buffer_size;
107039 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
107040 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
107041
107042 isight->period_counter += count;
107043 if (isight->period_counter >= runtime->period_size) {
107044 @@ -299,7 +299,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
107045 if (err < 0)
107046 return err;
107047
107048 - ACCESS_ONCE(isight->pcm_active) = true;
107049 + ACCESS_ONCE_RW(isight->pcm_active) = true;
107050
107051 return 0;
107052 }
107053 @@ -337,7 +337,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
107054 {
107055 struct isight *isight = substream->private_data;
107056
107057 - ACCESS_ONCE(isight->pcm_active) = false;
107058 + ACCESS_ONCE_RW(isight->pcm_active) = false;
107059
107060 mutex_lock(&isight->mutex);
107061 isight_stop_streaming(isight);
107062 @@ -430,10 +430,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
107063
107064 switch (cmd) {
107065 case SNDRV_PCM_TRIGGER_START:
107066 - ACCESS_ONCE(isight->pcm_running) = true;
107067 + ACCESS_ONCE_RW(isight->pcm_running) = true;
107068 break;
107069 case SNDRV_PCM_TRIGGER_STOP:
107070 - ACCESS_ONCE(isight->pcm_running) = false;
107071 + ACCESS_ONCE_RW(isight->pcm_running) = false;
107072 break;
107073 default:
107074 return -EINVAL;
107075 diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
107076 index 2dba848..c682aef 100644
107077 --- a/sound/firewire/scs1x.c
107078 +++ b/sound/firewire/scs1x.c
107079 @@ -74,7 +74,7 @@ static void scs_output_trigger(struct snd_rawmidi_substream *stream, int up)
107080 {
107081 struct scs *scs = stream->rmidi->private_data;
107082
107083 - ACCESS_ONCE(scs->output) = up ? stream : NULL;
107084 + ACCESS_ONCE_RW(scs->output) = up ? stream : NULL;
107085 if (up) {
107086 scs->output_idle = false;
107087 tasklet_schedule(&scs->tasklet);
107088 @@ -257,7 +257,7 @@ static void scs_input_trigger(struct snd_rawmidi_substream *stream, int up)
107089 {
107090 struct scs *scs = stream->rmidi->private_data;
107091
107092 - ACCESS_ONCE(scs->input) = up ? stream : NULL;
107093 + ACCESS_ONCE_RW(scs->input) = up ? stream : NULL;
107094 }
107095
107096 static void scs_input_escaped_byte(struct snd_rawmidi_substream *stream,
107097 @@ -473,8 +473,8 @@ static void scs_remove(struct fw_unit *unit)
107098
107099 snd_card_disconnect(scs->card);
107100
107101 - ACCESS_ONCE(scs->output) = NULL;
107102 - ACCESS_ONCE(scs->input) = NULL;
107103 + ACCESS_ONCE_RW(scs->output) = NULL;
107104 + ACCESS_ONCE_RW(scs->input) = NULL;
107105
107106 wait_event(scs->idle_wait, scs->output_idle);
107107
107108 diff --git a/sound/isa/sb/emu8000_synth.c b/sound/isa/sb/emu8000_synth.c
107109 index 4e3fcfb..ab45a9d 100644
107110 --- a/sound/isa/sb/emu8000_synth.c
107111 +++ b/sound/isa/sb/emu8000_synth.c
107112 @@ -120,8 +120,8 @@ static int __init alsa_emu8000_init(void)
107113 {
107114
107115 static struct snd_seq_dev_ops ops = {
107116 - snd_emu8000_new_device,
107117 - snd_emu8000_delete_device,
107118 + .init_device = snd_emu8000_new_device,
107119 + .free_device = snd_emu8000_delete_device,
107120 };
107121 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU8000, &ops,
107122 sizeof(struct snd_emu8000*));
107123 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
107124 index 048439a..3be9f6f 100644
107125 --- a/sound/oss/sb_audio.c
107126 +++ b/sound/oss/sb_audio.c
107127 @@ -904,7 +904,7 @@ sb16_copy_from_user(int dev,
107128 buf16 = (signed short *)(localbuf + localoffs);
107129 while (c)
107130 {
107131 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
107132 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
107133 if (copy_from_user(lbuf8,
107134 userbuf+useroffs + p,
107135 locallen))
107136 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
107137 index f851fd0..92576fb 100644
107138 --- a/sound/oss/swarm_cs4297a.c
107139 +++ b/sound/oss/swarm_cs4297a.c
107140 @@ -2623,7 +2623,6 @@ static int __init cs4297a_init(void)
107141 {
107142 struct cs4297a_state *s;
107143 u32 pwr, id;
107144 - mm_segment_t fs;
107145 int rval;
107146 #ifndef CONFIG_BCM_CS4297A_CSWARM
107147 u64 cfg;
107148 @@ -2713,22 +2712,23 @@ static int __init cs4297a_init(void)
107149 if (!rval) {
107150 char *sb1250_duart_present;
107151
107152 +#if 0
107153 + mm_segment_t fs;
107154 fs = get_fs();
107155 set_fs(KERNEL_DS);
107156 -#if 0
107157 val = SOUND_MASK_LINE;
107158 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
107159 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
107160 val = initvol[i].vol;
107161 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
107162 }
107163 + set_fs(fs);
107164 // cs4297a_write_ac97(s, 0x18, 0x0808);
107165 #else
107166 // cs4297a_write_ac97(s, 0x5e, 0x180);
107167 cs4297a_write_ac97(s, 0x02, 0x0808);
107168 cs4297a_write_ac97(s, 0x18, 0x0808);
107169 #endif
107170 - set_fs(fs);
107171
107172 list_add(&s->list, &cs4297a_devs);
107173
107174 diff --git a/sound/pci/emu10k1/emu10k1_synth.c b/sound/pci/emu10k1/emu10k1_synth.c
107175 index 4c41c90..37f3631 100644
107176 --- a/sound/pci/emu10k1/emu10k1_synth.c
107177 +++ b/sound/pci/emu10k1/emu10k1_synth.c
107178 @@ -108,8 +108,8 @@ static int __init alsa_emu10k1_synth_init(void)
107179 {
107180
107181 static struct snd_seq_dev_ops ops = {
107182 - snd_emu10k1_synth_new_device,
107183 - snd_emu10k1_synth_delete_device,
107184 + .init_device = snd_emu10k1_synth_new_device,
107185 + .free_device = snd_emu10k1_synth_delete_device,
107186 };
107187 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops,
107188 sizeof(struct snd_emu10k1_synth_arg));
107189 diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
107190 index 4c20277..91abdce 100644
107191 --- a/sound/pci/hda/hda_codec.c
107192 +++ b/sound/pci/hda/hda_codec.c
107193 @@ -966,14 +966,10 @@ find_codec_preset(struct hda_codec *codec)
107194 mutex_unlock(&preset_mutex);
107195
107196 if (mod_requested < HDA_MODREQ_MAX_COUNT) {
107197 - char name[32];
107198 if (!mod_requested)
107199 - snprintf(name, sizeof(name), "snd-hda-codec-id:%08x",
107200 - codec->vendor_id);
107201 + request_module("snd-hda-codec-id:%08x", codec->vendor_id);
107202 else
107203 - snprintf(name, sizeof(name), "snd-hda-codec-id:%04x*",
107204 - (codec->vendor_id >> 16) & 0xffff);
107205 - request_module(name);
107206 + request_module("snd-hda-codec-id:%04x*", (codec->vendor_id >> 16) & 0xffff);
107207 mod_requested++;
107208 goto again;
107209 }
107210 @@ -2777,7 +2773,7 @@ static int get_kctl_0dB_offset(struct snd_kcontrol *kctl, int *step_to_check)
107211 /* FIXME: set_fs() hack for obtaining user-space TLV data */
107212 mm_segment_t fs = get_fs();
107213 set_fs(get_ds());
107214 - if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), _tlv))
107215 + if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), (unsigned int __force_user *)_tlv))
107216 tlv = _tlv;
107217 set_fs(fs);
107218 } else if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_READ)
107219 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
107220 index 4631a23..001ae57 100644
107221 --- a/sound/pci/ymfpci/ymfpci.h
107222 +++ b/sound/pci/ymfpci/ymfpci.h
107223 @@ -358,7 +358,7 @@ struct snd_ymfpci {
107224 spinlock_t reg_lock;
107225 spinlock_t voice_lock;
107226 wait_queue_head_t interrupt_sleep;
107227 - atomic_t interrupt_sleep_count;
107228 + atomic_unchecked_t interrupt_sleep_count;
107229 struct snd_info_entry *proc_entry;
107230 const struct firmware *dsp_microcode;
107231 const struct firmware *controller_microcode;
107232 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
107233 index 81c916a..516f0bf 100644
107234 --- a/sound/pci/ymfpci/ymfpci_main.c
107235 +++ b/sound/pci/ymfpci/ymfpci_main.c
107236 @@ -204,8 +204,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
107237 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
107238 break;
107239 }
107240 - if (atomic_read(&chip->interrupt_sleep_count)) {
107241 - atomic_set(&chip->interrupt_sleep_count, 0);
107242 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
107243 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
107244 wake_up(&chip->interrupt_sleep);
107245 }
107246 __end:
107247 @@ -789,7 +789,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
107248 continue;
107249 init_waitqueue_entry(&wait, current);
107250 add_wait_queue(&chip->interrupt_sleep, &wait);
107251 - atomic_inc(&chip->interrupt_sleep_count);
107252 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
107253 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
107254 remove_wait_queue(&chip->interrupt_sleep, &wait);
107255 }
107256 @@ -827,8 +827,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
107257 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
107258 spin_unlock(&chip->reg_lock);
107259
107260 - if (atomic_read(&chip->interrupt_sleep_count)) {
107261 - atomic_set(&chip->interrupt_sleep_count, 0);
107262 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
107263 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
107264 wake_up(&chip->interrupt_sleep);
107265 }
107266 }
107267 @@ -2423,7 +2423,7 @@ int snd_ymfpci_create(struct snd_card *card,
107268 spin_lock_init(&chip->reg_lock);
107269 spin_lock_init(&chip->voice_lock);
107270 init_waitqueue_head(&chip->interrupt_sleep);
107271 - atomic_set(&chip->interrupt_sleep_count, 0);
107272 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
107273 chip->card = card;
107274 chip->pci = pci;
107275 chip->irq = -1;
107276 diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
107277 index 5428a1f..474f651 100644
107278 --- a/sound/soc/fsl/fsl_ssi.c
107279 +++ b/sound/soc/fsl/fsl_ssi.c
107280 @@ -1255,7 +1255,6 @@ static int fsl_ssi_probe(struct platform_device *pdev)
107281 {
107282 struct fsl_ssi_private *ssi_private;
107283 int ret = 0;
107284 - struct device_attribute *dev_attr = NULL;
107285 struct device_node *np = pdev->dev.of_node;
107286 const struct of_device_id *of_id;
107287 enum fsl_ssi_type hw_type;
107288 @@ -1481,7 +1480,7 @@ static int fsl_ssi_probe(struct platform_device *pdev)
107289 &ssi_private->cpu_dai_drv, 1);
107290 if (ret) {
107291 dev_err(&pdev->dev, "failed to register DAI: %d\n", ret);
107292 - goto error_dev;
107293 + goto error_clk;
107294 }
107295
107296 ret = fsl_ssi_debugfs_create(ssi_private, &pdev->dev);
107297 @@ -1562,9 +1561,6 @@ error_pcm:
107298 error_dbgfs:
107299 snd_soc_unregister_component(&pdev->dev);
107300
107301 -error_dev:
107302 - device_remove_file(&pdev->dev, dev_attr);
107303 -
107304 error_clk:
107305 if (ssi_private->ssi_on_imx) {
107306 if (!IS_ERR(ssi_private->baudclk))
107307 diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
107308 index 051c006..70598e8 100644
107309 --- a/sound/soc/soc-core.c
107310 +++ b/sound/soc/soc-core.c
107311 @@ -2255,8 +2255,10 @@ int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
107312 if (ret)
107313 return ret;
107314
107315 - ops->warm_reset = snd_soc_ac97_warm_reset;
107316 - ops->reset = snd_soc_ac97_reset;
107317 + pax_open_kernel();
107318 + *(void **)&ops->warm_reset = snd_soc_ac97_warm_reset;
107319 + *(void **)&ops->reset = snd_soc_ac97_reset;
107320 + pax_close_kernel();
107321
107322 snd_ac97_rst_cfg = cfg;
107323 return 0;
107324 diff --git a/sound/synth/emux/emux_seq.c b/sound/synth/emux/emux_seq.c
107325 index 7778b8e..3d619fc 100644
107326 --- a/sound/synth/emux/emux_seq.c
107327 +++ b/sound/synth/emux/emux_seq.c
107328 @@ -33,13 +33,13 @@ static int snd_emux_unuse(void *private_data, struct snd_seq_port_subscribe *inf
107329 * MIDI emulation operators
107330 */
107331 static struct snd_midi_op emux_ops = {
107332 - snd_emux_note_on,
107333 - snd_emux_note_off,
107334 - snd_emux_key_press,
107335 - snd_emux_terminate_note,
107336 - snd_emux_control,
107337 - snd_emux_nrpn,
107338 - snd_emux_sysex,
107339 + .note_on = snd_emux_note_on,
107340 + .note_off = snd_emux_note_off,
107341 + .key_press = snd_emux_key_press,
107342 + .note_terminate = snd_emux_terminate_note,
107343 + .control = snd_emux_control,
107344 + .nrpn = snd_emux_nrpn,
107345 + .sysex = snd_emux_sysex,
107346 };
107347
107348
107349 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
107350 new file mode 100644
107351 index 0000000..de92ed9
107352 --- /dev/null
107353 +++ b/tools/gcc/.gitignore
107354 @@ -0,0 +1 @@
107355 +randomize_layout_seed.h
107356 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
107357 new file mode 100644
107358 index 0000000..7b8921f
107359 --- /dev/null
107360 +++ b/tools/gcc/Makefile
107361 @@ -0,0 +1,52 @@
107362 +#CC := gcc
107363 +#PLUGIN_SOURCE_FILES := pax_plugin.c
107364 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
107365 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
107366 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
107367 +
107368 +ifeq ($(PLUGINCC),$(HOSTCC))
107369 +HOSTLIBS := hostlibs
107370 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu99 -ggdb
107371 +export HOST_EXTRACFLAGS
107372 +else
107373 +HOSTLIBS := hostcxxlibs
107374 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu++98 -fno-rtti -ggdb -Wno-unused-parameter -Wno-narrowing -Wno-unused-variable
107375 +export HOST_EXTRACXXFLAGS
107376 +endif
107377 +
107378 +export GCCPLUGINS_DIR HOSTLIBS
107379 +
107380 +$(HOSTLIBS)-$(CONFIG_PAX_CONSTIFY_PLUGIN) := constify_plugin.so
107381 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
107382 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
107383 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
107384 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
107385 +$(HOSTLIBS)-y += colorize_plugin.so
107386 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
107387 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STRUCTLEAK) += structleak_plugin.so
107388 +$(HOSTLIBS)-$(CONFIG_GRKERNSEC_RANDSTRUCT) += randomize_layout_plugin.so
107389 +
107390 +subdir-$(CONFIG_PAX_SIZE_OVERFLOW) := size_overflow_plugin
107391 +subdir- += size_overflow_plugin
107392 +
107393 +always := $($(HOSTLIBS)-y)
107394 +
107395 +constify_plugin-objs := constify_plugin.o
107396 +stackleak_plugin-objs := stackleak_plugin.o
107397 +kallocstat_plugin-objs := kallocstat_plugin.o
107398 +kernexec_plugin-objs := kernexec_plugin.o
107399 +checker_plugin-objs := checker_plugin.o
107400 +colorize_plugin-objs := colorize_plugin.o
107401 +latent_entropy_plugin-objs := latent_entropy_plugin.o
107402 +structleak_plugin-objs := structleak_plugin.o
107403 +randomize_layout_plugin-objs := randomize_layout_plugin.o
107404 +
107405 +$(obj)/randomize_layout_plugin.o: $(objtree)/$(obj)/randomize_layout_seed.h
107406 +
107407 +quiet_cmd_create_randomize_layout_seed = GENSEED $@
107408 + cmd_create_randomize_layout_seed = \
107409 + $(CONFIG_SHELL) $(srctree)/$(src)/gen-random-seed.sh $@ $(objtree)/include/generated/randomize_layout_hash.h
107410 +$(objtree)/$(obj)/randomize_layout_seed.h: FORCE
107411 + $(call if_changed,create_randomize_layout_seed)
107412 +
107413 +targets += randomize_layout_seed.h randomize_layout_hash.h
107414 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
107415 new file mode 100644
107416 index 0000000..5452feea
107417 --- /dev/null
107418 +++ b/tools/gcc/checker_plugin.c
107419 @@ -0,0 +1,150 @@
107420 +/*
107421 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
107422 + * Licensed under the GPL v2
107423 + *
107424 + * Note: the choice of the license means that the compilation process is
107425 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
107426 + * but for the kernel it doesn't matter since it doesn't link against
107427 + * any of the gcc libraries
107428 + *
107429 + * gcc plugin to implement various sparse (source code checker) features
107430 + *
107431 + * TODO:
107432 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
107433 + *
107434 + * BUGS:
107435 + * - none known
107436 + */
107437 +
107438 +#include "gcc-common.h"
107439 +
107440 +extern void c_register_addr_space (const char *str, addr_space_t as);
107441 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
107442 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
107443 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
107444 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
107445 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
107446 +
107447 +int plugin_is_GPL_compatible;
107448 +
107449 +static struct plugin_info checker_plugin_info = {
107450 + .version = "201304082245",
107451 + .help = NULL,
107452 +};
107453 +
107454 +#define ADDR_SPACE_KERNEL 0
107455 +#define ADDR_SPACE_FORCE_KERNEL 1
107456 +#define ADDR_SPACE_USER 2
107457 +#define ADDR_SPACE_FORCE_USER 3
107458 +#define ADDR_SPACE_IOMEM 0
107459 +#define ADDR_SPACE_FORCE_IOMEM 0
107460 +#define ADDR_SPACE_PERCPU 0
107461 +#define ADDR_SPACE_FORCE_PERCPU 0
107462 +#define ADDR_SPACE_RCU 0
107463 +#define ADDR_SPACE_FORCE_RCU 0
107464 +
107465 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
107466 +{
107467 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
107468 +}
107469 +
107470 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
107471 +{
107472 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
107473 +}
107474 +
107475 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
107476 +{
107477 + return default_addr_space_valid_pointer_mode(mode, as);
107478 +}
107479 +
107480 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
107481 +{
107482 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
107483 +}
107484 +
107485 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
107486 +{
107487 + return default_addr_space_legitimize_address(x, oldx, mode, as);
107488 +}
107489 +
107490 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
107491 +{
107492 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
107493 + return true;
107494 +
107495 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
107496 + return true;
107497 +
107498 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
107499 + return true;
107500 +
107501 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
107502 + return true;
107503 +
107504 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
107505 + return true;
107506 +
107507 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
107508 + return true;
107509 +
107510 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
107511 + return true;
107512 +
107513 + return subset == superset;
107514 +}
107515 +
107516 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
107517 +{
107518 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
107519 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
107520 +
107521 + return op;
107522 +}
107523 +
107524 +static void register_checker_address_spaces(void *event_data, void *data)
107525 +{
107526 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
107527 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
107528 + c_register_addr_space("__user", ADDR_SPACE_USER);
107529 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
107530 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
107531 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
107532 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
107533 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
107534 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
107535 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
107536 +
107537 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
107538 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
107539 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
107540 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
107541 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
107542 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
107543 + targetm.addr_space.convert = checker_addr_space_convert;
107544 +}
107545 +
107546 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
107547 +{
107548 + const char * const plugin_name = plugin_info->base_name;
107549 + const int argc = plugin_info->argc;
107550 + const struct plugin_argument * const argv = plugin_info->argv;
107551 + int i;
107552 +
107553 + if (!plugin_default_version_check(version, &gcc_version)) {
107554 + error(G_("incompatible gcc/plugin versions"));
107555 + return 1;
107556 + }
107557 +
107558 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
107559 +
107560 + for (i = 0; i < argc; ++i)
107561 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
107562 +
107563 + if (TARGET_64BIT == 0)
107564 + return 0;
107565 +
107566 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
107567 +
107568 + return 0;
107569 +}
107570 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
107571 new file mode 100644
107572 index 0000000..54461af
107573 --- /dev/null
107574 +++ b/tools/gcc/colorize_plugin.c
107575 @@ -0,0 +1,210 @@
107576 +/*
107577 + * Copyright 2012-2014 by PaX Team <pageexec@freemail.hu>
107578 + * Licensed under the GPL v2
107579 + *
107580 + * Note: the choice of the license means that the compilation process is
107581 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
107582 + * but for the kernel it doesn't matter since it doesn't link against
107583 + * any of the gcc libraries
107584 + *
107585 + * gcc plugin to colorize diagnostic output
107586 + *
107587 + */
107588 +
107589 +#include "gcc-common.h"
107590 +
107591 +int plugin_is_GPL_compatible;
107592 +
107593 +static struct plugin_info colorize_plugin_info = {
107594 + .version = "201404202350",
107595 + .help = "color=[never|always|auto]\tdetermine when to colorize\n",
107596 +};
107597 +
107598 +#define GREEN "\033[32m\033[K"
107599 +#define LIGHTGREEN "\033[1;32m\033[K"
107600 +#define YELLOW "\033[33m\033[K"
107601 +#define LIGHTYELLOW "\033[1;33m\033[K"
107602 +#define RED "\033[31m\033[K"
107603 +#define LIGHTRED "\033[1;31m\033[K"
107604 +#define BLUE "\033[34m\033[K"
107605 +#define LIGHTBLUE "\033[1;34m\033[K"
107606 +#define BRIGHT "\033[1;m\033[K"
107607 +#define NORMAL "\033[m\033[K"
107608 +
107609 +static diagnostic_starter_fn old_starter;
107610 +static diagnostic_finalizer_fn old_finalizer;
107611 +
107612 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
107613 +{
107614 + const char *color;
107615 + char *newprefix;
107616 +
107617 + switch (diagnostic->kind) {
107618 + case DK_NOTE:
107619 + color = LIGHTBLUE;
107620 + break;
107621 +
107622 + case DK_PEDWARN:
107623 + case DK_WARNING:
107624 + color = LIGHTYELLOW;
107625 + break;
107626 +
107627 + case DK_ERROR:
107628 + case DK_FATAL:
107629 + case DK_ICE:
107630 + case DK_PERMERROR:
107631 + case DK_SORRY:
107632 + color = LIGHTRED;
107633 + break;
107634 +
107635 + default:
107636 + color = NORMAL;
107637 + }
107638 +
107639 + old_starter(context, diagnostic);
107640 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
107641 + return;
107642 + pp_destroy_prefix(context->printer);
107643 + pp_set_prefix(context->printer, newprefix);
107644 +}
107645 +
107646 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
107647 +{
107648 + old_finalizer(context, diagnostic);
107649 +}
107650 +
107651 +static void colorize_arm(void)
107652 +{
107653 + old_starter = diagnostic_starter(global_dc);
107654 + old_finalizer = diagnostic_finalizer(global_dc);
107655 +
107656 + diagnostic_starter(global_dc) = start_colorize;
107657 + diagnostic_finalizer(global_dc) = finalize_colorize;
107658 +}
107659 +
107660 +static unsigned int execute_colorize_rearm(void)
107661 +{
107662 + if (diagnostic_starter(global_dc) == start_colorize)
107663 + return 0;
107664 +
107665 + colorize_arm();
107666 + return 0;
107667 +}
107668 +
107669 +#if BUILDING_GCC_VERSION >= 4009
107670 +static const struct pass_data colorize_rearm_pass_data = {
107671 +#else
107672 +struct simple_ipa_opt_pass colorize_rearm_pass = {
107673 + .pass = {
107674 +#endif
107675 + .type = SIMPLE_IPA_PASS,
107676 + .name = "colorize_rearm",
107677 +#if BUILDING_GCC_VERSION >= 4008
107678 + .optinfo_flags = OPTGROUP_NONE,
107679 +#endif
107680 +#if BUILDING_GCC_VERSION >= 4009
107681 + .has_gate = false,
107682 + .has_execute = true,
107683 +#else
107684 + .gate = NULL,
107685 + .execute = execute_colorize_rearm,
107686 + .sub = NULL,
107687 + .next = NULL,
107688 + .static_pass_number = 0,
107689 +#endif
107690 + .tv_id = TV_NONE,
107691 + .properties_required = 0,
107692 + .properties_provided = 0,
107693 + .properties_destroyed = 0,
107694 + .todo_flags_start = 0,
107695 + .todo_flags_finish = 0
107696 +#if BUILDING_GCC_VERSION < 4009
107697 + }
107698 +#endif
107699 +};
107700 +
107701 +#if BUILDING_GCC_VERSION >= 4009
107702 +namespace {
107703 +class colorize_rearm_pass : public simple_ipa_opt_pass {
107704 +public:
107705 + colorize_rearm_pass() : simple_ipa_opt_pass(colorize_rearm_pass_data, g) {}
107706 + unsigned int execute() { return execute_colorize_rearm(); }
107707 +};
107708 +}
107709 +
107710 +static opt_pass *make_colorize_rearm_pass(void)
107711 +{
107712 + return new colorize_rearm_pass();
107713 +}
107714 +#else
107715 +static struct opt_pass *make_colorize_rearm_pass(void)
107716 +{
107717 + return &colorize_rearm_pass.pass;
107718 +}
107719 +#endif
107720 +
107721 +static void colorize_start_unit(void *gcc_data, void *user_data)
107722 +{
107723 + colorize_arm();
107724 +}
107725 +
107726 +static bool should_colorize(void)
107727 +{
107728 +#if BUILDING_GCC_VERSION >= 4009
107729 + return false;
107730 +#else
107731 + char const *t = getenv("TERM");
107732 +
107733 + return t && strcmp(t, "dumb") && isatty(STDERR_FILENO);
107734 +#endif
107735 +}
107736 +
107737 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
107738 +{
107739 + const char * const plugin_name = plugin_info->base_name;
107740 + const int argc = plugin_info->argc;
107741 + const struct plugin_argument * const argv = plugin_info->argv;
107742 + int i;
107743 + struct register_pass_info colorize_rearm_pass_info;
107744 + bool colorize;
107745 +
107746 + colorize_rearm_pass_info.pass = make_colorize_rearm_pass();
107747 + colorize_rearm_pass_info.reference_pass_name = "*free_lang_data";
107748 + colorize_rearm_pass_info.ref_pass_instance_number = 1;
107749 + colorize_rearm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
107750 +
107751 + if (!plugin_default_version_check(version, &gcc_version)) {
107752 + error(G_("incompatible gcc/plugin versions"));
107753 + return 1;
107754 + }
107755 +
107756 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
107757 +
107758 + colorize = getenv("GCC_COLORS") ? should_colorize() : false;
107759 +
107760 + for (i = 0; i < argc; ++i) {
107761 + if (!strcmp(argv[i].key, "color")) {
107762 + if (!argv[i].value) {
107763 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
107764 + continue;
107765 + }
107766 + if (!strcmp(argv[i].value, "always"))
107767 + colorize = true;
107768 + else if (!strcmp(argv[i].value, "never"))
107769 + colorize = false;
107770 + else if (!strcmp(argv[i].value, "auto"))
107771 + colorize = should_colorize();
107772 + else
107773 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
107774 + continue;
107775 + }
107776 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
107777 + }
107778 +
107779 + if (colorize) {
107780 + // TODO: parse GCC_COLORS as used by gcc 4.9+
107781 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
107782 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
107783 + }
107784 + return 0;
107785 +}
107786 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
107787 new file mode 100644
107788 index 0000000..82bc5a8
107789 --- /dev/null
107790 +++ b/tools/gcc/constify_plugin.c
107791 @@ -0,0 +1,557 @@
107792 +/*
107793 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
107794 + * Copyright 2011-2014 by PaX Team <pageexec@freemail.hu>
107795 + * Licensed under the GPL v2, or (at your option) v3
107796 + *
107797 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
107798 + *
107799 + * Homepage:
107800 + * http://www.grsecurity.net/~ephox/const_plugin/
107801 + *
107802 + * Usage:
107803 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
107804 + * $ gcc -fplugin=constify_plugin.so test.c -O2
107805 + */
107806 +
107807 +#include "gcc-common.h"
107808 +
107809 +// unused C type flag in all versions 4.5-4.9
107810 +#define TYPE_CONSTIFY_VISITED(TYPE) TYPE_LANG_FLAG_4(TYPE)
107811 +
107812 +int plugin_is_GPL_compatible;
107813 +
107814 +static struct plugin_info const_plugin_info = {
107815 + .version = "201401270210",
107816 + .help = "no-constify\tturn off constification\n",
107817 +};
107818 +
107819 +typedef struct {
107820 + bool has_fptr_field;
107821 + bool has_writable_field;
107822 + bool has_do_const_field;
107823 + bool has_no_const_field;
107824 +} constify_info;
107825 +
107826 +static const_tree get_field_type(const_tree field)
107827 +{
107828 + return strip_array_types(TREE_TYPE(field));
107829 +}
107830 +
107831 +static bool is_fptr(const_tree field)
107832 +{
107833 + const_tree ptr = get_field_type(field);
107834 +
107835 + if (TREE_CODE(ptr) != POINTER_TYPE)
107836 + return false;
107837 +
107838 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
107839 +}
107840 +
107841 +/*
107842 + * determine whether the given structure type meets the requirements for automatic constification,
107843 + * including the constification attributes on nested structure types
107844 + */
107845 +static void constifiable(const_tree node, constify_info *cinfo)
107846 +{
107847 + const_tree field;
107848 +
107849 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
107850 +
107851 + // e.g., pointer to structure fields while still constructing the structure type
107852 + if (TYPE_FIELDS(node) == NULL_TREE)
107853 + return;
107854 +
107855 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
107856 + const_tree type = get_field_type(field);
107857 + enum tree_code code = TREE_CODE(type);
107858 +
107859 + if (node == type)
107860 + continue;
107861 +
107862 + if (is_fptr(field))
107863 + cinfo->has_fptr_field = true;
107864 + else if (!TREE_READONLY(field))
107865 + cinfo->has_writable_field = true;
107866 +
107867 + if (code == RECORD_TYPE || code == UNION_TYPE) {
107868 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
107869 + cinfo->has_do_const_field = true;
107870 + else if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
107871 + cinfo->has_no_const_field = true;
107872 + else
107873 + constifiable(type, cinfo);
107874 + }
107875 + }
107876 +}
107877 +
107878 +static bool constified(const_tree node)
107879 +{
107880 + constify_info cinfo = {
107881 + .has_fptr_field = false,
107882 + .has_writable_field = false,
107883 + .has_do_const_field = false,
107884 + .has_no_const_field = false
107885 + };
107886 +
107887 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
107888 +
107889 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
107890 +// gcc_assert(!TYPE_READONLY(node));
107891 + return false;
107892 + }
107893 +
107894 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node))) {
107895 + gcc_assert(TYPE_READONLY(node));
107896 + return true;
107897 + }
107898 +
107899 + constifiable(node, &cinfo);
107900 + if ((!cinfo.has_fptr_field || cinfo.has_writable_field) && !cinfo.has_do_const_field)
107901 + return false;
107902 +
107903 + return TYPE_READONLY(node);
107904 +}
107905 +
107906 +static void deconstify_tree(tree node);
107907 +
107908 +static void deconstify_type(tree type)
107909 +{
107910 + tree field;
107911 +
107912 + gcc_assert(TREE_CODE(type) == RECORD_TYPE || TREE_CODE(type) == UNION_TYPE);
107913 +
107914 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
107915 + const_tree fieldtype = get_field_type(field);
107916 +
107917 + // special case handling of simple ptr-to-same-array-type members
107918 + if (TREE_CODE(TREE_TYPE(field)) == POINTER_TYPE) {
107919 + tree ptrtype = TREE_TYPE(TREE_TYPE(field));
107920 +
107921 + if (TREE_TYPE(TREE_TYPE(field)) == type)
107922 + continue;
107923 + if (TREE_CODE(ptrtype) != RECORD_TYPE && TREE_CODE(ptrtype) != UNION_TYPE)
107924 + continue;
107925 + if (!constified(ptrtype))
107926 + continue;
107927 + if (TYPE_MAIN_VARIANT(ptrtype) == TYPE_MAIN_VARIANT(type)) {
107928 + TREE_TYPE(field) = copy_node(TREE_TYPE(field));
107929 + TREE_TYPE(TREE_TYPE(field)) = build_qualified_type(type, TYPE_QUALS(ptrtype) & ~TYPE_QUAL_CONST);
107930 + }
107931 + continue;
107932 + }
107933 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
107934 + continue;
107935 + if (!constified(fieldtype))
107936 + continue;
107937 +
107938 + deconstify_tree(field);
107939 + TREE_READONLY(field) = 0;
107940 + }
107941 + TYPE_READONLY(type) = 0;
107942 + C_TYPE_FIELDS_READONLY(type) = 0;
107943 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
107944 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
107945 + TYPE_ATTRIBUTES(type) = remove_attribute("do_const", TYPE_ATTRIBUTES(type));
107946 + }
107947 +}
107948 +
107949 +static void deconstify_tree(tree node)
107950 +{
107951 + tree old_type, new_type, field;
107952 +
107953 + old_type = TREE_TYPE(node);
107954 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
107955 + node = TREE_TYPE(node) = copy_node(old_type);
107956 + old_type = TREE_TYPE(old_type);
107957 + }
107958 +
107959 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
107960 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
107961 +
107962 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
107963 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
107964 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
107965 + DECL_FIELD_CONTEXT(field) = new_type;
107966 +
107967 + deconstify_type(new_type);
107968 +
107969 + TREE_TYPE(node) = new_type;
107970 +}
107971 +
107972 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
107973 +{
107974 + tree type;
107975 + constify_info cinfo = {
107976 + .has_fptr_field = false,
107977 + .has_writable_field = false,
107978 + .has_do_const_field = false,
107979 + .has_no_const_field = false
107980 + };
107981 +
107982 + *no_add_attrs = true;
107983 + if (TREE_CODE(*node) == FUNCTION_DECL) {
107984 + error("%qE attribute does not apply to functions (%qF)", name, *node);
107985 + return NULL_TREE;
107986 + }
107987 +
107988 + if (TREE_CODE(*node) == PARM_DECL) {
107989 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
107990 + return NULL_TREE;
107991 + }
107992 +
107993 + if (TREE_CODE(*node) == VAR_DECL) {
107994 + error("%qE attribute does not apply to variables (%qD)", name, *node);
107995 + return NULL_TREE;
107996 + }
107997 +
107998 + if (TYPE_P(*node)) {
107999 + type = *node;
108000 + } else {
108001 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
108002 + type = TREE_TYPE(*node);
108003 + }
108004 +
108005 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
108006 + error("%qE attribute used on %qT applies to struct and union types only", name, type);
108007 + return NULL_TREE;
108008 + }
108009 +
108010 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
108011 + error("%qE attribute is already applied to the type %qT", name, type);
108012 + return NULL_TREE;
108013 + }
108014 +
108015 + if (TYPE_P(*node)) {
108016 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
108017 + error("%qE attribute used on type %qT is incompatible with 'do_const'", name, type);
108018 + else
108019 + *no_add_attrs = false;
108020 + return NULL_TREE;
108021 + }
108022 +
108023 + constifiable(type, &cinfo);
108024 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
108025 + deconstify_tree(*node);
108026 + TYPE_CONSTIFY_VISITED(TREE_TYPE(*node)) = 1;
108027 + return NULL_TREE;
108028 + }
108029 +
108030 + error("%qE attribute used on type %qT that is not constified", name, type);
108031 + return NULL_TREE;
108032 +}
108033 +
108034 +static void constify_type(tree type)
108035 +{
108036 + TYPE_READONLY(type) = 1;
108037 + C_TYPE_FIELDS_READONLY(type) = 1;
108038 + TYPE_CONSTIFY_VISITED(type) = 1;
108039 +// TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
108040 +// TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("do_const"), NULL_TREE, TYPE_ATTRIBUTES(type));
108041 +}
108042 +
108043 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
108044 +{
108045 + *no_add_attrs = true;
108046 + if (!TYPE_P(*node)) {
108047 + error("%qE attribute applies to types only (%qD)", name, *node);
108048 + return NULL_TREE;
108049 + }
108050 +
108051 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
108052 + error("%qE attribute used on %qT applies to struct and union types only", name, *node);
108053 + return NULL_TREE;
108054 + }
108055 +
108056 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(*node))) {
108057 + error("%qE attribute used on %qT is already applied to the type", name, *node);
108058 + return NULL_TREE;
108059 + }
108060 +
108061 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(*node))) {
108062 + error("%qE attribute used on %qT is incompatible with 'no_const'", name, *node);
108063 + return NULL_TREE;
108064 + }
108065 +
108066 + *no_add_attrs = false;
108067 + return NULL_TREE;
108068 +}
108069 +
108070 +static struct attribute_spec no_const_attr = {
108071 + .name = "no_const",
108072 + .min_length = 0,
108073 + .max_length = 0,
108074 + .decl_required = false,
108075 + .type_required = false,
108076 + .function_type_required = false,
108077 + .handler = handle_no_const_attribute,
108078 +#if BUILDING_GCC_VERSION >= 4007
108079 + .affects_type_identity = true
108080 +#endif
108081 +};
108082 +
108083 +static struct attribute_spec do_const_attr = {
108084 + .name = "do_const",
108085 + .min_length = 0,
108086 + .max_length = 0,
108087 + .decl_required = false,
108088 + .type_required = false,
108089 + .function_type_required = false,
108090 + .handler = handle_do_const_attribute,
108091 +#if BUILDING_GCC_VERSION >= 4007
108092 + .affects_type_identity = true
108093 +#endif
108094 +};
108095 +
108096 +static void register_attributes(void *event_data, void *data)
108097 +{
108098 + register_attribute(&no_const_attr);
108099 + register_attribute(&do_const_attr);
108100 +}
108101 +
108102 +static void finish_type(void *event_data, void *data)
108103 +{
108104 + tree type = (tree)event_data;
108105 + constify_info cinfo = {
108106 + .has_fptr_field = false,
108107 + .has_writable_field = false,
108108 + .has_do_const_field = false,
108109 + .has_no_const_field = false
108110 + };
108111 +
108112 + if (type == NULL_TREE || type == error_mark_node)
108113 + return;
108114 +
108115 + if (TYPE_FIELDS(type) == NULL_TREE || TYPE_CONSTIFY_VISITED(type))
108116 + return;
108117 +
108118 + constifiable(type, &cinfo);
108119 +
108120 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type))) {
108121 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || cinfo.has_do_const_field) {
108122 + deconstify_type(type);
108123 + TYPE_CONSTIFY_VISITED(type) = 1;
108124 + } else
108125 + error("'no_const' attribute used on type %qT that is not constified", type);
108126 + return;
108127 + }
108128 +
108129 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
108130 + if (!cinfo.has_writable_field) {
108131 + error("'do_const' attribute used on type %qT that is%sconstified", type, cinfo.has_fptr_field ? " " : " not ");
108132 + return;
108133 + }
108134 + constify_type(type);
108135 + return;
108136 + }
108137 +
108138 + if (cinfo.has_fptr_field && !cinfo.has_writable_field) {
108139 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
108140 + error("'do_const' attribute used on type %qT that is constified", type);
108141 + return;
108142 + }
108143 + constify_type(type);
108144 + return;
108145 + }
108146 +
108147 + deconstify_type(type);
108148 + TYPE_CONSTIFY_VISITED(type) = 1;
108149 +}
108150 +
108151 +static void check_global_variables(void *event_data, void *data)
108152 +{
108153 +#if BUILDING_GCC_VERSION >= 4009
108154 + varpool_node *node;
108155 +#else
108156 + struct varpool_node *node;
108157 +#endif
108158 +
108159 + FOR_EACH_VARIABLE(node) {
108160 + tree var = NODE_DECL(node);
108161 + tree type = TREE_TYPE(var);
108162 +
108163 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
108164 + continue;
108165 +
108166 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
108167 + continue;
108168 +
108169 + if (!TYPE_CONSTIFY_VISITED(type))
108170 + continue;
108171 +
108172 + if (DECL_EXTERNAL(var))
108173 + continue;
108174 +
108175 + if (DECL_INITIAL(var))
108176 + continue;
108177 +
108178 + // this works around a gcc bug/feature where uninitialized globals
108179 + // are moved into the .bss section regardless of any constification
108180 + DECL_INITIAL(var) = build_constructor(type, NULL);
108181 +// inform(DECL_SOURCE_LOCATION(var), "constified variable %qE moved into .rodata", var);
108182 + }
108183 +}
108184 +
108185 +static unsigned int check_local_variables(void)
108186 +{
108187 + unsigned int ret = 0;
108188 + tree var;
108189 +
108190 + unsigned int i;
108191 +
108192 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
108193 + tree type = TREE_TYPE(var);
108194 +
108195 + gcc_assert(DECL_P(var));
108196 + if (is_global_var(var))
108197 + continue;
108198 +
108199 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
108200 + continue;
108201 +
108202 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
108203 + continue;
108204 +
108205 + if (!TYPE_CONSTIFY_VISITED(type))
108206 + continue;
108207 +
108208 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
108209 + ret = 1;
108210 + }
108211 + return ret;
108212 +}
108213 +
108214 +#if BUILDING_GCC_VERSION >= 4009
108215 +static const struct pass_data check_local_variables_pass_data = {
108216 +#else
108217 +static struct gimple_opt_pass check_local_variables_pass = {
108218 + .pass = {
108219 +#endif
108220 + .type = GIMPLE_PASS,
108221 + .name = "check_local_variables",
108222 +#if BUILDING_GCC_VERSION >= 4008
108223 + .optinfo_flags = OPTGROUP_NONE,
108224 +#endif
108225 +#if BUILDING_GCC_VERSION >= 4009
108226 + .has_gate = false,
108227 + .has_execute = true,
108228 +#else
108229 + .gate = NULL,
108230 + .execute = check_local_variables,
108231 + .sub = NULL,
108232 + .next = NULL,
108233 + .static_pass_number = 0,
108234 +#endif
108235 + .tv_id = TV_NONE,
108236 + .properties_required = 0,
108237 + .properties_provided = 0,
108238 + .properties_destroyed = 0,
108239 + .todo_flags_start = 0,
108240 + .todo_flags_finish = 0
108241 +#if BUILDING_GCC_VERSION < 4009
108242 + }
108243 +#endif
108244 +};
108245 +
108246 +#if BUILDING_GCC_VERSION >= 4009
108247 +namespace {
108248 +class check_local_variables_pass : public gimple_opt_pass {
108249 +public:
108250 + check_local_variables_pass() : gimple_opt_pass(check_local_variables_pass_data, g) {}
108251 + unsigned int execute() { return check_local_variables(); }
108252 +};
108253 +}
108254 +
108255 +static opt_pass *make_check_local_variables_pass(void)
108256 +{
108257 + return new check_local_variables_pass();
108258 +}
108259 +#else
108260 +static struct opt_pass *make_check_local_variables_pass(void)
108261 +{
108262 + return &check_local_variables_pass.pass;
108263 +}
108264 +#endif
108265 +
108266 +static struct {
108267 + const char *name;
108268 + const char *asm_op;
108269 +} sections[] = {
108270 + {".init.rodata", "\t.section\t.init.rodata,\"a\""},
108271 + {".ref.rodata", "\t.section\t.ref.rodata,\"a\""},
108272 + {".devinit.rodata", "\t.section\t.devinit.rodata,\"a\""},
108273 + {".devexit.rodata", "\t.section\t.devexit.rodata,\"a\""},
108274 + {".cpuinit.rodata", "\t.section\t.cpuinit.rodata,\"a\""},
108275 + {".cpuexit.rodata", "\t.section\t.cpuexit.rodata,\"a\""},
108276 + {".meminit.rodata", "\t.section\t.meminit.rodata,\"a\""},
108277 + {".memexit.rodata", "\t.section\t.memexit.rodata,\"a\""},
108278 + {".data..read_only", "\t.section\t.data..read_only,\"a\""},
108279 +};
108280 +
108281 +static unsigned int (*old_section_type_flags)(tree decl, const char *name, int reloc);
108282 +
108283 +static unsigned int constify_section_type_flags(tree decl, const char *name, int reloc)
108284 +{
108285 + size_t i;
108286 +
108287 + for (i = 0; i < ARRAY_SIZE(sections); i++)
108288 + if (!strcmp(sections[i].name, name))
108289 + return 0;
108290 + return old_section_type_flags(decl, name, reloc);
108291 +}
108292 +
108293 +static void constify_start_unit(void *gcc_data, void *user_data)
108294 +{
108295 +// size_t i;
108296 +
108297 +// for (i = 0; i < ARRAY_SIZE(sections); i++)
108298 +// sections[i].section = get_unnamed_section(0, output_section_asm_op, sections[i].asm_op);
108299 +// sections[i].section = get_section(sections[i].name, 0, NULL);
108300 +
108301 + old_section_type_flags = targetm.section_type_flags;
108302 + targetm.section_type_flags = constify_section_type_flags;
108303 +}
108304 +
108305 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
108306 +{
108307 + const char * const plugin_name = plugin_info->base_name;
108308 + const int argc = plugin_info->argc;
108309 + const struct plugin_argument * const argv = plugin_info->argv;
108310 + int i;
108311 + bool constify = true;
108312 +
108313 + struct register_pass_info check_local_variables_pass_info;
108314 +
108315 + check_local_variables_pass_info.pass = make_check_local_variables_pass();
108316 + check_local_variables_pass_info.reference_pass_name = "ssa";
108317 + check_local_variables_pass_info.ref_pass_instance_number = 1;
108318 + check_local_variables_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
108319 +
108320 + if (!plugin_default_version_check(version, &gcc_version)) {
108321 + error(G_("incompatible gcc/plugin versions"));
108322 + return 1;
108323 + }
108324 +
108325 + for (i = 0; i < argc; ++i) {
108326 + if (!(strcmp(argv[i].key, "no-constify"))) {
108327 + constify = false;
108328 + continue;
108329 + }
108330 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
108331 + }
108332 +
108333 + if (strcmp(lang_hooks.name, "GNU C")) {
108334 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
108335 + constify = false;
108336 + }
108337 +
108338 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
108339 + if (constify) {
108340 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
108341 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
108342 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &check_local_variables_pass_info);
108343 + register_callback(plugin_name, PLUGIN_START_UNIT, constify_start_unit, NULL);
108344 + }
108345 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
108346 +
108347 + return 0;
108348 +}
108349 diff --git a/tools/gcc/gcc-common.h b/tools/gcc/gcc-common.h
108350 new file mode 100644
108351 index 0000000..e90c205
108352 --- /dev/null
108353 +++ b/tools/gcc/gcc-common.h
108354 @@ -0,0 +1,295 @@
108355 +#ifndef GCC_COMMON_H_INCLUDED
108356 +#define GCC_COMMON_H_INCLUDED
108357 +
108358 +#include "plugin.h"
108359 +#include "bversion.h"
108360 +#include "plugin-version.h"
108361 +#include "config.h"
108362 +#include "system.h"
108363 +#include "coretypes.h"
108364 +#include "tm.h"
108365 +#include "line-map.h"
108366 +#include "input.h"
108367 +#include "tree.h"
108368 +
108369 +#include "tree-inline.h"
108370 +#include "version.h"
108371 +#include "rtl.h"
108372 +#include "tm_p.h"
108373 +#include "flags.h"
108374 +//#include "insn-attr.h"
108375 +//#include "insn-config.h"
108376 +//#include "insn-flags.h"
108377 +#include "hard-reg-set.h"
108378 +//#include "recog.h"
108379 +#include "output.h"
108380 +#include "except.h"
108381 +#include "function.h"
108382 +#include "toplev.h"
108383 +//#include "expr.h"
108384 +#include "basic-block.h"
108385 +#include "intl.h"
108386 +#include "ggc.h"
108387 +//#include "regs.h"
108388 +#include "timevar.h"
108389 +
108390 +#include "params.h"
108391 +#include "pointer-set.h"
108392 +#include "emit-rtl.h"
108393 +//#include "reload.h"
108394 +//#include "ira.h"
108395 +//#include "dwarf2asm.h"
108396 +#include "debug.h"
108397 +#include "target.h"
108398 +#include "langhooks.h"
108399 +#include "cfgloop.h"
108400 +//#include "hosthooks.h"
108401 +#include "cgraph.h"
108402 +#include "opts.h"
108403 +//#include "coverage.h"
108404 +//#include "value-prof.h"
108405 +
108406 +#if BUILDING_GCC_VERSION >= 4007
108407 +#include "tree-pretty-print.h"
108408 +#include "gimple-pretty-print.h"
108409 +#include "c-tree.h"
108410 +//#include "alloc-pool.h"
108411 +#endif
108412 +
108413 +#if BUILDING_GCC_VERSION <= 4008
108414 +#include "tree-flow.h"
108415 +#else
108416 +#include "tree-cfgcleanup.h"
108417 +#endif
108418 +
108419 +#include "diagnostic.h"
108420 +//#include "tree-diagnostic.h"
108421 +#include "tree-dump.h"
108422 +#include "tree-pass.h"
108423 +//#include "df.h"
108424 +#include "predict.h"
108425 +#include "ipa-utils.h"
108426 +
108427 +#if BUILDING_GCC_VERSION >= 4009
108428 +#include "varasm.h"
108429 +#include "stor-layout.h"
108430 +#include "internal-fn.h"
108431 +#include "gimple-expr.h"
108432 +//#include "diagnostic-color.h"
108433 +#include "context.h"
108434 +#include "tree-ssa-alias.h"
108435 +#include "stringpool.h"
108436 +#include "tree-ssanames.h"
108437 +#include "print-tree.h"
108438 +#include "tree-eh.h"
108439 +#include "stmt.h"
108440 +#endif
108441 +
108442 +#include "gimple.h"
108443 +
108444 +#if BUILDING_GCC_VERSION >= 4009
108445 +#include "tree-ssa-operands.h"
108446 +#include "tree-phinodes.h"
108447 +#include "tree-cfg.h"
108448 +#include "gimple-iterator.h"
108449 +#include "gimple-ssa.h"
108450 +#include "ssa-iterators.h"
108451 +#endif
108452 +
108453 +//#include "lto/lto.h"
108454 +//#include "data-streamer.h"
108455 +//#include "lto-compress.h"
108456 +
108457 +//#include "expr.h" where are you...
108458 +extern rtx emit_move_insn(rtx x, rtx y);
108459 +
108460 +// missing from basic_block.h...
108461 +extern void debug_dominance_info(enum cdi_direction dir);
108462 +extern void debug_dominance_tree(enum cdi_direction dir, basic_block root);
108463 +
108464 +#define __unused __attribute__((__unused__))
108465 +
108466 +#define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
108467 +#define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
108468 +#define TYPE_NAME_POINTER(node) IDENTIFIER_POINTER(TYPE_NAME(node))
108469 +#define TYPE_NAME_LENGTH(node) IDENTIFIER_LENGTH(TYPE_NAME(node))
108470 +
108471 +#if BUILDING_GCC_VERSION == 4005
108472 +#define FOR_EACH_LOCAL_DECL(FUN, I, D) for (tree vars = (FUN)->local_decls; vars && (D = TREE_VALUE(vars)); vars = TREE_CHAIN(vars), I)
108473 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
108474 +#define FOR_EACH_VEC_ELT(T, V, I, P) for (I = 0; VEC_iterate(T, (V), (I), (P)); ++(I))
108475 +#define TODO_rebuild_cgraph_edges 0
108476 +
108477 +static inline bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
108478 +{
108479 + tree fndecl;
108480 +
108481 + if (!is_gimple_call(stmt))
108482 + return false;
108483 + fndecl = gimple_call_fndecl(stmt);
108484 + if (!fndecl || DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
108485 + return false;
108486 +// print_node(stderr, "pax", fndecl, 4);
108487 + return DECL_FUNCTION_CODE(fndecl) == code;
108488 +}
108489 +
108490 +static inline bool is_simple_builtin(tree decl)
108491 +{
108492 + if (decl && DECL_BUILT_IN_CLASS(decl) != BUILT_IN_NORMAL)
108493 + return false;
108494 +
108495 + switch (DECL_FUNCTION_CODE(decl)) {
108496 + /* Builtins that expand to constants. */
108497 + case BUILT_IN_CONSTANT_P:
108498 + case BUILT_IN_EXPECT:
108499 + case BUILT_IN_OBJECT_SIZE:
108500 + case BUILT_IN_UNREACHABLE:
108501 + /* Simple register moves or loads from stack. */
108502 + case BUILT_IN_RETURN_ADDRESS:
108503 + case BUILT_IN_EXTRACT_RETURN_ADDR:
108504 + case BUILT_IN_FROB_RETURN_ADDR:
108505 + case BUILT_IN_RETURN:
108506 + case BUILT_IN_AGGREGATE_INCOMING_ADDRESS:
108507 + case BUILT_IN_FRAME_ADDRESS:
108508 + case BUILT_IN_VA_END:
108509 + case BUILT_IN_STACK_SAVE:
108510 + case BUILT_IN_STACK_RESTORE:
108511 + /* Exception state returns or moves registers around. */
108512 + case BUILT_IN_EH_FILTER:
108513 + case BUILT_IN_EH_POINTER:
108514 + case BUILT_IN_EH_COPY_VALUES:
108515 + return true;
108516 +
108517 + default:
108518 + return false;
108519 + }
108520 +}
108521 +#endif
108522 +
108523 +#if BUILDING_GCC_VERSION <= 4006
108524 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
108525 +#define C_DECL_REGISTER(EXP) DECL_LANG_FLAG_4(EXP)
108526 +
108527 +// should come from c-tree.h if only it were installed for gcc 4.5...
108528 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
108529 +
108530 +#define get_random_seed(noinit) ({ \
108531 + unsigned HOST_WIDE_INT seed; \
108532 + sscanf(get_random_seed(noinit), "%" HOST_WIDE_INT_PRINT "x", &seed); \
108533 + seed * seed; })
108534 +
108535 +static inline bool gimple_clobber_p(gimple s)
108536 +{
108537 + return false;
108538 +}
108539 +
108540 +static inline tree builtin_decl_implicit(enum built_in_function fncode)
108541 +{
108542 + return implicit_built_in_decls[fncode];
108543 +}
108544 +
108545 +static inline struct cgraph_node *cgraph_get_create_node(tree decl)
108546 +{
108547 + struct cgraph_node *node = cgraph_get_node(decl);
108548 +
108549 + return node ? node : cgraph_node(decl);
108550 +}
108551 +
108552 +static inline bool cgraph_function_with_gimple_body_p(struct cgraph_node *node)
108553 +{
108554 + return node->analyzed && !node->thunk.thunk_p && !node->alias;
108555 +}
108556 +
108557 +static inline struct cgraph_node *cgraph_first_function_with_gimple_body(void)
108558 +{
108559 + struct cgraph_node *node;
108560 +
108561 + for (node = cgraph_nodes; node; node = node->next)
108562 + if (cgraph_function_with_gimple_body_p(node))
108563 + return node;
108564 + return NULL;
108565 +}
108566 +
108567 +static inline struct cgraph_node *cgraph_next_function_with_gimple_body(struct cgraph_node *node)
108568 +{
108569 + for (node = node->next; node; node = node->next)
108570 + if (cgraph_function_with_gimple_body_p(node))
108571 + return node;
108572 + return NULL;
108573 +}
108574 +
108575 +#define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
108576 + for ((node) = cgraph_first_function_with_gimple_body(); (node); \
108577 + (node) = cgraph_next_function_with_gimple_body(node))
108578 +#endif
108579 +
108580 +#if BUILDING_GCC_VERSION == 4006
108581 +extern void debug_gimple_stmt(gimple);
108582 +extern void debug_gimple_seq(gimple_seq);
108583 +extern void print_gimple_seq(FILE *, gimple_seq, int, int);
108584 +extern void print_gimple_stmt(FILE *, gimple, int, int);
108585 +extern void print_gimple_expr(FILE *, gimple, int, int);
108586 +extern void dump_gimple_stmt(pretty_printer *, gimple, int, int);
108587 +#endif
108588 +
108589 +#if BUILDING_GCC_VERSION <= 4007
108590 +#define FOR_EACH_VARIABLE(node) for (node = varpool_nodes; node; node = node->next)
108591 +#define PROP_loops 0
108592 +
108593 +static inline int bb_loop_depth(const_basic_block bb)
108594 +{
108595 + return bb->loop_father ? loop_depth(bb->loop_father) : 0;
108596 +}
108597 +
108598 +static inline bool gimple_store_p(gimple gs)
108599 +{
108600 + tree lhs = gimple_get_lhs(gs);
108601 + return lhs && !is_gimple_reg(lhs);
108602 +}
108603 +#endif
108604 +
108605 +#if BUILDING_GCC_VERSION >= 4007
108606 +#define cgraph_create_edge(caller, callee, call_stmt, count, freq, nest) \
108607 + cgraph_create_edge((caller), (callee), (call_stmt), (count), (freq))
108608 +#define cgraph_create_edge_including_clones(caller, callee, old_call_stmt, call_stmt, count, freq, nest, reason) \
108609 + cgraph_create_edge_including_clones((caller), (callee), (old_call_stmt), (call_stmt), (count), (freq), (reason))
108610 +#endif
108611 +
108612 +#if BUILDING_GCC_VERSION <= 4008
108613 +#define ENTRY_BLOCK_PTR_FOR_FN(FN) ENTRY_BLOCK_PTR_FOR_FUNCTION(FN)
108614 +#define EXIT_BLOCK_PTR_FOR_FN(FN) EXIT_BLOCK_PTR_FOR_FUNCTION(FN)
108615 +#define basic_block_info_for_fn(FN) ((FN)->cfg->x_basic_block_info)
108616 +#define n_basic_blocks_for_fn(FN) ((FN)->cfg->x_n_basic_blocks)
108617 +#define n_edges_for_fn(FN) ((FN)->cfg->x_n_edges)
108618 +#define last_basic_block_for_fn(FN) ((FN)->cfg->x_last_basic_block)
108619 +#define label_to_block_map_for_fn(FN) ((FN)->cfg->x_label_to_block_map)
108620 +#define profile_status_for_fn(FN) ((FN)->cfg->x_profile_status)
108621 +
108622 +static inline const char *get_tree_code_name(enum tree_code code)
108623 +{
108624 + gcc_assert(code < MAX_TREE_CODES);
108625 + return tree_code_name[code];
108626 +}
108627 +
108628 +#define ipa_remove_stmt_references(cnode, stmt)
108629 +#endif
108630 +
108631 +#if BUILDING_GCC_VERSION == 4008
108632 +#define NODE_DECL(node) node->symbol.decl
108633 +#else
108634 +#define NODE_DECL(node) node->decl
108635 +#endif
108636 +
108637 +#if BUILDING_GCC_VERSION >= 4008
108638 +#define add_referenced_var(var)
108639 +#define mark_sym_for_renaming(var)
108640 +#define varpool_mark_needed_node(node)
108641 +#define TODO_dump_func 0
108642 +#define TODO_dump_cgraph 0
108643 +#endif
108644 +
108645 +#if BUILDING_GCC_VERSION >= 4009
108646 +#define TODO_ggc_collect 0
108647 +#endif
108648 +
108649 +#endif
108650 diff --git a/tools/gcc/gen-random-seed.sh b/tools/gcc/gen-random-seed.sh
108651 new file mode 100644
108652 index 0000000..7514850
108653 --- /dev/null
108654 +++ b/tools/gcc/gen-random-seed.sh
108655 @@ -0,0 +1,8 @@
108656 +#!/bin/sh
108657 +
108658 +if [ ! -f "$1" ]; then
108659 + SEED=`od -A n -t x8 -N 32 /dev/urandom | tr -d ' \n'`
108660 + echo "const char *randstruct_seed = \"$SEED\";" > "$1"
108661 + HASH=`echo -n "$SEED" | sha256sum | cut -d" " -f1 | tr -d ' \n'`
108662 + echo "#define RANDSTRUCT_HASHED_SEED \"$HASH\"" > "$2"
108663 +fi
108664 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
108665 new file mode 100644
108666 index 0000000..d81c094
108667 --- /dev/null
108668 +++ b/tools/gcc/kallocstat_plugin.c
108669 @@ -0,0 +1,183 @@
108670 +/*
108671 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
108672 + * Licensed under the GPL v2
108673 + *
108674 + * Note: the choice of the license means that the compilation process is
108675 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
108676 + * but for the kernel it doesn't matter since it doesn't link against
108677 + * any of the gcc libraries
108678 + *
108679 + * gcc plugin to find the distribution of k*alloc sizes
108680 + *
108681 + * TODO:
108682 + *
108683 + * BUGS:
108684 + * - none known
108685 + */
108686 +
108687 +#include "gcc-common.h"
108688 +
108689 +int plugin_is_GPL_compatible;
108690 +
108691 +static struct plugin_info kallocstat_plugin_info = {
108692 + .version = "201401260140",
108693 + .help = NULL
108694 +};
108695 +
108696 +static const char * const kalloc_functions[] = {
108697 + "__kmalloc",
108698 + "kmalloc",
108699 + "kmalloc_large",
108700 + "kmalloc_node",
108701 + "kmalloc_order",
108702 + "kmalloc_order_trace",
108703 + "kmalloc_slab",
108704 + "kzalloc",
108705 + "kzalloc_node",
108706 +};
108707 +
108708 +static bool is_kalloc(const char *fnname)
108709 +{
108710 + size_t i;
108711 +
108712 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
108713 + if (!strcmp(fnname, kalloc_functions[i]))
108714 + return true;
108715 + return false;
108716 +}
108717 +
108718 +static unsigned int execute_kallocstat(void)
108719 +{
108720 + basic_block bb;
108721 +
108722 + // 1. loop through BBs and GIMPLE statements
108723 + FOR_EACH_BB_FN(bb, cfun) {
108724 + gimple_stmt_iterator gsi;
108725 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
108726 + // gimple match:
108727 + tree fndecl, size;
108728 + gimple stmt;
108729 + const char *fnname;
108730 +
108731 + // is it a call
108732 + stmt = gsi_stmt(gsi);
108733 + if (!is_gimple_call(stmt))
108734 + continue;
108735 + fndecl = gimple_call_fndecl(stmt);
108736 + if (fndecl == NULL_TREE)
108737 + continue;
108738 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
108739 + continue;
108740 +
108741 + // is it a call to k*alloc
108742 + fnname = DECL_NAME_POINTER(fndecl);
108743 + if (!is_kalloc(fnname))
108744 + continue;
108745 +
108746 + // is the size arg const or the result of a simple const assignment
108747 + size = gimple_call_arg(stmt, 0);
108748 + while (true) {
108749 + expanded_location xloc;
108750 + size_t size_val;
108751 +
108752 + if (TREE_CONSTANT(size)) {
108753 + xloc = expand_location(gimple_location(stmt));
108754 + if (!xloc.file)
108755 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
108756 + size_val = TREE_INT_CST_LOW(size);
108757 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
108758 + break;
108759 + }
108760 +
108761 + if (TREE_CODE(size) != SSA_NAME)
108762 + break;
108763 + stmt = SSA_NAME_DEF_STMT(size);
108764 +//debug_gimple_stmt(stmt);
108765 +//debug_tree(size);
108766 + if (!stmt || !is_gimple_assign(stmt))
108767 + break;
108768 + if (gimple_num_ops(stmt) != 2)
108769 + break;
108770 + size = gimple_assign_rhs1(stmt);
108771 + }
108772 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
108773 +//debug_tree(gimple_call_fn(call_stmt));
108774 +//print_node(stderr, "pax", fndecl, 4);
108775 + }
108776 + }
108777 +
108778 + return 0;
108779 +}
108780 +
108781 +#if BUILDING_GCC_VERSION >= 4009
108782 +static const struct pass_data kallocstat_pass_data = {
108783 +#else
108784 +static struct gimple_opt_pass kallocstat_pass = {
108785 + .pass = {
108786 +#endif
108787 + .type = GIMPLE_PASS,
108788 + .name = "kallocstat",
108789 +#if BUILDING_GCC_VERSION >= 4008
108790 + .optinfo_flags = OPTGROUP_NONE,
108791 +#endif
108792 +#if BUILDING_GCC_VERSION >= 4009
108793 + .has_gate = false,
108794 + .has_execute = true,
108795 +#else
108796 + .gate = NULL,
108797 + .execute = execute_kallocstat,
108798 + .sub = NULL,
108799 + .next = NULL,
108800 + .static_pass_number = 0,
108801 +#endif
108802 + .tv_id = TV_NONE,
108803 + .properties_required = 0,
108804 + .properties_provided = 0,
108805 + .properties_destroyed = 0,
108806 + .todo_flags_start = 0,
108807 + .todo_flags_finish = 0
108808 +#if BUILDING_GCC_VERSION < 4009
108809 + }
108810 +#endif
108811 +};
108812 +
108813 +#if BUILDING_GCC_VERSION >= 4009
108814 +namespace {
108815 +class kallocstat_pass : public gimple_opt_pass {
108816 +public:
108817 + kallocstat_pass() : gimple_opt_pass(kallocstat_pass_data, g) {}
108818 + unsigned int execute() { return execute_kallocstat(); }
108819 +};
108820 +}
108821 +
108822 +static opt_pass *make_kallocstat_pass(void)
108823 +{
108824 + return new kallocstat_pass();
108825 +}
108826 +#else
108827 +static struct opt_pass *make_kallocstat_pass(void)
108828 +{
108829 + return &kallocstat_pass.pass;
108830 +}
108831 +#endif
108832 +
108833 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
108834 +{
108835 + const char * const plugin_name = plugin_info->base_name;
108836 + struct register_pass_info kallocstat_pass_info;
108837 +
108838 + kallocstat_pass_info.pass = make_kallocstat_pass();
108839 + kallocstat_pass_info.reference_pass_name = "ssa";
108840 + kallocstat_pass_info.ref_pass_instance_number = 1;
108841 + kallocstat_pass_info.pos_op = PASS_POS_INSERT_AFTER;
108842 +
108843 + if (!plugin_default_version_check(version, &gcc_version)) {
108844 + error(G_("incompatible gcc/plugin versions"));
108845 + return 1;
108846 + }
108847 +
108848 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
108849 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
108850 +
108851 + return 0;
108852 +}
108853 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
108854 new file mode 100644
108855 index 0000000..89f256d
108856 --- /dev/null
108857 +++ b/tools/gcc/kernexec_plugin.c
108858 @@ -0,0 +1,522 @@
108859 +/*
108860 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
108861 + * Licensed under the GPL v2
108862 + *
108863 + * Note: the choice of the license means that the compilation process is
108864 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
108865 + * but for the kernel it doesn't matter since it doesn't link against
108866 + * any of the gcc libraries
108867 + *
108868 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
108869 + *
108870 + * TODO:
108871 + *
108872 + * BUGS:
108873 + * - none known
108874 + */
108875 +
108876 +#include "gcc-common.h"
108877 +
108878 +int plugin_is_GPL_compatible;
108879 +
108880 +static struct plugin_info kernexec_plugin_info = {
108881 + .version = "201401260140",
108882 + .help = "method=[bts|or]\tinstrumentation method\n"
108883 +};
108884 +
108885 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
108886 +static void (*kernexec_instrument_retaddr)(rtx);
108887 +
108888 +/*
108889 + * add special KERNEXEC instrumentation: reload %r12 after it has been clobbered
108890 + */
108891 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
108892 +{
108893 + gimple asm_movabs_stmt;
108894 +
108895 + // build asm volatile("movabs $0x8000000000000000, %%r12\n\t" : : : );
108896 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r12\n\t", NULL, NULL, NULL, NULL);
108897 + gimple_asm_set_volatile(asm_movabs_stmt, true);
108898 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
108899 + update_stmt(asm_movabs_stmt);
108900 +}
108901 +
108902 +/*
108903 + * find all asm() stmts that clobber r12 and add a reload of r12
108904 + */
108905 +static unsigned int execute_kernexec_reload(void)
108906 +{
108907 + basic_block bb;
108908 +
108909 + // 1. loop through BBs and GIMPLE statements
108910 + FOR_EACH_BB_FN(bb, cfun) {
108911 + gimple_stmt_iterator gsi;
108912 +
108913 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
108914 + // gimple match: __asm__ ("" : : : "r12");
108915 + gimple asm_stmt;
108916 + size_t nclobbers;
108917 +
108918 + // is it an asm ...
108919 + asm_stmt = gsi_stmt(gsi);
108920 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
108921 + continue;
108922 +
108923 + // ... clobbering r12
108924 + nclobbers = gimple_asm_nclobbers(asm_stmt);
108925 + while (nclobbers--) {
108926 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
108927 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r12"))
108928 + continue;
108929 + kernexec_reload_fptr_mask(&gsi);
108930 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
108931 + break;
108932 + }
108933 + }
108934 + }
108935 +
108936 + return 0;
108937 +}
108938 +
108939 +/*
108940 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
108941 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
108942 + */
108943 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
108944 +{
108945 + gimple assign_intptr, assign_new_fptr, call_stmt;
108946 + tree intptr, orptr, old_fptr, new_fptr, kernexec_mask;
108947 +
108948 + call_stmt = gsi_stmt(*gsi);
108949 + old_fptr = gimple_call_fn(call_stmt);
108950 +
108951 + // create temporary unsigned long variable used for bitops and cast fptr to it
108952 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
108953 + add_referenced_var(intptr);
108954 + intptr = make_ssa_name(intptr, NULL);
108955 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
108956 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
108957 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
108958 + update_stmt(assign_intptr);
108959 +
108960 + // apply logical or to temporary unsigned long and bitmask
108961 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
108962 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
108963 + orptr = fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask);
108964 + intptr = make_ssa_name(SSA_NAME_VAR(intptr), NULL);
108965 + assign_intptr = gimple_build_assign(intptr, orptr);
108966 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
108967 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
108968 + update_stmt(assign_intptr);
108969 +
108970 + // cast temporary unsigned long back to a temporary fptr variable
108971 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
108972 + add_referenced_var(new_fptr);
108973 + new_fptr = make_ssa_name(new_fptr, NULL);
108974 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
108975 + SSA_NAME_DEF_STMT(new_fptr) = assign_new_fptr;
108976 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
108977 + update_stmt(assign_new_fptr);
108978 +
108979 + // replace call stmt fn with the new fptr
108980 + gimple_call_set_fn(call_stmt, new_fptr);
108981 + update_stmt(call_stmt);
108982 +}
108983 +
108984 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
108985 +{
108986 + gimple asm_or_stmt, call_stmt;
108987 + tree old_fptr, new_fptr, input, output;
108988 +#if BUILDING_GCC_VERSION <= 4007
108989 + VEC(tree, gc) *inputs = NULL;
108990 + VEC(tree, gc) *outputs = NULL;
108991 +#else
108992 + vec<tree, va_gc> *inputs = NULL;
108993 + vec<tree, va_gc> *outputs = NULL;
108994 +#endif
108995 +
108996 + call_stmt = gsi_stmt(*gsi);
108997 + old_fptr = gimple_call_fn(call_stmt);
108998 +
108999 + // create temporary fptr variable
109000 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
109001 + add_referenced_var(new_fptr);
109002 + new_fptr = make_ssa_name(new_fptr, NULL);
109003 +
109004 + // build asm volatile("orq %%r12, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
109005 + input = build_tree_list(NULL_TREE, build_string(1, "0"));
109006 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
109007 + output = build_tree_list(NULL_TREE, build_string(2, "=r"));
109008 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
109009 +#if BUILDING_GCC_VERSION <= 4007
109010 + VEC_safe_push(tree, gc, inputs, input);
109011 + VEC_safe_push(tree, gc, outputs, output);
109012 +#else
109013 + vec_safe_push(inputs, input);
109014 + vec_safe_push(outputs, output);
109015 +#endif
109016 + asm_or_stmt = gimple_build_asm_vec("orq %%r12, %0\n\t", inputs, outputs, NULL, NULL);
109017 + SSA_NAME_DEF_STMT(new_fptr) = asm_or_stmt;
109018 + gimple_asm_set_volatile(asm_or_stmt, true);
109019 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
109020 + update_stmt(asm_or_stmt);
109021 +
109022 + // replace call stmt fn with the new fptr
109023 + gimple_call_set_fn(call_stmt, new_fptr);
109024 + update_stmt(call_stmt);
109025 +}
109026 +
109027 +/*
109028 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
109029 + */
109030 +static unsigned int execute_kernexec_fptr(void)
109031 +{
109032 + basic_block bb;
109033 +
109034 + // 1. loop through BBs and GIMPLE statements
109035 + FOR_EACH_BB_FN(bb, cfun) {
109036 + gimple_stmt_iterator gsi;
109037 +
109038 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
109039 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
109040 + tree fn;
109041 + gimple call_stmt;
109042 +
109043 + // is it a call ...
109044 + call_stmt = gsi_stmt(gsi);
109045 + if (!is_gimple_call(call_stmt))
109046 + continue;
109047 + fn = gimple_call_fn(call_stmt);
109048 + if (TREE_CODE(fn) == ADDR_EXPR)
109049 + continue;
109050 + if (TREE_CODE(fn) != SSA_NAME)
109051 + gcc_unreachable();
109052 +
109053 + // ... through a function pointer
109054 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
109055 + fn = SSA_NAME_VAR(fn);
109056 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
109057 + debug_tree(fn);
109058 + gcc_unreachable();
109059 + }
109060 + }
109061 + fn = TREE_TYPE(fn);
109062 + if (TREE_CODE(fn) != POINTER_TYPE)
109063 + continue;
109064 + fn = TREE_TYPE(fn);
109065 + if (TREE_CODE(fn) != FUNCTION_TYPE)
109066 + continue;
109067 +
109068 + kernexec_instrument_fptr(&gsi);
109069 +
109070 +//debug_tree(gimple_call_fn(call_stmt));
109071 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
109072 + }
109073 + }
109074 +
109075 + return 0;
109076 +}
109077 +
109078 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
109079 +static void kernexec_instrument_retaddr_bts(rtx insn)
109080 +{
109081 + rtx btsq;
109082 + rtvec argvec, constraintvec, labelvec;
109083 + int line;
109084 +
109085 + // create asm volatile("btsq $63,(%%rsp)":::)
109086 + argvec = rtvec_alloc(0);
109087 + constraintvec = rtvec_alloc(0);
109088 + labelvec = rtvec_alloc(0);
109089 + line = expand_location(RTL_LOCATION(insn)).line;
109090 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
109091 + MEM_VOLATILE_P(btsq) = 1;
109092 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
109093 + emit_insn_before(btsq, insn);
109094 +}
109095 +
109096 +// add special KERNEXEC instrumentation: orq %r12,(%rsp) just before retn
109097 +static void kernexec_instrument_retaddr_or(rtx insn)
109098 +{
109099 + rtx orq;
109100 + rtvec argvec, constraintvec, labelvec;
109101 + int line;
109102 +
109103 + // create asm volatile("orq %%r12,(%%rsp)":::)
109104 + argvec = rtvec_alloc(0);
109105 + constraintvec = rtvec_alloc(0);
109106 + labelvec = rtvec_alloc(0);
109107 + line = expand_location(RTL_LOCATION(insn)).line;
109108 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r12,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
109109 + MEM_VOLATILE_P(orq) = 1;
109110 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
109111 + emit_insn_before(orq, insn);
109112 +}
109113 +
109114 +/*
109115 + * find all asm level function returns and forcibly set the highest bit of the return address
109116 + */
109117 +static unsigned int execute_kernexec_retaddr(void)
109118 +{
109119 + rtx insn;
109120 +
109121 +// if (stack_realign_drap)
109122 +// inform(DECL_SOURCE_LOCATION(current_function_decl), "drap detected in %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
109123 +
109124 + // 1. find function returns
109125 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
109126 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
109127 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
109128 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
109129 + rtx body;
109130 +
109131 + // is it a retn
109132 + if (!JUMP_P(insn))
109133 + continue;
109134 + body = PATTERN(insn);
109135 + if (GET_CODE(body) == PARALLEL)
109136 + body = XVECEXP(body, 0, 0);
109137 + if (!ANY_RETURN_P(body))
109138 + continue;
109139 + kernexec_instrument_retaddr(insn);
109140 + }
109141 +
109142 +// print_simple_rtl(stderr, get_insns());
109143 +// print_rtl(stderr, get_insns());
109144 +
109145 + return 0;
109146 +}
109147 +
109148 +static bool kernexec_cmodel_check(void)
109149 +{
109150 + tree section;
109151 +
109152 + if (ix86_cmodel != CM_KERNEL)
109153 + return false;
109154 +
109155 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
109156 + if (!section || !TREE_VALUE(section))
109157 + return true;
109158 +
109159 + section = TREE_VALUE(TREE_VALUE(section));
109160 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
109161 + return true;
109162 +
109163 + return false;
109164 +}
109165 +
109166 +#if BUILDING_GCC_VERSION >= 4009
109167 +static const struct pass_data kernexec_reload_pass_data = {
109168 +#else
109169 +static struct gimple_opt_pass kernexec_reload_pass = {
109170 + .pass = {
109171 +#endif
109172 + .type = GIMPLE_PASS,
109173 + .name = "kernexec_reload",
109174 +#if BUILDING_GCC_VERSION >= 4008
109175 + .optinfo_flags = OPTGROUP_NONE,
109176 +#endif
109177 +#if BUILDING_GCC_VERSION >= 4009
109178 + .has_gate = true,
109179 + .has_execute = true,
109180 +#else
109181 + .gate = kernexec_cmodel_check,
109182 + .execute = execute_kernexec_reload,
109183 + .sub = NULL,
109184 + .next = NULL,
109185 + .static_pass_number = 0,
109186 +#endif
109187 + .tv_id = TV_NONE,
109188 + .properties_required = 0,
109189 + .properties_provided = 0,
109190 + .properties_destroyed = 0,
109191 + .todo_flags_start = 0,
109192 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
109193 +#if BUILDING_GCC_VERSION < 4009
109194 + }
109195 +#endif
109196 +};
109197 +
109198 +#if BUILDING_GCC_VERSION >= 4009
109199 +static const struct pass_data kernexec_fptr_pass_data = {
109200 +#else
109201 +static struct gimple_opt_pass kernexec_fptr_pass = {
109202 + .pass = {
109203 +#endif
109204 + .type = GIMPLE_PASS,
109205 + .name = "kernexec_fptr",
109206 +#if BUILDING_GCC_VERSION >= 4008
109207 + .optinfo_flags = OPTGROUP_NONE,
109208 +#endif
109209 +#if BUILDING_GCC_VERSION >= 4009
109210 + .has_gate = true,
109211 + .has_execute = true,
109212 +#else
109213 + .gate = kernexec_cmodel_check,
109214 + .execute = execute_kernexec_fptr,
109215 + .sub = NULL,
109216 + .next = NULL,
109217 + .static_pass_number = 0,
109218 +#endif
109219 + .tv_id = TV_NONE,
109220 + .properties_required = 0,
109221 + .properties_provided = 0,
109222 + .properties_destroyed = 0,
109223 + .todo_flags_start = 0,
109224 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
109225 +#if BUILDING_GCC_VERSION < 4009
109226 + }
109227 +#endif
109228 +};
109229 +
109230 +#if BUILDING_GCC_VERSION >= 4009
109231 +static const struct pass_data kernexec_retaddr_pass_data = {
109232 +#else
109233 +static struct rtl_opt_pass kernexec_retaddr_pass = {
109234 + .pass = {
109235 +#endif
109236 + .type = RTL_PASS,
109237 + .name = "kernexec_retaddr",
109238 +#if BUILDING_GCC_VERSION >= 4008
109239 + .optinfo_flags = OPTGROUP_NONE,
109240 +#endif
109241 +#if BUILDING_GCC_VERSION >= 4009
109242 + .has_gate = true,
109243 + .has_execute = true,
109244 +#else
109245 + .gate = kernexec_cmodel_check,
109246 + .execute = execute_kernexec_retaddr,
109247 + .sub = NULL,
109248 + .next = NULL,
109249 + .static_pass_number = 0,
109250 +#endif
109251 + .tv_id = TV_NONE,
109252 + .properties_required = 0,
109253 + .properties_provided = 0,
109254 + .properties_destroyed = 0,
109255 + .todo_flags_start = 0,
109256 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
109257 +#if BUILDING_GCC_VERSION < 4009
109258 + }
109259 +#endif
109260 +};
109261 +
109262 +#if BUILDING_GCC_VERSION >= 4009
109263 +namespace {
109264 +class kernexec_reload_pass : public gimple_opt_pass {
109265 +public:
109266 + kernexec_reload_pass() : gimple_opt_pass(kernexec_reload_pass_data, g) {}
109267 + bool gate() { return kernexec_cmodel_check(); }
109268 + unsigned int execute() { return execute_kernexec_reload(); }
109269 +};
109270 +
109271 +class kernexec_fptr_pass : public gimple_opt_pass {
109272 +public:
109273 + kernexec_fptr_pass() : gimple_opt_pass(kernexec_fptr_pass_data, g) {}
109274 + bool gate() { return kernexec_cmodel_check(); }
109275 + unsigned int execute() { return execute_kernexec_fptr(); }
109276 +};
109277 +
109278 +class kernexec_retaddr_pass : public rtl_opt_pass {
109279 +public:
109280 + kernexec_retaddr_pass() : rtl_opt_pass(kernexec_retaddr_pass_data, g) {}
109281 + bool gate() { return kernexec_cmodel_check(); }
109282 + unsigned int execute() { return execute_kernexec_retaddr(); }
109283 +};
109284 +}
109285 +
109286 +static opt_pass *make_kernexec_reload_pass(void)
109287 +{
109288 + return new kernexec_reload_pass();
109289 +}
109290 +
109291 +static opt_pass *make_kernexec_fptr_pass(void)
109292 +{
109293 + return new kernexec_fptr_pass();
109294 +}
109295 +
109296 +static opt_pass *make_kernexec_retaddr_pass(void)
109297 +{
109298 + return new kernexec_retaddr_pass();
109299 +}
109300 +#else
109301 +static struct opt_pass *make_kernexec_reload_pass(void)
109302 +{
109303 + return &kernexec_reload_pass.pass;
109304 +}
109305 +
109306 +static struct opt_pass *make_kernexec_fptr_pass(void)
109307 +{
109308 + return &kernexec_fptr_pass.pass;
109309 +}
109310 +
109311 +static struct opt_pass *make_kernexec_retaddr_pass(void)
109312 +{
109313 + return &kernexec_retaddr_pass.pass;
109314 +}
109315 +#endif
109316 +
109317 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
109318 +{
109319 + const char * const plugin_name = plugin_info->base_name;
109320 + const int argc = plugin_info->argc;
109321 + const struct plugin_argument * const argv = plugin_info->argv;
109322 + int i;
109323 + struct register_pass_info kernexec_reload_pass_info;
109324 + struct register_pass_info kernexec_fptr_pass_info;
109325 + struct register_pass_info kernexec_retaddr_pass_info;
109326 +
109327 + kernexec_reload_pass_info.pass = make_kernexec_reload_pass();
109328 + kernexec_reload_pass_info.reference_pass_name = "ssa";
109329 + kernexec_reload_pass_info.ref_pass_instance_number = 1;
109330 + kernexec_reload_pass_info.pos_op = PASS_POS_INSERT_AFTER;
109331 +
109332 + kernexec_fptr_pass_info.pass = make_kernexec_fptr_pass();
109333 + kernexec_fptr_pass_info.reference_pass_name = "ssa";
109334 + kernexec_fptr_pass_info.ref_pass_instance_number = 1;
109335 + kernexec_fptr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
109336 +
109337 + kernexec_retaddr_pass_info.pass = make_kernexec_retaddr_pass();
109338 + kernexec_retaddr_pass_info.reference_pass_name = "pro_and_epilogue";
109339 + kernexec_retaddr_pass_info.ref_pass_instance_number = 1;
109340 + kernexec_retaddr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
109341 +
109342 + if (!plugin_default_version_check(version, &gcc_version)) {
109343 + error(G_("incompatible gcc/plugin versions"));
109344 + return 1;
109345 + }
109346 +
109347 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
109348 +
109349 + if (TARGET_64BIT == 0)
109350 + return 0;
109351 +
109352 + for (i = 0; i < argc; ++i) {
109353 + if (!strcmp(argv[i].key, "method")) {
109354 + if (!argv[i].value) {
109355 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
109356 + continue;
109357 + }
109358 + if (!strcmp(argv[i].value, "bts")) {
109359 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
109360 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
109361 + } else if (!strcmp(argv[i].value, "or")) {
109362 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
109363 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
109364 + fix_register("r12", 1, 1);
109365 + } else
109366 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
109367 + continue;
109368 + }
109369 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
109370 + }
109371 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
109372 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
109373 +
109374 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
109375 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
109376 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
109377 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
109378 +
109379 + return 0;
109380 +}
109381 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
109382 new file mode 100644
109383 index 0000000..39d7cc7
109384 --- /dev/null
109385 +++ b/tools/gcc/latent_entropy_plugin.c
109386 @@ -0,0 +1,462 @@
109387 +/*
109388 + * Copyright 2012-2014 by the PaX Team <pageexec@freemail.hu>
109389 + * Licensed under the GPL v2
109390 + *
109391 + * Note: the choice of the license means that the compilation process is
109392 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
109393 + * but for the kernel it doesn't matter since it doesn't link against
109394 + * any of the gcc libraries
109395 + *
109396 + * gcc plugin to help generate a little bit of entropy from program state,
109397 + * used throughout the uptime of the kernel
109398 + *
109399 + * TODO:
109400 + * - add ipa pass to identify not explicitly marked candidate functions
109401 + * - mix in more program state (function arguments/return values, loop variables, etc)
109402 + * - more instrumentation control via attribute parameters
109403 + *
109404 + * BUGS:
109405 + * - LTO needs -flto-partition=none for now
109406 + */
109407 +
109408 +#include "gcc-common.h"
109409 +
109410 +int plugin_is_GPL_compatible;
109411 +
109412 +static tree latent_entropy_decl;
109413 +
109414 +static struct plugin_info latent_entropy_plugin_info = {
109415 + .version = "201403280150",
109416 + .help = NULL
109417 +};
109418 +
109419 +static unsigned HOST_WIDE_INT seed;
109420 +static unsigned HOST_WIDE_INT get_random_const(void)
109421 +{
109422 + unsigned int i;
109423 + unsigned HOST_WIDE_INT ret = 0;
109424 +
109425 + for (i = 0; i < 8 * sizeof ret; i++) {
109426 + ret = (ret << 1) | (seed & 1);
109427 + seed >>= 1;
109428 + if (ret & 1)
109429 + seed ^= 0xD800000000000000ULL;
109430 + }
109431 +
109432 + return ret;
109433 +}
109434 +
109435 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
109436 +{
109437 + tree type;
109438 + unsigned long long mask;
109439 +#if BUILDING_GCC_VERSION <= 4007
109440 + VEC(constructor_elt, gc) *vals;
109441 +#else
109442 + vec<constructor_elt, va_gc> *vals;
109443 +#endif
109444 +
109445 + switch (TREE_CODE(*node)) {
109446 + default:
109447 + *no_add_attrs = true;
109448 + error("%qE attribute only applies to functions and variables", name);
109449 + break;
109450 +
109451 + case VAR_DECL:
109452 + if (DECL_INITIAL(*node)) {
109453 + *no_add_attrs = true;
109454 + error("variable %qD with %qE attribute must not be initialized", *node, name);
109455 + break;
109456 + }
109457 +
109458 + if (!TREE_STATIC(*node)) {
109459 + *no_add_attrs = true;
109460 + error("variable %qD with %qE attribute must not be local", *node, name);
109461 + break;
109462 + }
109463 +
109464 + type = TREE_TYPE(*node);
109465 + switch (TREE_CODE(type)) {
109466 + default:
109467 + *no_add_attrs = true;
109468 + 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);
109469 + break;
109470 +
109471 + case RECORD_TYPE: {
109472 + tree field;
109473 + unsigned int nelt = 0;
109474 +
109475 + for (field = TYPE_FIELDS(type); field; nelt++, field = TREE_CHAIN(field)) {
109476 + tree fieldtype;
109477 +
109478 + fieldtype = TREE_TYPE(field);
109479 + if (TREE_CODE(fieldtype) != INTEGER_TYPE) {
109480 + *no_add_attrs = true;
109481 + error("structure variable %qD with %qE attribute has a non-integer field %qE", *node, name, field);
109482 + break;
109483 + }
109484 + }
109485 +
109486 + if (field)
109487 + break;
109488 +
109489 +#if BUILDING_GCC_VERSION <= 4007
109490 + vals = VEC_alloc(constructor_elt, gc, nelt);
109491 +#else
109492 + vec_alloc(vals, nelt);
109493 +#endif
109494 +
109495 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
109496 + tree fieldtype;
109497 +
109498 + fieldtype = TREE_TYPE(field);
109499 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(fieldtype)) - 1);
109500 + mask = 2 * (mask - 1) + 1;
109501 +
109502 + if (TYPE_UNSIGNED(fieldtype))
109503 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cstu(fieldtype, mask & get_random_const()));
109504 + else
109505 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cst(fieldtype, mask & get_random_const()));
109506 + }
109507 +
109508 + DECL_INITIAL(*node) = build_constructor(type, vals);
109509 +//debug_tree(DECL_INITIAL(*node));
109510 + break;
109511 + }
109512 +
109513 + case INTEGER_TYPE:
109514 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(type)) - 1);
109515 + mask = 2 * (mask - 1) + 1;
109516 +
109517 + if (TYPE_UNSIGNED(type))
109518 + DECL_INITIAL(*node) = build_int_cstu(type, mask & get_random_const());
109519 + else
109520 + DECL_INITIAL(*node) = build_int_cst(type, mask & get_random_const());
109521 + break;
109522 +
109523 + case ARRAY_TYPE: {
109524 + tree elt_type, array_size, elt_size;
109525 + unsigned int i, nelt;
109526 +
109527 + elt_type = TREE_TYPE(type);
109528 + elt_size = TYPE_SIZE_UNIT(TREE_TYPE(type));
109529 + array_size = TYPE_SIZE_UNIT(type);
109530 +
109531 + if (TREE_CODE(elt_type) != INTEGER_TYPE || !array_size || TREE_CODE(array_size) != INTEGER_CST) {
109532 + *no_add_attrs = true;
109533 + error("array variable %qD with %qE attribute must be a fixed length integer array type", *node, name);
109534 + break;
109535 + }
109536 +
109537 + nelt = TREE_INT_CST_LOW(array_size) / TREE_INT_CST_LOW(elt_size);
109538 +#if BUILDING_GCC_VERSION <= 4007
109539 + vals = VEC_alloc(constructor_elt, gc, nelt);
109540 +#else
109541 + vec_alloc(vals, nelt);
109542 +#endif
109543 +
109544 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(elt_type)) - 1);
109545 + mask = 2 * (mask - 1) + 1;
109546 +
109547 + for (i = 0; i < nelt; i++)
109548 + if (TYPE_UNSIGNED(elt_type))
109549 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cstu(elt_type, mask & get_random_const()));
109550 + else
109551 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cst(elt_type, mask & get_random_const()));
109552 +
109553 + DECL_INITIAL(*node) = build_constructor(type, vals);
109554 +//debug_tree(DECL_INITIAL(*node));
109555 + break;
109556 + }
109557 + }
109558 + break;
109559 +
109560 + case FUNCTION_DECL:
109561 + break;
109562 + }
109563 +
109564 + return NULL_TREE;
109565 +}
109566 +
109567 +static struct attribute_spec latent_entropy_attr = {
109568 + .name = "latent_entropy",
109569 + .min_length = 0,
109570 + .max_length = 0,
109571 + .decl_required = true,
109572 + .type_required = false,
109573 + .function_type_required = false,
109574 + .handler = handle_latent_entropy_attribute,
109575 +#if BUILDING_GCC_VERSION >= 4007
109576 + .affects_type_identity = false
109577 +#endif
109578 +};
109579 +
109580 +static void register_attributes(void *event_data, void *data)
109581 +{
109582 + register_attribute(&latent_entropy_attr);
109583 +}
109584 +
109585 +static bool gate_latent_entropy(void)
109586 +{
109587 + // don't bother with noreturn functions for now
109588 + if (TREE_THIS_VOLATILE(current_function_decl))
109589 + return false;
109590 +
109591 + return lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl)) != NULL_TREE;
109592 +}
109593 +
109594 +static enum tree_code get_op(tree *rhs)
109595 +{
109596 + static enum tree_code op;
109597 + unsigned HOST_WIDE_INT random_const;
109598 +
109599 + random_const = get_random_const();
109600 +
109601 + switch (op) {
109602 + case BIT_XOR_EXPR:
109603 + op = PLUS_EXPR;
109604 + break;
109605 +
109606 + case PLUS_EXPR:
109607 + if (rhs) {
109608 + op = LROTATE_EXPR;
109609 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
109610 + break;
109611 + }
109612 +
109613 + case LROTATE_EXPR:
109614 + default:
109615 + op = BIT_XOR_EXPR;
109616 + break;
109617 + }
109618 + if (rhs)
109619 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
109620 + return op;
109621 +}
109622 +
109623 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
109624 +{
109625 + gimple_stmt_iterator gsi;
109626 + gimple assign;
109627 + tree addxorrol, rhs;
109628 + enum tree_code op;
109629 +
109630 + op = get_op(&rhs);
109631 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
109632 + assign = gimple_build_assign(local_entropy, addxorrol);
109633 + gsi = gsi_after_labels(bb);
109634 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
109635 + update_stmt(assign);
109636 +//debug_bb(bb);
109637 +}
109638 +
109639 +static void perturb_latent_entropy(basic_block bb, tree rhs)
109640 +{
109641 + gimple_stmt_iterator gsi;
109642 + gimple assign;
109643 + tree addxorrol, temp;
109644 +
109645 + // 1. create temporary copy of latent_entropy
109646 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
109647 + add_referenced_var(temp);
109648 +
109649 + // 2. read...
109650 + temp = make_ssa_name(temp, NULL);
109651 + assign = gimple_build_assign(temp, latent_entropy_decl);
109652 + SSA_NAME_DEF_STMT(temp) = assign;
109653 + add_referenced_var(latent_entropy_decl);
109654 + gsi = gsi_after_labels(bb);
109655 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
109656 + update_stmt(assign);
109657 +
109658 + // 3. ...modify...
109659 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
109660 + temp = make_ssa_name(SSA_NAME_VAR(temp), NULL);
109661 + assign = gimple_build_assign(temp, addxorrol);
109662 + SSA_NAME_DEF_STMT(temp) = assign;
109663 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
109664 + update_stmt(assign);
109665 +
109666 + // 4. ...write latent_entropy
109667 + assign = gimple_build_assign(latent_entropy_decl, temp);
109668 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
109669 + update_stmt(assign);
109670 +}
109671 +
109672 +static unsigned int execute_latent_entropy(void)
109673 +{
109674 + basic_block bb;
109675 + gimple assign;
109676 + gimple_stmt_iterator gsi;
109677 + tree local_entropy;
109678 +
109679 + if (!latent_entropy_decl) {
109680 +#if BUILDING_GCC_VERSION >= 4009
109681 + varpool_node *node;
109682 +#else
109683 + struct varpool_node *node;
109684 +#endif
109685 +
109686 + FOR_EACH_VARIABLE(node) {
109687 + tree var = NODE_DECL(node);
109688 +
109689 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
109690 + continue;
109691 + latent_entropy_decl = var;
109692 +// debug_tree(var);
109693 + break;
109694 + }
109695 + if (!latent_entropy_decl) {
109696 +// debug_tree(current_function_decl);
109697 + return 0;
109698 + }
109699 + }
109700 +
109701 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
109702 +
109703 + // 1. create local entropy variable
109704 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
109705 + add_referenced_var(local_entropy);
109706 + mark_sym_for_renaming(local_entropy);
109707 +
109708 + // 2. initialize local entropy variable
109709 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
109710 + if (dom_info_available_p(CDI_DOMINATORS))
109711 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
109712 + gsi = gsi_start_bb(bb);
109713 +
109714 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
109715 +// gimple_set_location(assign, loc);
109716 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
109717 + update_stmt(assign);
109718 +//debug_bb(bb);
109719 + gcc_assert(single_succ_p(bb));
109720 + bb = single_succ(bb);
109721 +
109722 + // 3. instrument each BB with an operation on the local entropy variable
109723 + while (bb != EXIT_BLOCK_PTR_FOR_FN(cfun)) {
109724 + perturb_local_entropy(bb, local_entropy);
109725 +//debug_bb(bb);
109726 + bb = bb->next_bb;
109727 + };
109728 +
109729 + // 4. mix local entropy into the global entropy variable
109730 + gcc_assert(single_pred_p(EXIT_BLOCK_PTR_FOR_FN(cfun)));
109731 + perturb_latent_entropy(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)), local_entropy);
109732 +//debug_bb(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)));
109733 + return 0;
109734 +}
109735 +
109736 +static void latent_entropy_start_unit(void *gcc_data, void *user_data)
109737 +{
109738 + tree latent_entropy_type;
109739 +
109740 + seed = get_random_seed(false);
109741 +
109742 + if (in_lto_p)
109743 + return;
109744 +
109745 + // extern volatile u64 latent_entropy
109746 + gcc_assert(TYPE_PRECISION(long_long_unsigned_type_node) == 64);
109747 + latent_entropy_type = build_qualified_type(long_long_unsigned_type_node, TYPE_QUALS(long_long_unsigned_type_node) | TYPE_QUAL_VOLATILE);
109748 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), latent_entropy_type);
109749 +
109750 + TREE_STATIC(latent_entropy_decl) = 1;
109751 + TREE_PUBLIC(latent_entropy_decl) = 1;
109752 + TREE_USED(latent_entropy_decl) = 1;
109753 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
109754 + DECL_EXTERNAL(latent_entropy_decl) = 1;
109755 + DECL_ARTIFICIAL(latent_entropy_decl) = 1;
109756 + lang_hooks.decls.pushdecl(latent_entropy_decl);
109757 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
109758 +// varpool_finalize_decl(latent_entropy_decl);
109759 +// varpool_mark_needed_node(latent_entropy_decl);
109760 +}
109761 +
109762 +#if BUILDING_GCC_VERSION >= 4009
109763 +static const struct pass_data latent_entropy_pass_data = {
109764 +#else
109765 +static struct gimple_opt_pass latent_entropy_pass = {
109766 + .pass = {
109767 +#endif
109768 + .type = GIMPLE_PASS,
109769 + .name = "latent_entropy",
109770 +#if BUILDING_GCC_VERSION >= 4008
109771 + .optinfo_flags = OPTGROUP_NONE,
109772 +#endif
109773 +#if BUILDING_GCC_VERSION >= 4009
109774 + .has_gate = true,
109775 + .has_execute = true,
109776 +#else
109777 + .gate = gate_latent_entropy,
109778 + .execute = execute_latent_entropy,
109779 + .sub = NULL,
109780 + .next = NULL,
109781 + .static_pass_number = 0,
109782 +#endif
109783 + .tv_id = TV_NONE,
109784 + .properties_required = PROP_gimple_leh | PROP_cfg,
109785 + .properties_provided = 0,
109786 + .properties_destroyed = 0,
109787 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
109788 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
109789 +#if BUILDING_GCC_VERSION < 4009
109790 + }
109791 +#endif
109792 +};
109793 +
109794 +#if BUILDING_GCC_VERSION >= 4009
109795 +namespace {
109796 +class latent_entropy_pass : public gimple_opt_pass {
109797 +public:
109798 + latent_entropy_pass() : gimple_opt_pass(latent_entropy_pass_data, g) {}
109799 + bool gate() { return gate_latent_entropy(); }
109800 + unsigned int execute() { return execute_latent_entropy(); }
109801 +};
109802 +}
109803 +
109804 +static opt_pass *make_latent_entropy_pass(void)
109805 +{
109806 + return new latent_entropy_pass();
109807 +}
109808 +#else
109809 +static struct opt_pass *make_latent_entropy_pass(void)
109810 +{
109811 + return &latent_entropy_pass.pass;
109812 +}
109813 +#endif
109814 +
109815 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
109816 +{
109817 + const char * const plugin_name = plugin_info->base_name;
109818 + struct register_pass_info latent_entropy_pass_info;
109819 +
109820 + latent_entropy_pass_info.pass = make_latent_entropy_pass();
109821 + latent_entropy_pass_info.reference_pass_name = "optimized";
109822 + latent_entropy_pass_info.ref_pass_instance_number = 1;
109823 + latent_entropy_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
109824 + static const struct ggc_root_tab gt_ggc_r_gt_latent_entropy[] = {
109825 + {
109826 + .base = &latent_entropy_decl,
109827 + .nelt = 1,
109828 + .stride = sizeof(latent_entropy_decl),
109829 + .cb = &gt_ggc_mx_tree_node,
109830 + .pchw = &gt_pch_nx_tree_node
109831 + },
109832 + LAST_GGC_ROOT_TAB
109833 + };
109834 +
109835 + if (!plugin_default_version_check(version, &gcc_version)) {
109836 + error(G_("incompatible gcc/plugin versions"));
109837 + return 1;
109838 + }
109839 +
109840 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
109841 + register_callback(plugin_name, PLUGIN_START_UNIT, &latent_entropy_start_unit, NULL);
109842 + if (!in_lto_p)
109843 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_latent_entropy);
109844 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
109845 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
109846 +
109847 + return 0;
109848 +}
109849 diff --git a/tools/gcc/randomize_layout_plugin.c b/tools/gcc/randomize_layout_plugin.c
109850 new file mode 100644
109851 index 0000000..a5cb46b
109852 --- /dev/null
109853 +++ b/tools/gcc/randomize_layout_plugin.c
109854 @@ -0,0 +1,915 @@
109855 +/*
109856 + * Copyright 2014 by Open Source Security, Inc., Brad Spengler <spender@grsecurity.net>
109857 + * and PaX Team <pageexec@freemail.hu>
109858 + * Licensed under the GPL v2
109859 + *
109860 + * Usage:
109861 + * $ # for 4.5/4.6/C based 4.7
109862 + * $ 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
109863 + * $ # for C++ based 4.7/4.8+
109864 + * $ 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
109865 + * $ gcc -fplugin=./randomize_layout_plugin.so test.c -O2
109866 + */
109867 +
109868 +#include "gcc-common.h"
109869 +#include "randomize_layout_seed.h"
109870 +
109871 +#if BUILDING_GCC_MAJOR < 4 || BUILDING_GCC_MINOR < 6 || (BUILDING_GCC_MINOR == 6 && BUILDING_GCC_PATCHLEVEL < 4)
109872 +#error "The RANDSTRUCT plugin requires GCC 4.6.4 or newer."
109873 +#endif
109874 +
109875 +#define ORIG_TYPE_NAME(node) \
109876 + (TYPE_NAME(TYPE_MAIN_VARIANT(node)) != NULL_TREE ? ((const unsigned char *)IDENTIFIER_POINTER(TYPE_NAME(TYPE_MAIN_VARIANT(node)))) : (const unsigned char *)"anonymous")
109877 +
109878 +int plugin_is_GPL_compatible;
109879 +
109880 +static int performance_mode;
109881 +
109882 +static struct plugin_info randomize_layout_plugin_info = {
109883 + .version = "201402201816",
109884 + .help = "disable\t\t\tdo not activate plugin\n"
109885 + "performance-mode\tenable cacheline-aware layout randomization\n"
109886 +};
109887 +
109888 +/* from old Linux dcache.h */
109889 +static inline unsigned long
109890 +partial_name_hash(unsigned long c, unsigned long prevhash)
109891 +{
109892 + return (prevhash + (c << 4) + (c >> 4)) * 11;
109893 +}
109894 +static inline unsigned int
109895 +name_hash(const unsigned char *name)
109896 +{
109897 + unsigned long hash = 0;
109898 + unsigned int len = strlen((const char *)name);
109899 + while (len--)
109900 + hash = partial_name_hash(*name++, hash);
109901 + return (unsigned int)hash;
109902 +}
109903 +
109904 +static tree handle_randomize_layout_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
109905 +{
109906 + tree type;
109907 +
109908 + *no_add_attrs = true;
109909 + if (TREE_CODE(*node) == FUNCTION_DECL) {
109910 + error("%qE attribute does not apply to functions (%qF)", name, *node);
109911 + return NULL_TREE;
109912 + }
109913 +
109914 + if (TREE_CODE(*node) == PARM_DECL) {
109915 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
109916 + return NULL_TREE;
109917 + }
109918 +
109919 + if (TREE_CODE(*node) == VAR_DECL) {
109920 + error("%qE attribute does not apply to variables (%qD)", name, *node);
109921 + return NULL_TREE;
109922 + }
109923 +
109924 + if (TYPE_P(*node)) {
109925 + type = *node;
109926 + } else {
109927 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
109928 + type = TREE_TYPE(*node);
109929 + }
109930 +
109931 + if (TREE_CODE(type) != RECORD_TYPE) {
109932 + error("%qE attribute used on %qT applies to struct types only", name, type);
109933 + return NULL_TREE;
109934 + }
109935 +
109936 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
109937 + error("%qE attribute is already applied to the type %qT", name, type);
109938 + return NULL_TREE;
109939 + }
109940 +
109941 + *no_add_attrs = false;
109942 +
109943 + return NULL_TREE;
109944 +}
109945 +
109946 +/* set on complete types that we don't need to inspect further at all */
109947 +static tree handle_randomize_considered_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
109948 +{
109949 + *no_add_attrs = false;
109950 + return NULL_TREE;
109951 +}
109952 +
109953 +/*
109954 + * set on types that we've performed a shuffle on, to prevent re-shuffling
109955 + * this does not preclude us from inspecting its fields for potential shuffles
109956 + */
109957 +static tree handle_randomize_performed_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
109958 +{
109959 + *no_add_attrs = false;
109960 + return NULL_TREE;
109961 +}
109962 +
109963 +/*
109964 + * 64bit variant of Bob Jenkins' public domain PRNG
109965 + * 256 bits of internal state
109966 + */
109967 +
109968 +typedef unsigned long long u64;
109969 +
109970 +typedef struct ranctx { u64 a; u64 b; u64 c; u64 d; } ranctx;
109971 +
109972 +#define rot(x,k) (((x)<<(k))|((x)>>(64-(k))))
109973 +static u64 ranval(ranctx *x) {
109974 + u64 e = x->a - rot(x->b, 7);
109975 + x->a = x->b ^ rot(x->c, 13);
109976 + x->b = x->c + rot(x->d, 37);
109977 + x->c = x->d + e;
109978 + x->d = e + x->a;
109979 + return x->d;
109980 +}
109981 +
109982 +static void raninit(ranctx *x, u64 *seed) {
109983 + int i;
109984 +
109985 + x->a = seed[0];
109986 + x->b = seed[1];
109987 + x->c = seed[2];
109988 + x->d = seed[3];
109989 +
109990 + for (i=0; i < 30; ++i)
109991 + (void)ranval(x);
109992 +}
109993 +
109994 +static u64 shuffle_seed[4];
109995 +
109996 +struct partition_group {
109997 + tree tree_start;
109998 + unsigned long start;
109999 + unsigned long length;
110000 +};
110001 +
110002 +static void partition_struct(tree *fields, unsigned long length, struct partition_group *size_groups, unsigned long *num_groups)
110003 +{
110004 + unsigned long i;
110005 + unsigned long accum_size = 0;
110006 + unsigned long accum_length = 0;
110007 + unsigned long group_idx = 0;
110008 +
110009 + gcc_assert(length < INT_MAX);
110010 +
110011 + memset(size_groups, 0, sizeof(struct partition_group) * length);
110012 +
110013 + for (i = 0; i < length; i++) {
110014 + if (size_groups[group_idx].tree_start == NULL_TREE) {
110015 + size_groups[group_idx].tree_start = fields[i];
110016 + size_groups[group_idx].start = i;
110017 + accum_length = 0;
110018 + accum_size = 0;
110019 + }
110020 + accum_size += (unsigned long)int_size_in_bytes(TREE_TYPE(fields[i]));
110021 + accum_length++;
110022 + if (accum_size >= 64) {
110023 + size_groups[group_idx].length = accum_length;
110024 + accum_length = 0;
110025 + group_idx++;
110026 + }
110027 + }
110028 +
110029 + if (size_groups[group_idx].tree_start != NULL_TREE &&
110030 + !size_groups[group_idx].length) {
110031 + size_groups[group_idx].length = accum_length;
110032 + group_idx++;
110033 + }
110034 +
110035 + *num_groups = group_idx;
110036 +}
110037 +
110038 +static void performance_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
110039 +{
110040 + unsigned long i, x;
110041 + struct partition_group size_group[length];
110042 + unsigned long num_groups = 0;
110043 + unsigned long randnum;
110044 +
110045 + partition_struct(newtree, length, (struct partition_group *)&size_group, &num_groups);
110046 + for (i = num_groups - 1; i > 0; i--) {
110047 + struct partition_group tmp;
110048 + randnum = ranval(prng_state) % (i + 1);
110049 + tmp = size_group[i];
110050 + size_group[i] = size_group[randnum];
110051 + size_group[randnum] = tmp;
110052 + }
110053 +
110054 + for (x = 0; x < num_groups; x++) {
110055 + for (i = size_group[x].start + size_group[x].length - 1; i > size_group[x].start; i--) {
110056 + tree tmp;
110057 + if (DECL_BIT_FIELD_TYPE(newtree[i]))
110058 + continue;
110059 + randnum = ranval(prng_state) % (i + 1);
110060 + // we could handle this case differently if desired
110061 + if (DECL_BIT_FIELD_TYPE(newtree[randnum]))
110062 + continue;
110063 + tmp = newtree[i];
110064 + newtree[i] = newtree[randnum];
110065 + newtree[randnum] = tmp;
110066 + }
110067 + }
110068 +}
110069 +
110070 +static void full_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
110071 +{
110072 + unsigned long i, randnum;
110073 +
110074 + for (i = length - 1; i > 0; i--) {
110075 + tree tmp;
110076 + randnum = ranval(prng_state) % (i + 1);
110077 + tmp = newtree[i];
110078 + newtree[i] = newtree[randnum];
110079 + newtree[randnum] = tmp;
110080 + }
110081 +}
110082 +
110083 +/* modern in-place Fisher-Yates shuffle */
110084 +static void shuffle(const_tree type, tree *newtree, unsigned long length)
110085 +{
110086 + unsigned long i;
110087 + u64 seed[4];
110088 + ranctx prng_state;
110089 + const unsigned char *structname;
110090 +
110091 + if (length == 0)
110092 + return;
110093 +
110094 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
110095 +
110096 + structname = ORIG_TYPE_NAME(type);
110097 +
110098 +#ifdef __DEBUG_PLUGIN
110099 + fprintf(stderr, "Shuffling struct %s %p\n", (const char *)structname, type);
110100 +#ifdef __DEBUG_VERBOSE
110101 + debug_tree((tree)type);
110102 +#endif
110103 +#endif
110104 +
110105 + for (i = 0; i < 4; i++) {
110106 + seed[i] = shuffle_seed[i];
110107 + seed[i] ^= name_hash(structname);
110108 + }
110109 +
110110 + raninit(&prng_state, (u64 *)&seed);
110111 +
110112 + if (performance_mode)
110113 + performance_shuffle(newtree, length, &prng_state);
110114 + else
110115 + full_shuffle(newtree, length, &prng_state);
110116 +}
110117 +
110118 +static bool is_flexible_array(const_tree field)
110119 +{
110120 + const_tree fieldtype;
110121 + const_tree typesize;
110122 + const_tree elemtype;
110123 + const_tree elemsize;
110124 +
110125 + fieldtype = TREE_TYPE(field);
110126 + typesize = TYPE_SIZE(fieldtype);
110127 +
110128 + if (TREE_CODE(fieldtype) != ARRAY_TYPE)
110129 + return false;
110130 +
110131 + elemtype = TREE_TYPE(fieldtype);
110132 + elemsize = TYPE_SIZE(elemtype);
110133 +
110134 + /* size of type is represented in bits */
110135 +
110136 + if (typesize == NULL_TREE && TYPE_DOMAIN(fieldtype) != NULL_TREE &&
110137 + TYPE_MAX_VALUE(TYPE_DOMAIN(fieldtype)) == NULL_TREE)
110138 + return true;
110139 +
110140 + if (typesize != NULL_TREE &&
110141 + (TREE_CONSTANT(typesize) && (!TREE_INT_CST_LOW(typesize) ||
110142 + TREE_INT_CST_LOW(typesize) == TREE_INT_CST_LOW(elemsize))))
110143 + return true;
110144 +
110145 + return false;
110146 +}
110147 +
110148 +static int relayout_struct(tree type)
110149 +{
110150 + unsigned long num_fields = (unsigned long)list_length(TYPE_FIELDS(type));
110151 + unsigned long shuffle_length = num_fields;
110152 + tree field;
110153 + tree newtree[num_fields];
110154 + unsigned long i;
110155 + tree list;
110156 + tree variant;
110157 + expanded_location xloc;
110158 +
110159 + if (TYPE_FIELDS(type) == NULL_TREE)
110160 + return 0;
110161 +
110162 + if (num_fields < 2)
110163 + return 0;
110164 +
110165 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
110166 +
110167 + gcc_assert(num_fields < INT_MAX);
110168 +
110169 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)) ||
110170 + lookup_attribute("no_randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))))
110171 + return 0;
110172 +
110173 + /* Workaround for 3rd-party VirtualBox source that we can't modify ourselves */
110174 + if (!strcmp((const char *)ORIG_TYPE_NAME(type), "INTNETTRUNKFACTORY") ||
110175 + !strcmp((const char *)ORIG_TYPE_NAME(type), "RAWPCIFACTORY"))
110176 + return 0;
110177 +
110178 + /* throw out any structs in uapi */
110179 + xloc = expand_location(DECL_SOURCE_LOCATION(TYPE_FIELDS(type)));
110180 +
110181 + if (strstr(xloc.file, "/uapi/"))
110182 + error(G_("attempted to randomize userland API struct %s"), ORIG_TYPE_NAME(type));
110183 +
110184 + for (field = TYPE_FIELDS(type), i = 0; field; field = TREE_CHAIN(field), i++) {
110185 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
110186 + newtree[i] = field;
110187 + }
110188 +
110189 + /*
110190 + * enforce that we don't randomize the layout of the last
110191 + * element of a struct if it's a 0 or 1-length array
110192 + * or a proper flexible array
110193 + */
110194 + if (is_flexible_array(newtree[num_fields - 1]))
110195 + shuffle_length--;
110196 +
110197 + shuffle(type, (tree *)newtree, shuffle_length);
110198 +
110199 + /*
110200 + * set up a bogus anonymous struct field designed to error out on unnamed struct initializers
110201 + * as gcc provides no other way to detect such code
110202 + */
110203 + list = make_node(FIELD_DECL);
110204 + TREE_CHAIN(list) = newtree[0];
110205 + TREE_TYPE(list) = void_type_node;
110206 + DECL_SIZE(list) = bitsize_zero_node;
110207 + DECL_NONADDRESSABLE_P(list) = 1;
110208 + DECL_FIELD_BIT_OFFSET(list) = bitsize_zero_node;
110209 + DECL_SIZE_UNIT(list) = size_zero_node;
110210 + DECL_FIELD_OFFSET(list) = size_zero_node;
110211 + // to satisfy the constify plugin
110212 + TREE_READONLY(list) = 1;
110213 +
110214 + for (i = 0; i < num_fields - 1; i++)
110215 + TREE_CHAIN(newtree[i]) = newtree[i+1];
110216 + TREE_CHAIN(newtree[num_fields - 1]) = NULL_TREE;
110217 +
110218 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
110219 + TYPE_FIELDS(variant) = list;
110220 + TYPE_ATTRIBUTES(variant) = copy_list(TYPE_ATTRIBUTES(variant));
110221 + TYPE_ATTRIBUTES(variant) = tree_cons(get_identifier("randomize_performed"), NULL_TREE, TYPE_ATTRIBUTES(variant));
110222 + // force a re-layout
110223 + TYPE_SIZE(variant) = NULL_TREE;
110224 + layout_type(variant);
110225 + }
110226 +
110227 + return 1;
110228 +}
110229 +
110230 +/* from constify plugin */
110231 +static const_tree get_field_type(const_tree field)
110232 +{
110233 + return strip_array_types(TREE_TYPE(field));
110234 +}
110235 +
110236 +/* from constify plugin */
110237 +static bool is_fptr(const_tree fieldtype)
110238 +{
110239 + if (TREE_CODE(fieldtype) != POINTER_TYPE)
110240 + return false;
110241 +
110242 + return TREE_CODE(TREE_TYPE(fieldtype)) == FUNCTION_TYPE;
110243 +}
110244 +
110245 +/* derived from constify plugin */
110246 +static int is_pure_ops_struct(const_tree node)
110247 +{
110248 + const_tree field;
110249 +
110250 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
110251 +
110252 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
110253 + const_tree fieldtype = get_field_type(field);
110254 + enum tree_code code = TREE_CODE(fieldtype);
110255 +
110256 + if (node == fieldtype)
110257 + continue;
110258 +
110259 + if (!is_fptr(fieldtype))
110260 + return 0;
110261 +
110262 + if (code != RECORD_TYPE && code != UNION_TYPE)
110263 + continue;
110264 +
110265 + if (!is_pure_ops_struct(fieldtype))
110266 + return 0;
110267 + }
110268 +
110269 + return 1;
110270 +}
110271 +
110272 +static void randomize_type(tree type)
110273 +{
110274 + tree variant;
110275 +
110276 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
110277 +
110278 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
110279 + return;
110280 +
110281 + if (lookup_attribute("randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))) || is_pure_ops_struct(type))
110282 + relayout_struct(type);
110283 +
110284 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
110285 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
110286 + TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("randomize_considered"), NULL_TREE, TYPE_ATTRIBUTES(type));
110287 + }
110288 +#ifdef __DEBUG_PLUGIN
110289 + fprintf(stderr, "Marking randomize_considered on struct %s\n", ORIG_TYPE_NAME(type));
110290 +#ifdef __DEBUG_VERBOSE
110291 + debug_tree(type);
110292 +#endif
110293 +#endif
110294 +}
110295 +
110296 +static void randomize_layout_finish_decl(void *event_data, void *data)
110297 +{
110298 + tree decl = (tree)event_data;
110299 + tree type;
110300 +
110301 + if (decl == NULL_TREE || decl == error_mark_node)
110302 + return;
110303 +
110304 + type = TREE_TYPE(decl);
110305 +
110306 + if (TREE_CODE(decl) != VAR_DECL)
110307 + return;
110308 +
110309 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
110310 + return;
110311 +
110312 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)))
110313 + return;
110314 +
110315 + relayout_decl(decl);
110316 +}
110317 +
110318 +static void finish_type(void *event_data, void *data)
110319 +{
110320 + tree type = (tree)event_data;
110321 +
110322 + if (type == NULL_TREE || type == error_mark_node)
110323 + return;
110324 +
110325 + if (TREE_CODE(type) != RECORD_TYPE)
110326 + return;
110327 +
110328 + if (TYPE_FIELDS(type) == NULL_TREE)
110329 + return;
110330 +
110331 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
110332 + return;
110333 +
110334 +#ifdef __DEBUG_PLUGIN
110335 + fprintf(stderr, "Calling randomize_type on %s\n", ORIG_TYPE_NAME(type));
110336 +#endif
110337 +#ifdef __DEBUG_VERBOSE
110338 + debug_tree(type);
110339 +#endif
110340 + randomize_type(type);
110341 +
110342 + return;
110343 +}
110344 +
110345 +static struct attribute_spec randomize_layout_attr = {
110346 + .name = "randomize_layout",
110347 + // related to args
110348 + .min_length = 0,
110349 + .max_length = 0,
110350 + .decl_required = false,
110351 + // need type declaration
110352 + .type_required = true,
110353 + .function_type_required = false,
110354 + .handler = handle_randomize_layout_attr,
110355 +#if BUILDING_GCC_VERSION >= 4007
110356 + .affects_type_identity = true
110357 +#endif
110358 +};
110359 +
110360 +static struct attribute_spec no_randomize_layout_attr = {
110361 + .name = "no_randomize_layout",
110362 + // related to args
110363 + .min_length = 0,
110364 + .max_length = 0,
110365 + .decl_required = false,
110366 + // need type declaration
110367 + .type_required = true,
110368 + .function_type_required = false,
110369 + .handler = handle_randomize_layout_attr,
110370 +#if BUILDING_GCC_VERSION >= 4007
110371 + .affects_type_identity = true
110372 +#endif
110373 +};
110374 +
110375 +static struct attribute_spec randomize_considered_attr = {
110376 + .name = "randomize_considered",
110377 + // related to args
110378 + .min_length = 0,
110379 + .max_length = 0,
110380 + .decl_required = false,
110381 + // need type declaration
110382 + .type_required = true,
110383 + .function_type_required = false,
110384 + .handler = handle_randomize_considered_attr,
110385 +#if BUILDING_GCC_VERSION >= 4007
110386 + .affects_type_identity = false
110387 +#endif
110388 +};
110389 +
110390 +static struct attribute_spec randomize_performed_attr = {
110391 + .name = "randomize_performed",
110392 + // related to args
110393 + .min_length = 0,
110394 + .max_length = 0,
110395 + .decl_required = false,
110396 + // need type declaration
110397 + .type_required = true,
110398 + .function_type_required = false,
110399 + .handler = handle_randomize_performed_attr,
110400 +#if BUILDING_GCC_VERSION >= 4007
110401 + .affects_type_identity = false
110402 +#endif
110403 +};
110404 +
110405 +static void register_attributes(void *event_data, void *data)
110406 +{
110407 + register_attribute(&randomize_layout_attr);
110408 + register_attribute(&no_randomize_layout_attr);
110409 + register_attribute(&randomize_considered_attr);
110410 + register_attribute(&randomize_performed_attr);
110411 +}
110412 +
110413 +static void check_bad_casts_in_constructor(tree var, tree init)
110414 +{
110415 + unsigned HOST_WIDE_INT idx;
110416 + tree field, val;
110417 + tree field_type, val_type;
110418 +
110419 + FOR_EACH_CONSTRUCTOR_ELT(CONSTRUCTOR_ELTS(init), idx, field, val) {
110420 + if (TREE_CODE(val) == CONSTRUCTOR) {
110421 + check_bad_casts_in_constructor(var, val);
110422 + continue;
110423 + }
110424 +
110425 + /* pipacs' plugin creates franken-arrays that differ from those produced by
110426 + normal code which all have valid 'field' trees. work around this */
110427 + if (field == NULL_TREE)
110428 + continue;
110429 + field_type = TREE_TYPE(field);
110430 + val_type = TREE_TYPE(val);
110431 +
110432 + if (TREE_CODE(field_type) != POINTER_TYPE || TREE_CODE(val_type) != POINTER_TYPE)
110433 + continue;
110434 +
110435 + if (field_type == val_type)
110436 + continue;
110437 +
110438 + field_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(field_type))));
110439 + val_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(val_type))));
110440 +
110441 + if (field_type == void_type_node)
110442 + continue;
110443 + if (field_type == val_type)
110444 + continue;
110445 + if (TREE_CODE(val_type) != RECORD_TYPE)
110446 + continue;
110447 +
110448 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(val_type)))
110449 + continue;
110450 + inform(DECL_SOURCE_LOCATION(var), "found mismatched struct pointer types: %qT and %qT\n", TYPE_MAIN_VARIANT(field_type), TYPE_MAIN_VARIANT(val_type));
110451 + }
110452 +}
110453 +
110454 +/* derived from the constify plugin */
110455 +static void check_global_variables(void *event_data, void *data)
110456 +{
110457 + struct varpool_node *node;
110458 + tree init;
110459 +
110460 + FOR_EACH_VARIABLE(node) {
110461 + tree var = NODE_DECL(node);
110462 + init = DECL_INITIAL(var);
110463 + if (init == NULL_TREE)
110464 + continue;
110465 +
110466 + if (TREE_CODE(init) != CONSTRUCTOR)
110467 + continue;
110468 +
110469 + check_bad_casts_in_constructor(var, init);
110470 + }
110471 +}
110472 +
110473 +static bool dominated_by_is_err(const_tree rhs, basic_block bb)
110474 +{
110475 + basic_block dom;
110476 + gimple dom_stmt;
110477 + gimple call_stmt;
110478 + const_tree dom_lhs;
110479 + const_tree poss_is_err_cond;
110480 + const_tree poss_is_err_func;
110481 + const_tree is_err_arg;
110482 +
110483 + dom = get_immediate_dominator(CDI_DOMINATORS, bb);
110484 + if (!dom)
110485 + return false;
110486 +
110487 + dom_stmt = last_stmt(dom);
110488 + if (!dom_stmt)
110489 + return false;
110490 +
110491 + if (gimple_code(dom_stmt) != GIMPLE_COND)
110492 + return false;
110493 +
110494 + if (gimple_cond_code(dom_stmt) != NE_EXPR)
110495 + return false;
110496 +
110497 + if (!integer_zerop(gimple_cond_rhs(dom_stmt)))
110498 + return false;
110499 +
110500 + poss_is_err_cond = gimple_cond_lhs(dom_stmt);
110501 +
110502 + if (TREE_CODE(poss_is_err_cond) != SSA_NAME)
110503 + return false;
110504 +
110505 + call_stmt = SSA_NAME_DEF_STMT(poss_is_err_cond);
110506 +
110507 + if (gimple_code(call_stmt) != GIMPLE_CALL)
110508 + return false;
110509 +
110510 + dom_lhs = gimple_get_lhs(call_stmt);
110511 + poss_is_err_func = gimple_call_fndecl(call_stmt);
110512 + if (!poss_is_err_func)
110513 + return false;
110514 + if (dom_lhs != poss_is_err_cond)
110515 + return false;
110516 + if (strcmp(DECL_NAME_POINTER(poss_is_err_func), "IS_ERR"))
110517 + return false;
110518 +
110519 + is_err_arg = gimple_call_arg(call_stmt, 0);
110520 + if (!is_err_arg)
110521 + return false;
110522 +
110523 + if (is_err_arg != rhs)
110524 + return false;
110525 +
110526 + return true;
110527 +}
110528 +
110529 +static void handle_local_var_initializers(void)
110530 +{
110531 + tree var;
110532 + unsigned int i;
110533 +
110534 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
110535 + tree init = DECL_INITIAL(var);
110536 + if (!init)
110537 + continue;
110538 + if (TREE_CODE(init) != CONSTRUCTOR)
110539 + continue;
110540 + check_bad_casts_in_constructor(var, init);
110541 + }
110542 +}
110543 +
110544 +/*
110545 + * iterate over all statements to find "bad" casts:
110546 + * those where the address of the start of a structure is cast
110547 + * to a pointer of a structure of a different type, or a
110548 + * structure pointer type is cast to a different structure pointer type
110549 + */
110550 +static unsigned int find_bad_casts(void)
110551 +{
110552 + basic_block bb;
110553 +
110554 + handle_local_var_initializers();
110555 +
110556 + FOR_ALL_BB_FN(bb, cfun) {
110557 + gimple_stmt_iterator gsi;
110558 +
110559 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
110560 + gimple stmt;
110561 + const_tree lhs;
110562 + const_tree lhs_type;
110563 + const_tree rhs1;
110564 + const_tree rhs_type;
110565 + const_tree ptr_lhs_type;
110566 + const_tree ptr_rhs_type;
110567 + const_tree op0;
110568 + const_tree op0_type;
110569 + enum tree_code rhs_code;
110570 +
110571 + stmt = gsi_stmt(gsi);
110572 +
110573 +#ifdef __DEBUG_PLUGIN
110574 +#ifdef __DEBUG_VERBOSE
110575 + debug_gimple_stmt(stmt);
110576 + debug_tree(gimple_get_lhs(stmt));
110577 +#endif
110578 +#endif
110579 +
110580 + if (gimple_code(stmt) != GIMPLE_ASSIGN)
110581 + continue;
110582 +
110583 +#ifdef __DEBUG_PLUGIN
110584 +#ifdef __DEBUG_VERBOSE
110585 + debug_tree(gimple_assign_rhs1(stmt));
110586 +#endif
110587 +#endif
110588 +
110589 + rhs_code = gimple_assign_rhs_code(stmt);
110590 +
110591 + if (rhs_code != ADDR_EXPR && rhs_code != SSA_NAME)
110592 + continue;
110593 +
110594 + lhs = gimple_get_lhs(stmt);
110595 + lhs_type = TREE_TYPE(lhs);
110596 + rhs1 = gimple_assign_rhs1(stmt);
110597 + rhs_type = TREE_TYPE(rhs1);
110598 +
110599 + if (TREE_CODE(rhs_type) != POINTER_TYPE ||
110600 + TREE_CODE(lhs_type) != POINTER_TYPE)
110601 + continue;
110602 +
110603 + ptr_lhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(lhs_type))));
110604 + ptr_rhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(rhs_type))));
110605 +
110606 + if (ptr_rhs_type == void_type_node)
110607 + continue;
110608 +
110609 + if (ptr_lhs_type == void_type_node)
110610 + continue;
110611 +
110612 + if (dominated_by_is_err(rhs1, bb))
110613 + continue;
110614 +
110615 + if (TREE_CODE(ptr_rhs_type) != RECORD_TYPE) {
110616 +#ifndef __DEBUG_PLUGIN
110617 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_lhs_type)))
110618 +#endif
110619 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
110620 + continue;
110621 + }
110622 +
110623 + if (rhs_code == SSA_NAME && ptr_lhs_type == ptr_rhs_type)
110624 + continue;
110625 +
110626 + if (rhs_code == ADDR_EXPR) {
110627 + op0 = TREE_OPERAND(rhs1, 0);
110628 +
110629 + if (op0 == NULL_TREE)
110630 + continue;
110631 +
110632 + if (TREE_CODE(op0) != VAR_DECL)
110633 + continue;
110634 +
110635 + op0_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(op0))));
110636 + if (op0_type == ptr_lhs_type)
110637 + continue;
110638 +
110639 +#ifndef __DEBUG_PLUGIN
110640 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(op0_type)))
110641 +#endif
110642 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, op0_type);
110643 + } else {
110644 + const_tree ssa_name_var = SSA_NAME_VAR(rhs1);
110645 + /* skip bogus type casts introduced by container_of */
110646 + if (ssa_name_var != NULL_TREE && DECL_NAME(ssa_name_var) &&
110647 + !strcmp((const char *)DECL_NAME_POINTER(ssa_name_var), "__mptr"))
110648 + continue;
110649 +#ifndef __DEBUG_PLUGIN
110650 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_rhs_type)))
110651 +#endif
110652 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
110653 + }
110654 +
110655 + }
110656 + }
110657 + return 0;
110658 +}
110659 +
110660 +#if BUILDING_GCC_VERSION >= 4009
110661 +static const struct pass_data randomize_layout_bad_cast_data = {
110662 +#else
110663 +static struct gimple_opt_pass randomize_layout_bad_cast = {
110664 + .pass = {
110665 +#endif
110666 + .type = GIMPLE_PASS,
110667 + .name = "randomize_layout_bad_cast",
110668 +#if BUILDING_GCC_VERSION >= 4008
110669 + .optinfo_flags = OPTGROUP_NONE,
110670 +#endif
110671 +#if BUILDING_GCC_VERSION >= 4009
110672 + .has_gate = false,
110673 + .has_execute = true,
110674 +#else
110675 + .gate = NULL,
110676 + .execute = find_bad_casts,
110677 + .sub = NULL,
110678 + .next = NULL,
110679 + .static_pass_number = 0,
110680 +#endif
110681 + .tv_id = TV_NONE,
110682 + .properties_required = PROP_cfg,
110683 + .properties_provided = 0,
110684 + .properties_destroyed = 0,
110685 + .todo_flags_start = 0,
110686 + .todo_flags_finish = TODO_dump_func
110687 +#if BUILDING_GCC_VERSION < 4009
110688 + }
110689 +#endif
110690 +};
110691 +
110692 +#if BUILDING_GCC_VERSION >= 4009
110693 +namespace {
110694 +class randomize_layout_bad_cast : public gimple_opt_pass {
110695 +public:
110696 + randomize_layout_bad_cast() : gimple_opt_pass(randomize_layout_bad_cast_data, g) {}
110697 + unsigned int execute() { return find_bad_casts(); }
110698 +};
110699 +}
110700 +#endif
110701 +
110702 +static struct opt_pass *make_randomize_layout_bad_cast(void)
110703 +{
110704 +#if BUILDING_GCC_VERSION >= 4009
110705 + return new randomize_layout_bad_cast();
110706 +#else
110707 + return &randomize_layout_bad_cast.pass;
110708 +#endif
110709 +}
110710 +
110711 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
110712 +{
110713 + int i;
110714 + const char * const plugin_name = plugin_info->base_name;
110715 + const int argc = plugin_info->argc;
110716 + const struct plugin_argument * const argv = plugin_info->argv;
110717 + bool enable = true;
110718 + int obtained_seed = 0;
110719 + struct register_pass_info randomize_layout_bad_cast_info;
110720 +
110721 + randomize_layout_bad_cast_info.pass = make_randomize_layout_bad_cast();
110722 + randomize_layout_bad_cast_info.reference_pass_name = "ssa";
110723 + randomize_layout_bad_cast_info.ref_pass_instance_number = 1;
110724 + randomize_layout_bad_cast_info.pos_op = PASS_POS_INSERT_AFTER;
110725 +
110726 + if (!plugin_default_version_check(version, &gcc_version)) {
110727 + error(G_("incompatible gcc/plugin versions"));
110728 + return 1;
110729 + }
110730 +
110731 + if (strcmp(lang_hooks.name, "GNU C")) {
110732 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
110733 + enable = false;
110734 + }
110735 +
110736 + for (i = 0; i < argc; ++i) {
110737 + if (!strcmp(argv[i].key, "disable")) {
110738 + enable = false;
110739 + continue;
110740 + }
110741 + if (!strcmp(argv[i].key, "performance-mode")) {
110742 + performance_mode = 1;
110743 + continue;
110744 + }
110745 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
110746 + }
110747 +
110748 + if (strlen(randstruct_seed) != 64) {
110749 + error(G_("invalid seed value supplied for %s plugin"), plugin_name);
110750 + return 1;
110751 + }
110752 + obtained_seed = sscanf(randstruct_seed, "%016llx%016llx%016llx%016llx",
110753 + &shuffle_seed[0], &shuffle_seed[1], &shuffle_seed[2], &shuffle_seed[3]);
110754 + if (obtained_seed != 4) {
110755 + error(G_("Invalid seed supplied for %s plugin"), plugin_name);
110756 + return 1;
110757 + }
110758 +
110759 + register_callback(plugin_name, PLUGIN_INFO, NULL, &randomize_layout_plugin_info);
110760 + if (enable) {
110761 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
110762 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &randomize_layout_bad_cast_info);
110763 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
110764 + register_callback(plugin_name, PLUGIN_FINISH_DECL, randomize_layout_finish_decl, NULL);
110765 + }
110766 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
110767 +
110768 + return 0;
110769 +}
110770 diff --git a/tools/gcc/size_overflow_plugin/.gitignore b/tools/gcc/size_overflow_plugin/.gitignore
110771 new file mode 100644
110772 index 0000000..1f0214f
110773 --- /dev/null
110774 +++ b/tools/gcc/size_overflow_plugin/.gitignore
110775 @@ -0,0 +1,3 @@
110776 +randomize_layout_seed.h
110777 +size_overflow_hash.h
110778 +size_overflow_hash_aux.h
110779 diff --git a/tools/gcc/size_overflow_plugin/Makefile b/tools/gcc/size_overflow_plugin/Makefile
110780 new file mode 100644
110781 index 0000000..1ae2ed5
110782 --- /dev/null
110783 +++ b/tools/gcc/size_overflow_plugin/Makefile
110784 @@ -0,0 +1,20 @@
110785 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
110786 +always := $($(HOSTLIBS)-y)
110787 +
110788 +size_overflow_plugin-objs := $(patsubst $(srctree)/$(src)/%.c,%.o,$(wildcard $(srctree)/$(src)/*.c))
110789 +
110790 +$(patsubst $(srctree)/$(src)/%.c,$(obj)/%.o,$(wildcard $(srctree)/$(src)/*.c)): $(objtree)/$(obj)/size_overflow_hash.h $(objtree)/$(obj)/size_overflow_hash_aux.h
110791 +
110792 +quiet_cmd_build_size_overflow_hash = GENHASH $@
110793 + cmd_build_size_overflow_hash = \
110794 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash -d $< -o $@
110795 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
110796 + $(call if_changed,build_size_overflow_hash)
110797 +
110798 +quiet_cmd_build_size_overflow_hash_aux = GENHASH $@
110799 + cmd_build_size_overflow_hash_aux = \
110800 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash_aux -d $< -o $@
110801 +$(objtree)/$(obj)/size_overflow_hash_aux.h: $(src)/size_overflow_hash_aux.data FORCE
110802 + $(call if_changed,build_size_overflow_hash_aux)
110803 +
110804 +targets += size_overflow_hash.h size_overflow_hash_aux.h
110805 diff --git a/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
110806 new file mode 100644
110807 index 0000000..12b1e3b
110808 --- /dev/null
110809 +++ b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
110810 @@ -0,0 +1,102 @@
110811 +#!/bin/bash
110812 +
110813 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
110814 +
110815 +header1="size_overflow_hash.h"
110816 +database="size_overflow_hash.data"
110817 +n=65536
110818 +hashtable_name="size_overflow_hash"
110819 +
110820 +usage() {
110821 +cat <<EOF
110822 +usage: $0 options
110823 +OPTIONS:
110824 + -h|--help help
110825 + -o header file
110826 + -d database file
110827 + -n hash array size
110828 + -s name of the hash table
110829 +EOF
110830 + return 0
110831 +}
110832 +
110833 +while true
110834 +do
110835 + case "$1" in
110836 + -h|--help) usage && exit 0;;
110837 + -n) n=$2; shift 2;;
110838 + -o) header1="$2"; shift 2;;
110839 + -d) database="$2"; shift 2;;
110840 + -s) hashtable_name="$2"; shift 2;;
110841 + --) shift 1; break ;;
110842 + *) break ;;
110843 + esac
110844 +done
110845 +
110846 +create_defines() {
110847 + for i in `seq 0 31`
110848 + do
110849 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
110850 + done
110851 + echo >> "$header1"
110852 +}
110853 +
110854 +create_structs() {
110855 + rm -f "$header1"
110856 +
110857 + create_defines
110858 +
110859 + cat "$database" | while read data
110860 + do
110861 + data_array=($data)
110862 + struct_hash_name="${data_array[0]}"
110863 + funcn="${data_array[1]}"
110864 + params="${data_array[2]}"
110865 + next="${data_array[4]}"
110866 +
110867 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
110868 +
110869 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
110870 + echo -en "\t.param\t= " >> "$header1"
110871 + line=
110872 + for param_num in ${params//-/ };
110873 + do
110874 + line="${line}PARAM"$param_num"|"
110875 + done
110876 +
110877 + echo -e "${line%?},\n};\n" >> "$header1"
110878 + done
110879 +}
110880 +
110881 +create_headers() {
110882 + echo "const struct size_overflow_hash * const $hashtable_name[$n] = {" >> "$header1"
110883 +}
110884 +
110885 +create_array_elements() {
110886 + index=0
110887 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
110888 + do
110889 + data_array=($data)
110890 + i="${data_array[3]}"
110891 + hash="${data_array[0]}"
110892 + while [[ $index -lt $i ]]
110893 + do
110894 + echo -e "\t["$index"]\t= NULL," >> "$header1"
110895 + index=$(($index + 1))
110896 + done
110897 + index=$(($index + 1))
110898 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
110899 + done
110900 + echo '};' >> $header1
110901 +}
110902 +
110903 +size_overflow_plugin_dir=`dirname $header1`
110904 +if [ "$size_overflow_plugin_dir" != '.' ]; then
110905 + mkdir -p "$size_overflow_plugin_dir" 2> /dev/null
110906 +fi
110907 +
110908 +create_structs
110909 +create_headers
110910 +create_array_elements
110911 +
110912 +exit 0
110913 diff --git a/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
110914 new file mode 100644
110915 index 0000000..c43901f
110916 --- /dev/null
110917 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
110918 @@ -0,0 +1,748 @@
110919 +/*
110920 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
110921 + * Licensed under the GPL v2, or (at your option) v3
110922 + *
110923 + * Homepage:
110924 + * http://www.grsecurity.net/~ephox/overflow_plugin/
110925 + *
110926 + * Documentation:
110927 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
110928 + *
110929 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
110930 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
110931 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
110932 + *
110933 + * Usage:
110934 + * $ make
110935 + * $ make run
110936 + */
110937 +
110938 +#include "gcc-common.h"
110939 +#include "size_overflow.h"
110940 +
110941 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs);
110942 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs);
110943 +
110944 +// data for the size_overflow asm stmt
110945 +struct asm_data {
110946 + gimple def_stmt;
110947 + tree input;
110948 + tree output;
110949 +};
110950 +
110951 +#if BUILDING_GCC_VERSION <= 4007
110952 +static VEC(tree, gc) *create_asm_io_list(tree string, tree io)
110953 +#else
110954 +static vec<tree, va_gc> *create_asm_io_list(tree string, tree io)
110955 +#endif
110956 +{
110957 + tree list;
110958 +#if BUILDING_GCC_VERSION <= 4007
110959 + VEC(tree, gc) *vec_list = NULL;
110960 +#else
110961 + vec<tree, va_gc> *vec_list = NULL;
110962 +#endif
110963 +
110964 + list = build_tree_list(NULL_TREE, string);
110965 + list = chainon(NULL_TREE, build_tree_list(list, io));
110966 +#if BUILDING_GCC_VERSION <= 4007
110967 + VEC_safe_push(tree, gc, vec_list, list);
110968 +#else
110969 + vec_safe_push(vec_list, list);
110970 +#endif
110971 + return vec_list;
110972 +}
110973 +
110974 +static void create_asm_stmt(const char *str, tree str_input, tree str_output, struct asm_data *asm_data)
110975 +{
110976 + gimple asm_stmt;
110977 + gimple_stmt_iterator gsi;
110978 +#if BUILDING_GCC_VERSION <= 4007
110979 + VEC(tree, gc) *input, *output = NULL;
110980 +#else
110981 + vec<tree, va_gc> *input, *output = NULL;
110982 +#endif
110983 +
110984 + input = create_asm_io_list(str_input, asm_data->input);
110985 +
110986 + if (asm_data->output)
110987 + output = create_asm_io_list(str_output, asm_data->output);
110988 +
110989 + asm_stmt = gimple_build_asm_vec(str, input, output, NULL, NULL);
110990 + gsi = gsi_for_stmt(asm_data->def_stmt);
110991 + gsi_insert_after(&gsi, asm_stmt, GSI_NEW_STMT);
110992 +
110993 + if (asm_data->output)
110994 + SSA_NAME_DEF_STMT(asm_data->output) = asm_stmt;
110995 +}
110996 +
110997 +static void replace_call_lhs(const struct asm_data *asm_data)
110998 +{
110999 + gimple_set_lhs(asm_data->def_stmt, asm_data->input);
111000 + update_stmt(asm_data->def_stmt);
111001 + SSA_NAME_DEF_STMT(asm_data->input) = asm_data->def_stmt;
111002 +}
111003 +
111004 +static enum mark search_intentional_phi(struct pointer_set_t *visited, const_tree result)
111005 +{
111006 + enum mark cur_fndecl_attr;
111007 + gimple phi = get_def_stmt(result);
111008 + unsigned int i, n = gimple_phi_num_args(phi);
111009 +
111010 + pointer_set_insert(visited, phi);
111011 + for (i = 0; i < n; i++) {
111012 + tree arg = gimple_phi_arg_def(phi, i);
111013 +
111014 + cur_fndecl_attr = search_intentional(visited, arg);
111015 + if (cur_fndecl_attr != MARK_NO)
111016 + return cur_fndecl_attr;
111017 + }
111018 + return MARK_NO;
111019 +}
111020 +
111021 +static enum mark search_intentional_binary(struct pointer_set_t *visited, const_tree lhs)
111022 +{
111023 + enum mark cur_fndecl_attr;
111024 + const_tree rhs1, rhs2;
111025 + gimple def_stmt = get_def_stmt(lhs);
111026 +
111027 + rhs1 = gimple_assign_rhs1(def_stmt);
111028 + rhs2 = gimple_assign_rhs2(def_stmt);
111029 +
111030 + cur_fndecl_attr = search_intentional(visited, rhs1);
111031 + if (cur_fndecl_attr != MARK_NO)
111032 + return cur_fndecl_attr;
111033 + return search_intentional(visited, rhs2);
111034 +}
111035 +
111036 +// Look up the intentional_overflow attribute on the caller and the callee functions.
111037 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs)
111038 +{
111039 + const_gimple def_stmt;
111040 +
111041 + if (TREE_CODE(lhs) != SSA_NAME)
111042 + return get_intentional_attr_type(lhs);
111043 +
111044 + def_stmt = get_def_stmt(lhs);
111045 + if (!def_stmt)
111046 + return MARK_NO;
111047 +
111048 + if (pointer_set_contains(visited, def_stmt))
111049 + return MARK_NO;
111050 +
111051 + switch (gimple_code(def_stmt)) {
111052 + case GIMPLE_NOP:
111053 + return search_intentional(visited, SSA_NAME_VAR(lhs));
111054 + case GIMPLE_ASM:
111055 + if (is_size_overflow_intentional_asm_turn_off(def_stmt))
111056 + return MARK_TURN_OFF;
111057 + return MARK_NO;
111058 + case GIMPLE_CALL:
111059 + return MARK_NO;
111060 + case GIMPLE_PHI:
111061 + return search_intentional_phi(visited, lhs);
111062 + case GIMPLE_ASSIGN:
111063 + switch (gimple_num_ops(def_stmt)) {
111064 + case 2:
111065 + return search_intentional(visited, gimple_assign_rhs1(def_stmt));
111066 + case 3:
111067 + return search_intentional_binary(visited, lhs);
111068 + }
111069 + case GIMPLE_RETURN:
111070 + return MARK_NO;
111071 + default:
111072 + debug_gimple_stmt((gimple)def_stmt);
111073 + error("%s: unknown gimple code", __func__);
111074 + gcc_unreachable();
111075 + }
111076 +}
111077 +
111078 +// Check the intentional_overflow attribute and create the asm comment string for the size_overflow asm stmt.
111079 +static enum mark check_intentional_attribute_gimple(const_tree arg, const_gimple stmt, unsigned int argnum)
111080 +{
111081 + const_tree fndecl;
111082 + struct pointer_set_t *visited;
111083 + enum mark cur_fndecl_attr, decl_attr = MARK_NO;
111084 +
111085 + fndecl = get_interesting_orig_fndecl(stmt, argnum);
111086 + if (is_end_intentional_intentional_attr(fndecl, argnum))
111087 + decl_attr = MARK_NOT_INTENTIONAL;
111088 + else if (is_yes_intentional_attr(fndecl, argnum))
111089 + decl_attr = MARK_YES;
111090 + else if (is_turn_off_intentional_attr(fndecl) || is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
111091 + return MARK_TURN_OFF;
111092 + }
111093 +
111094 + visited = pointer_set_create();
111095 + cur_fndecl_attr = search_intentional(visited, arg);
111096 + pointer_set_destroy(visited);
111097 +
111098 + switch (cur_fndecl_attr) {
111099 + case MARK_NO:
111100 + case MARK_TURN_OFF:
111101 + return cur_fndecl_attr;
111102 + default:
111103 + print_missing_intentional(decl_attr, cur_fndecl_attr, fndecl, argnum);
111104 + return MARK_YES;
111105 + }
111106 +}
111107 +
111108 +static void check_missing_size_overflow_attribute(tree var)
111109 +{
111110 + tree orig_fndecl;
111111 + unsigned int num;
111112 +
111113 + if (is_a_return_check(var))
111114 + orig_fndecl = DECL_ORIGIN(var);
111115 + else
111116 + orig_fndecl = DECL_ORIGIN(current_function_decl);
111117 +
111118 + num = get_function_num(var, orig_fndecl);
111119 + if (num == CANNOT_FIND_ARG)
111120 + return;
111121 +
111122 + is_missing_function(orig_fndecl, num);
111123 +}
111124 +
111125 +static void search_size_overflow_attribute_phi(struct pointer_set_t *visited, const_tree result)
111126 +{
111127 + gimple phi = get_def_stmt(result);
111128 + unsigned int i, n = gimple_phi_num_args(phi);
111129 +
111130 + pointer_set_insert(visited, phi);
111131 + for (i = 0; i < n; i++) {
111132 + tree arg = gimple_phi_arg_def(phi, i);
111133 +
111134 + search_size_overflow_attribute(visited, arg);
111135 + }
111136 +}
111137 +
111138 +static void search_size_overflow_attribute_binary(struct pointer_set_t *visited, const_tree lhs)
111139 +{
111140 + const_gimple def_stmt = get_def_stmt(lhs);
111141 + tree rhs1, rhs2;
111142 +
111143 + rhs1 = gimple_assign_rhs1(def_stmt);
111144 + rhs2 = gimple_assign_rhs2(def_stmt);
111145 +
111146 + search_size_overflow_attribute(visited, rhs1);
111147 + search_size_overflow_attribute(visited, rhs2);
111148 +}
111149 +
111150 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs)
111151 +{
111152 + const_gimple def_stmt;
111153 +
111154 + if (TREE_CODE(lhs) == PARM_DECL) {
111155 + check_missing_size_overflow_attribute(lhs);
111156 + return;
111157 + }
111158 +
111159 + def_stmt = get_def_stmt(lhs);
111160 + if (!def_stmt)
111161 + return;
111162 +
111163 + if (pointer_set_insert(visited, def_stmt))
111164 + return;
111165 +
111166 + switch (gimple_code(def_stmt)) {
111167 + case GIMPLE_NOP:
111168 + return search_size_overflow_attribute(visited, SSA_NAME_VAR(lhs));
111169 + case GIMPLE_ASM:
111170 + return;
111171 + case GIMPLE_CALL: {
111172 + tree fndecl = gimple_call_fndecl(def_stmt);
111173 +
111174 + if (fndecl == NULL_TREE)
111175 + return;
111176 + check_missing_size_overflow_attribute(fndecl);
111177 + return;
111178 + }
111179 + case GIMPLE_PHI:
111180 + return search_size_overflow_attribute_phi(visited, lhs);
111181 + case GIMPLE_ASSIGN:
111182 + switch (gimple_num_ops(def_stmt)) {
111183 + case 2:
111184 + return search_size_overflow_attribute(visited, gimple_assign_rhs1(def_stmt));
111185 + case 3:
111186 + return search_size_overflow_attribute_binary(visited, lhs);
111187 + }
111188 + default:
111189 + debug_gimple_stmt((gimple)def_stmt);
111190 + error("%s: unknown gimple code", __func__);
111191 + gcc_unreachable();
111192 + }
111193 +}
111194 +
111195 +// Search missing entries in the hash table (invoked from the gimple pass)
111196 +static void search_missing_size_overflow_attribute_gimple(const_gimple stmt, unsigned int num)
111197 +{
111198 + tree fndecl = NULL_TREE;
111199 + tree lhs;
111200 + struct pointer_set_t *visited;
111201 +
111202 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl)))
111203 + return;
111204 +
111205 + if (num == 0) {
111206 + gcc_assert(gimple_code(stmt) == GIMPLE_RETURN);
111207 + lhs = gimple_return_retval(stmt);
111208 + } else {
111209 + gcc_assert(is_gimple_call(stmt));
111210 + lhs = gimple_call_arg(stmt, num - 1);
111211 + fndecl = gimple_call_fndecl(stmt);
111212 + }
111213 +
111214 + if (fndecl != NULL_TREE && is_turn_off_intentional_attr(DECL_ORIGIN(fndecl)))
111215 + return;
111216 +
111217 + visited = pointer_set_create();
111218 + search_size_overflow_attribute(visited, lhs);
111219 + pointer_set_destroy(visited);
111220 +}
111221 +
111222 +static void create_output_from_phi(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
111223 +{
111224 + gimple_stmt_iterator gsi;
111225 + gimple assign;
111226 +
111227 + assign = gimple_build_assign(asm_data->input, asm_data->output);
111228 + gsi = gsi_for_stmt(stmt);
111229 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
111230 + asm_data->def_stmt = assign;
111231 +
111232 + asm_data->output = create_new_var(TREE_TYPE(asm_data->output));
111233 + asm_data->output = make_ssa_name(asm_data->output, stmt);
111234 + if (gimple_code(stmt) == GIMPLE_RETURN)
111235 + gimple_return_set_retval(stmt, asm_data->output);
111236 + else
111237 + gimple_call_set_arg(stmt, argnum - 1, asm_data->output);
111238 + update_stmt(stmt);
111239 +}
111240 +
111241 +static char *create_asm_comment(unsigned int argnum, const_gimple stmt , const char *mark_str)
111242 +{
111243 + const char *fn_name;
111244 + char *asm_comment;
111245 + unsigned int len;
111246 +
111247 + if (argnum == 0)
111248 + fn_name = DECL_NAME_POINTER(current_function_decl);
111249 + else
111250 + fn_name = DECL_NAME_POINTER(gimple_call_fndecl(stmt));
111251 +
111252 + len = asprintf(&asm_comment, "%s %s %u", mark_str, fn_name, argnum);
111253 + gcc_assert(len > 0);
111254 +
111255 + return asm_comment;
111256 +}
111257 +
111258 +static const char *convert_mark_to_str(enum mark mark)
111259 +{
111260 + switch (mark) {
111261 + case MARK_NO:
111262 + return OK_ASM_STR;
111263 + case MARK_YES:
111264 + case MARK_NOT_INTENTIONAL:
111265 + return YES_ASM_STR;
111266 + case MARK_TURN_OFF:
111267 + return TURN_OFF_ASM_STR;
111268 + }
111269 +
111270 + gcc_unreachable();
111271 +}
111272 +
111273 +/* Create the input of the size_overflow asm stmt.
111274 + * When the arg of the callee function is a parm_decl it creates this kind of size_overflow asm stmt:
111275 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
111276 + * The input field in asm_data will be empty if there is no need for further size_overflow asm stmt insertion.
111277 + * otherwise create the input (for a phi stmt the output too) of the asm stmt.
111278 + */
111279 +static void create_asm_input(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
111280 +{
111281 + if (!asm_data->def_stmt) {
111282 + asm_data->input = NULL_TREE;
111283 + return;
111284 + }
111285 +
111286 + asm_data->input = create_new_var(TREE_TYPE(asm_data->output));
111287 + asm_data->input = make_ssa_name(asm_data->input, asm_data->def_stmt);
111288 +
111289 + switch (gimple_code(asm_data->def_stmt)) {
111290 + case GIMPLE_ASSIGN:
111291 + case GIMPLE_CALL:
111292 + replace_call_lhs(asm_data);
111293 + break;
111294 + case GIMPLE_PHI:
111295 + create_output_from_phi(stmt, argnum, asm_data);
111296 + break;
111297 + case GIMPLE_NOP: {
111298 + enum mark mark;
111299 + const char *mark_str;
111300 + char *asm_comment;
111301 +
111302 + mark = check_intentional_attribute_gimple(asm_data->output, stmt, argnum);
111303 +
111304 + asm_data->input = asm_data->output;
111305 + asm_data->output = NULL;
111306 + asm_data->def_stmt = stmt;
111307 +
111308 + mark_str = convert_mark_to_str(mark);
111309 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
111310 +
111311 + create_asm_stmt(asm_comment, build_string(3, "rm"), NULL, asm_data);
111312 + free(asm_comment);
111313 + asm_data->input = NULL_TREE;
111314 + break;
111315 + }
111316 + case GIMPLE_ASM:
111317 + if (is_size_overflow_asm(asm_data->def_stmt)) {
111318 + asm_data->input = NULL_TREE;
111319 + break;
111320 + }
111321 + default:
111322 + debug_gimple_stmt(asm_data->def_stmt);
111323 + gcc_unreachable();
111324 + }
111325 +}
111326 +
111327 +/* This is the gimple part of searching for a missing size_overflow attribute. If the intentional_overflow attribute type
111328 + * is of the right kind create the appropriate size_overflow asm stmts:
111329 + * __asm__("# size_overflow" : =rm" D.3344_8 : "0" cicus.4_16);
111330 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
111331 + */
111332 +static void create_size_overflow_asm(gimple stmt, tree output_node, unsigned int argnum)
111333 +{
111334 + struct asm_data asm_data;
111335 + const char *mark_str;
111336 + char *asm_comment;
111337 + enum mark mark;
111338 +
111339 + if (is_gimple_constant(output_node))
111340 + return;
111341 +
111342 + asm_data.output = output_node;
111343 + mark = check_intentional_attribute_gimple(asm_data.output, stmt, argnum);
111344 + if (mark != MARK_TURN_OFF)
111345 + search_missing_size_overflow_attribute_gimple(stmt, argnum);
111346 +
111347 + asm_data.def_stmt = get_def_stmt(asm_data.output);
111348 + if (is_size_overflow_intentional_asm_turn_off(asm_data.def_stmt))
111349 + return;
111350 +
111351 + create_asm_input(stmt, argnum, &asm_data);
111352 + if (asm_data.input == NULL_TREE)
111353 + return;
111354 +
111355 + mark_str = convert_mark_to_str(mark);
111356 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
111357 + create_asm_stmt(asm_comment, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
111358 + free(asm_comment);
111359 +}
111360 +
111361 +// Insert an asm stmt with "MARK_TURN_OFF", "MARK_YES" or "MARK_NOT_INTENTIONAL".
111362 +static bool create_mark_asm(gimple stmt, enum mark mark)
111363 +{
111364 + struct asm_data asm_data;
111365 + const char *asm_str;
111366 +
111367 + switch (mark) {
111368 + case MARK_TURN_OFF:
111369 + asm_str = TURN_OFF_ASM_STR;
111370 + break;
111371 + case MARK_NOT_INTENTIONAL:
111372 + case MARK_YES:
111373 + asm_str = YES_ASM_STR;
111374 + break;
111375 + default:
111376 + gcc_unreachable();
111377 + }
111378 +
111379 + asm_data.def_stmt = stmt;
111380 + asm_data.output = gimple_call_lhs(stmt);
111381 +
111382 + if (asm_data.output == NULL_TREE) {
111383 + asm_data.input = gimple_call_arg(stmt, 0);
111384 + if (is_gimple_constant(asm_data.input))
111385 + return false;
111386 + asm_data.output = NULL;
111387 + create_asm_stmt(asm_str, build_string(3, "rm"), NULL, &asm_data);
111388 + return true;
111389 + }
111390 +
111391 + create_asm_input(stmt, 0, &asm_data);
111392 + gcc_assert(asm_data.input != NULL_TREE);
111393 +
111394 + create_asm_stmt(asm_str, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
111395 + return true;
111396 +}
111397 +
111398 +static void walk_use_def_ptr(struct pointer_set_t *visited, const_tree lhs)
111399 +{
111400 + gimple def_stmt;
111401 +
111402 + def_stmt = get_def_stmt(lhs);
111403 + if (!def_stmt)
111404 + return;
111405 +
111406 + if (pointer_set_insert(visited, def_stmt))
111407 + return;
111408 +
111409 + switch (gimple_code(def_stmt)) {
111410 + case GIMPLE_NOP:
111411 + case GIMPLE_ASM:
111412 + case GIMPLE_CALL:
111413 + break;
111414 + case GIMPLE_PHI: {
111415 + unsigned int i, n = gimple_phi_num_args(def_stmt);
111416 +
111417 + pointer_set_insert(visited, def_stmt);
111418 +
111419 + for (i = 0; i < n; i++) {
111420 + tree arg = gimple_phi_arg_def(def_stmt, i);
111421 +
111422 + walk_use_def_ptr(visited, arg);
111423 + }
111424 + }
111425 + case GIMPLE_ASSIGN:
111426 + switch (gimple_num_ops(def_stmt)) {
111427 + case 2:
111428 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
111429 + return;
111430 + case 3:
111431 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
111432 + walk_use_def_ptr(visited, gimple_assign_rhs2(def_stmt));
111433 + return;
111434 + default:
111435 + return;
111436 + }
111437 + default:
111438 + debug_gimple_stmt((gimple)def_stmt);
111439 + error("%s: unknown gimple code", __func__);
111440 + gcc_unreachable();
111441 + }
111442 +}
111443 +
111444 +// Look for a ptr - ptr expression (e.g., cpuset_common_file_read() s - page)
111445 +static void insert_mark_not_intentional_asm_at_ptr(const_tree arg)
111446 +{
111447 + struct pointer_set_t *visited;
111448 +
111449 + visited = pointer_set_create();
111450 + walk_use_def_ptr(visited, arg);
111451 + pointer_set_destroy(visited);
111452 +}
111453 +
111454 +// Determine the return value and insert the asm stmt to mark the return stmt.
111455 +static void insert_asm_ret(gimple stmt)
111456 +{
111457 + tree ret;
111458 +
111459 + ret = gimple_return_retval(stmt);
111460 + create_size_overflow_asm(stmt, ret, 0);
111461 +}
111462 +
111463 +// Determine the correct arg index and arg and insert the asm stmt to mark the stmt.
111464 +static void insert_asm_arg(gimple stmt, unsigned int orig_argnum)
111465 +{
111466 + tree arg;
111467 + unsigned int argnum;
111468 +
111469 + argnum = get_correct_arg_count(orig_argnum, gimple_call_fndecl(stmt));
111470 + gcc_assert(argnum != 0);
111471 + if (argnum == CANNOT_FIND_ARG)
111472 + return;
111473 +
111474 + arg = gimple_call_arg(stmt, argnum - 1);
111475 + gcc_assert(arg != NULL_TREE);
111476 +
111477 + // skip all ptr - ptr expressions
111478 + insert_mark_not_intentional_asm_at_ptr(arg);
111479 +
111480 + create_size_overflow_asm(stmt, arg, argnum);
111481 +}
111482 +
111483 +// If a function arg or the return value is marked by the size_overflow attribute then set its index in the array.
111484 +static void set_argnum_attribute(const_tree attr, bool *argnums)
111485 +{
111486 + unsigned int argnum;
111487 + tree attr_value;
111488 +
111489 + for (attr_value = TREE_VALUE(attr); attr_value; attr_value = TREE_CHAIN(attr_value)) {
111490 + argnum = TREE_INT_CST_LOW(TREE_VALUE(attr_value));
111491 + argnums[argnum] = true;
111492 + }
111493 +}
111494 +
111495 +// If a function arg or the return value is in the hash table then set its index in the array.
111496 +static void set_argnum_hash(tree fndecl, bool *argnums)
111497 +{
111498 + unsigned int num;
111499 + const struct size_overflow_hash *hash;
111500 +
111501 + hash = get_function_hash(DECL_ORIGIN(fndecl));
111502 + if (!hash)
111503 + return;
111504 +
111505 + for (num = 0; num <= MAX_PARAM; num++) {
111506 + if (!(hash->param & (1U << num)))
111507 + continue;
111508 +
111509 + argnums[num] = true;
111510 + }
111511 +}
111512 +
111513 +static bool is_all_the_argnums_empty(bool *argnums)
111514 +{
111515 + unsigned int i;
111516 +
111517 + for (i = 0; i <= MAX_PARAM; i++)
111518 + if (argnums[i])
111519 + return false;
111520 + return true;
111521 +}
111522 +
111523 +// Check whether the arguments or the return value of the function are in the hash table or are marked by the size_overflow attribute.
111524 +static void search_interesting_args(tree fndecl, bool *argnums)
111525 +{
111526 + const_tree attr;
111527 +
111528 + set_argnum_hash(fndecl, argnums);
111529 + if (!is_all_the_argnums_empty(argnums))
111530 + return;
111531 +
111532 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
111533 + if (attr && TREE_VALUE(attr))
111534 + set_argnum_attribute(attr, argnums);
111535 +}
111536 +
111537 +/*
111538 + * Look up the intentional_overflow attribute that turns off ipa based duplication
111539 + * on the callee function.
111540 + */
111541 +static bool is_mark_turn_off_attribute(gimple stmt)
111542 +{
111543 + enum mark mark;
111544 + const_tree fndecl = gimple_call_fndecl(stmt);
111545 +
111546 + mark = get_intentional_attr_type(DECL_ORIGIN(fndecl));
111547 + if (mark == MARK_TURN_OFF)
111548 + return true;
111549 + return false;
111550 +}
111551 +
111552 +// 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
111553 +static void handle_interesting_function(gimple stmt)
111554 +{
111555 + unsigned int argnum;
111556 + tree fndecl;
111557 + bool orig_argnums[MAX_PARAM + 1] = {false};
111558 +
111559 + if (gimple_call_num_args(stmt) == 0)
111560 + return;
111561 + fndecl = gimple_call_fndecl(stmt);
111562 + if (fndecl == NULL_TREE)
111563 + return;
111564 + fndecl = DECL_ORIGIN(fndecl);
111565 +
111566 + if (is_mark_turn_off_attribute(stmt)) {
111567 + create_mark_asm(stmt, MARK_TURN_OFF);
111568 + return;
111569 + }
111570 +
111571 + search_interesting_args(fndecl, orig_argnums);
111572 +
111573 + for (argnum = 1; argnum < MAX_PARAM; argnum++)
111574 + if (orig_argnums[argnum])
111575 + insert_asm_arg(stmt, argnum);
111576 +}
111577 +
111578 +// 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
111579 +static void handle_interesting_ret(gimple stmt)
111580 +{
111581 + bool orig_argnums[MAX_PARAM + 1] = {false};
111582 +
111583 + search_interesting_args(current_function_decl, orig_argnums);
111584 +
111585 + if (orig_argnums[0])
111586 + insert_asm_ret(stmt);
111587 +}
111588 +
111589 +// Iterate over all the stmts and search for call and return stmts and mark them if they're in the hash table
111590 +static unsigned int search_interesting_functions(void)
111591 +{
111592 + basic_block bb;
111593 +
111594 + FOR_ALL_BB_FN(bb, cfun) {
111595 + gimple_stmt_iterator gsi;
111596 +
111597 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
111598 + gimple stmt = gsi_stmt(gsi);
111599 +
111600 + if (is_size_overflow_asm(stmt))
111601 + continue;
111602 +
111603 + if (is_gimple_call(stmt))
111604 + handle_interesting_function(stmt);
111605 + else if (gimple_code(stmt) == GIMPLE_RETURN)
111606 + handle_interesting_ret(stmt);
111607 + }
111608 + }
111609 + return 0;
111610 +}
111611 +
111612 +/*
111613 + * A lot of functions get inlined before the ipa passes so after the build_ssa gimple pass
111614 + * this pass inserts asm stmts to mark the interesting args
111615 + * that the ipa pass will detect and insert the size overflow checks for.
111616 + */
111617 +#if BUILDING_GCC_VERSION >= 4009
111618 +static const struct pass_data insert_size_overflow_asm_pass_data = {
111619 +#else
111620 +static struct gimple_opt_pass insert_size_overflow_asm_pass = {
111621 + .pass = {
111622 +#endif
111623 + .type = GIMPLE_PASS,
111624 + .name = "insert_size_overflow_asm",
111625 +#if BUILDING_GCC_VERSION >= 4008
111626 + .optinfo_flags = OPTGROUP_NONE,
111627 +#endif
111628 +#if BUILDING_GCC_VERSION >= 4009
111629 + .has_gate = false,
111630 + .has_execute = true,
111631 +#else
111632 + .gate = NULL,
111633 + .execute = search_interesting_functions,
111634 + .sub = NULL,
111635 + .next = NULL,
111636 + .static_pass_number = 0,
111637 +#endif
111638 + .tv_id = TV_NONE,
111639 + .properties_required = PROP_cfg,
111640 + .properties_provided = 0,
111641 + .properties_destroyed = 0,
111642 + .todo_flags_start = 0,
111643 + .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
111644 +#if BUILDING_GCC_VERSION < 4009
111645 + }
111646 +#endif
111647 +};
111648 +
111649 +#if BUILDING_GCC_VERSION >= 4009
111650 +namespace {
111651 +class insert_size_overflow_asm_pass : public gimple_opt_pass {
111652 +public:
111653 + insert_size_overflow_asm_pass() : gimple_opt_pass(insert_size_overflow_asm_pass_data, g) {}
111654 + unsigned int execute() { return search_interesting_functions(); }
111655 +};
111656 +}
111657 +#endif
111658 +
111659 +struct opt_pass *make_insert_size_overflow_asm_pass(void)
111660 +{
111661 +#if BUILDING_GCC_VERSION >= 4009
111662 + return new insert_size_overflow_asm_pass();
111663 +#else
111664 + return &insert_size_overflow_asm_pass.pass;
111665 +#endif
111666 +}
111667 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
111668 new file mode 100644
111669 index 0000000..73f0a12
111670 --- /dev/null
111671 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_core.c
111672 @@ -0,0 +1,943 @@
111673 +/*
111674 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
111675 + * Licensed under the GPL v2, or (at your option) v3
111676 + *
111677 + * Homepage:
111678 + * http://www.grsecurity.net/~ephox/overflow_plugin/
111679 + *
111680 + * Documentation:
111681 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
111682 + *
111683 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
111684 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
111685 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
111686 + *
111687 + * Usage:
111688 + * $ make
111689 + * $ make run
111690 + */
111691 +
111692 +#include "gcc-common.h"
111693 +#include "size_overflow.h"
111694 +
111695 +#define MIN_CHECK true
111696 +#define MAX_CHECK false
111697 +
111698 +static tree get_size_overflow_type(struct visited *visited, const_gimple stmt, const_tree node)
111699 +{
111700 + const_tree type;
111701 + tree new_type;
111702 +
111703 + gcc_assert(node != NULL_TREE);
111704 +
111705 + type = TREE_TYPE(node);
111706 +
111707 + if (pointer_set_contains(visited->my_stmts, stmt))
111708 + return TREE_TYPE(node);
111709 +
111710 + switch (TYPE_MODE(type)) {
111711 + case QImode:
111712 + new_type = size_overflow_type_HI;
111713 + break;
111714 + case HImode:
111715 + new_type = size_overflow_type_SI;
111716 + break;
111717 + case SImode:
111718 + new_type = size_overflow_type_DI;
111719 + break;
111720 + case DImode:
111721 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
111722 + new_type = TYPE_UNSIGNED(type) ? unsigned_intDI_type_node : intDI_type_node;
111723 + else
111724 + new_type = size_overflow_type_TI;
111725 + break;
111726 + case TImode:
111727 + gcc_assert(!TYPE_UNSIGNED(type));
111728 + new_type = size_overflow_type_TI;
111729 + break;
111730 + default:
111731 + debug_tree((tree)node);
111732 + error("%s: unsupported gcc configuration (%qE).", __func__, current_function_decl);
111733 + gcc_unreachable();
111734 + }
111735 +
111736 + if (TYPE_QUALS(type) != 0)
111737 + return build_qualified_type(new_type, TYPE_QUALS(type));
111738 + return new_type;
111739 +}
111740 +
111741 +static tree get_lhs(const_gimple stmt)
111742 +{
111743 + switch (gimple_code(stmt)) {
111744 + case GIMPLE_ASSIGN:
111745 + case GIMPLE_CALL:
111746 + return gimple_get_lhs(stmt);
111747 + case GIMPLE_PHI:
111748 + return gimple_phi_result(stmt);
111749 + default:
111750 + return NULL_TREE;
111751 + }
111752 +}
111753 +
111754 +static tree cast_to_new_size_overflow_type(struct visited *visited, gimple stmt, tree rhs, tree size_overflow_type, bool before)
111755 +{
111756 + gimple_stmt_iterator gsi;
111757 + tree lhs;
111758 + gimple new_stmt;
111759 +
111760 + if (rhs == NULL_TREE)
111761 + return NULL_TREE;
111762 +
111763 + gsi = gsi_for_stmt(stmt);
111764 + new_stmt = build_cast_stmt(visited, size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before, false);
111765 + pointer_set_insert(visited->my_stmts, new_stmt);
111766 +
111767 + lhs = get_lhs(new_stmt);
111768 + gcc_assert(lhs != NULL_TREE);
111769 + return lhs;
111770 +}
111771 +
111772 +tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before)
111773 +{
111774 + tree lhs, dst_type;
111775 + gimple_stmt_iterator gsi;
111776 +
111777 + if (rhs1 == NULL_TREE) {
111778 + debug_gimple_stmt(oldstmt);
111779 + error("%s: rhs1 is NULL_TREE", __func__);
111780 + gcc_unreachable();
111781 + }
111782 +
111783 + switch (gimple_code(oldstmt)) {
111784 + case GIMPLE_ASM:
111785 + lhs = rhs1;
111786 + break;
111787 + case GIMPLE_CALL:
111788 + case GIMPLE_ASSIGN:
111789 + lhs = gimple_get_lhs(oldstmt);
111790 + break;
111791 + default:
111792 + debug_gimple_stmt(oldstmt);
111793 + gcc_unreachable();
111794 + }
111795 +
111796 + gsi = gsi_for_stmt(oldstmt);
111797 + pointer_set_insert(visited->stmts, oldstmt);
111798 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
111799 + basic_block next_bb, cur_bb;
111800 + const_edge e;
111801 +
111802 + gcc_assert(before == false);
111803 + gcc_assert(stmt_can_throw_internal(oldstmt));
111804 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
111805 + gcc_assert(!gsi_end_p(gsi));
111806 +
111807 + cur_bb = gimple_bb(oldstmt);
111808 + next_bb = cur_bb->next_bb;
111809 + e = find_edge(cur_bb, next_bb);
111810 + gcc_assert(e != NULL);
111811 + gcc_assert(e->flags & EDGE_FALLTHRU);
111812 +
111813 + gsi = gsi_after_labels(next_bb);
111814 + gcc_assert(!gsi_end_p(gsi));
111815 +
111816 + before = true;
111817 + oldstmt = gsi_stmt(gsi);
111818 + }
111819 +
111820 + dst_type = get_size_overflow_type(visited, oldstmt, lhs);
111821 +
111822 + if (is_gimple_constant(rhs1))
111823 + return cast_a_tree(dst_type, rhs1);
111824 + return cast_to_new_size_overflow_type(visited, oldstmt, rhs1, dst_type, before);
111825 +}
111826 +
111827 +tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
111828 +{
111829 + gimple stmt;
111830 + gimple_stmt_iterator gsi;
111831 + tree size_overflow_type, new_var, lhs = gimple_assign_lhs(oldstmt);
111832 +
111833 + if (pointer_set_contains(visited->my_stmts, oldstmt))
111834 + return lhs;
111835 +
111836 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
111837 + rhs1 = gimple_assign_rhs1(oldstmt);
111838 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
111839 + }
111840 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
111841 + rhs2 = gimple_assign_rhs2(oldstmt);
111842 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
111843 + }
111844 +
111845 + stmt = gimple_copy(oldstmt);
111846 + gimple_set_location(stmt, gimple_location(oldstmt));
111847 + pointer_set_insert(visited->my_stmts, stmt);
111848 +
111849 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
111850 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
111851 +
111852 + size_overflow_type = get_size_overflow_type(visited, oldstmt, node);
111853 +
111854 + new_var = create_new_var(size_overflow_type);
111855 + new_var = make_ssa_name(new_var, stmt);
111856 + gimple_assign_set_lhs(stmt, new_var);
111857 +
111858 + if (rhs1 != NULL_TREE)
111859 + gimple_assign_set_rhs1(stmt, rhs1);
111860 +
111861 + if (rhs2 != NULL_TREE)
111862 + gimple_assign_set_rhs2(stmt, rhs2);
111863 +#if BUILDING_GCC_VERSION >= 4006
111864 + if (rhs3 != NULL_TREE)
111865 + gimple_assign_set_rhs3(stmt, rhs3);
111866 +#endif
111867 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
111868 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
111869 +
111870 + gsi = gsi_for_stmt(oldstmt);
111871 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
111872 + update_stmt(stmt);
111873 + pointer_set_insert(visited->stmts, oldstmt);
111874 + return gimple_assign_lhs(stmt);
111875 +}
111876 +
111877 +static tree cast_parm_decl(struct visited *visited, tree phi_ssa_name, tree arg, tree size_overflow_type, basic_block bb)
111878 +{
111879 + gimple assign;
111880 + gimple_stmt_iterator gsi;
111881 + basic_block first_bb;
111882 +
111883 + gcc_assert(SSA_NAME_IS_DEFAULT_DEF(arg));
111884 +
111885 + if (bb->index == 0) {
111886 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
111887 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
111888 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
111889 + bb = first_bb;
111890 + }
111891 +
111892 + gsi = gsi_after_labels(bb);
111893 + assign = build_cast_stmt(visited, size_overflow_type, arg, phi_ssa_name, &gsi, BEFORE_STMT, false);
111894 + pointer_set_insert(visited->my_stmts, assign);
111895 +
111896 + return gimple_assign_lhs(assign);
111897 +}
111898 +
111899 +static tree use_phi_ssa_name(struct visited *visited, tree ssa_name_var, tree new_arg)
111900 +{
111901 + gimple_stmt_iterator gsi;
111902 + gimple assign, def_stmt = get_def_stmt(new_arg);
111903 +
111904 + if (gimple_code(def_stmt) == GIMPLE_PHI) {
111905 + gsi = gsi_after_labels(gimple_bb(def_stmt));
111906 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, BEFORE_STMT, true);
111907 + } else {
111908 + gsi = gsi_for_stmt(def_stmt);
111909 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, AFTER_STMT, true);
111910 + }
111911 +
111912 + pointer_set_insert(visited->my_stmts, assign);
111913 + return gimple_assign_lhs(assign);
111914 +}
111915 +
111916 +static tree cast_visited_phi_arg(struct visited *visited, tree ssa_name_var, tree arg, tree size_overflow_type)
111917 +{
111918 + basic_block bb;
111919 + gimple_stmt_iterator gsi;
111920 + const_gimple def_stmt;
111921 + gimple assign;
111922 +
111923 + def_stmt = get_def_stmt(arg);
111924 + bb = gimple_bb(def_stmt);
111925 + gcc_assert(bb->index != 0);
111926 + gsi = gsi_after_labels(bb);
111927 +
111928 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, BEFORE_STMT, false);
111929 + pointer_set_insert(visited->my_stmts, assign);
111930 + return gimple_assign_lhs(assign);
111931 +}
111932 +
111933 +static tree create_new_phi_arg(struct visited *visited, tree ssa_name_var, tree new_arg, gimple oldstmt, unsigned int i)
111934 +{
111935 + tree size_overflow_type;
111936 + tree arg;
111937 + const_gimple def_stmt;
111938 +
111939 + if (new_arg != NULL_TREE && is_gimple_constant(new_arg))
111940 + return new_arg;
111941 +
111942 + arg = gimple_phi_arg_def(oldstmt, i);
111943 + def_stmt = get_def_stmt(arg);
111944 + gcc_assert(def_stmt != NULL);
111945 + size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
111946 +
111947 + switch (gimple_code(def_stmt)) {
111948 + case GIMPLE_PHI:
111949 + return cast_visited_phi_arg(visited, ssa_name_var, arg, size_overflow_type);
111950 + case GIMPLE_NOP: {
111951 + basic_block bb;
111952 +
111953 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
111954 + return cast_parm_decl(visited, ssa_name_var, arg, size_overflow_type, bb);
111955 + }
111956 + case GIMPLE_ASM: {
111957 + gimple_stmt_iterator gsi;
111958 + gimple assign, stmt = get_def_stmt(arg);
111959 +
111960 + gsi = gsi_for_stmt(stmt);
111961 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, AFTER_STMT, false);
111962 + pointer_set_insert(visited->my_stmts, assign);
111963 + return gimple_assign_lhs(assign);
111964 + }
111965 + default:
111966 + gcc_assert(new_arg != NULL_TREE);
111967 + gcc_assert(types_compatible_p(TREE_TYPE(new_arg), size_overflow_type));
111968 + return use_phi_ssa_name(visited, ssa_name_var, new_arg);
111969 + }
111970 +}
111971 +
111972 +static gimple overflow_create_phi_node(struct visited *visited, gimple oldstmt, tree result)
111973 +{
111974 + basic_block bb;
111975 + gimple phi;
111976 + gimple_seq seq;
111977 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
111978 +
111979 + bb = gsi_bb(gsi);
111980 +
111981 + if (result == NULL_TREE) {
111982 + tree old_result = gimple_phi_result(oldstmt);
111983 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, old_result);
111984 +
111985 + result = create_new_var(size_overflow_type);
111986 + }
111987 +
111988 + phi = create_phi_node(result, bb);
111989 + gimple_phi_set_result(phi, make_ssa_name(result, phi));
111990 + seq = phi_nodes(bb);
111991 + gsi = gsi_last(seq);
111992 + gsi_remove(&gsi, false);
111993 +
111994 + gsi = gsi_for_stmt(oldstmt);
111995 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
111996 + gimple_set_bb(phi, bb);
111997 + return phi;
111998 +}
111999 +
112000 +#if BUILDING_GCC_VERSION <= 4007
112001 +static tree create_new_phi_node(struct visited *visited, VEC(tree, heap) **args, tree ssa_name_var, gimple oldstmt)
112002 +#else
112003 +static tree create_new_phi_node(struct visited *visited, vec<tree, va_heap, vl_embed> *&args, tree ssa_name_var, gimple oldstmt)
112004 +#endif
112005 +{
112006 + gimple new_phi;
112007 + unsigned int i;
112008 + tree arg, result;
112009 + location_t loc = gimple_location(oldstmt);
112010 +
112011 +#if BUILDING_GCC_VERSION <= 4007
112012 + gcc_assert(!VEC_empty(tree, *args));
112013 +#else
112014 + gcc_assert(!args->is_empty());
112015 +#endif
112016 +
112017 + new_phi = overflow_create_phi_node(visited, oldstmt, ssa_name_var);
112018 + result = gimple_phi_result(new_phi);
112019 + ssa_name_var = SSA_NAME_VAR(result);
112020 +
112021 +#if BUILDING_GCC_VERSION <= 4007
112022 + FOR_EACH_VEC_ELT(tree, *args, i, arg) {
112023 +#else
112024 + FOR_EACH_VEC_SAFE_ELT(args, i, arg) {
112025 +#endif
112026 + arg = create_new_phi_arg(visited, ssa_name_var, arg, oldstmt, i);
112027 + add_phi_arg(new_phi, arg, gimple_phi_arg_edge(oldstmt, i), loc);
112028 + }
112029 +
112030 +#if BUILDING_GCC_VERSION <= 4007
112031 + VEC_free(tree, heap, *args);
112032 +#else
112033 + vec_free(args);
112034 +#endif
112035 + update_stmt(new_phi);
112036 + pointer_set_insert(visited->my_stmts, new_phi);
112037 + return result;
112038 +}
112039 +
112040 +static tree handle_phi(struct visited *visited, struct cgraph_node *caller_node, tree orig_result)
112041 +{
112042 + tree ssa_name_var = NULL_TREE;
112043 +#if BUILDING_GCC_VERSION <= 4007
112044 + VEC(tree, heap) *args = NULL;
112045 +#else
112046 + vec<tree, va_heap, vl_embed> *args = NULL;
112047 +#endif
112048 + gimple oldstmt = get_def_stmt(orig_result);
112049 + unsigned int i, len = gimple_phi_num_args(oldstmt);
112050 +
112051 + pointer_set_insert(visited->stmts, oldstmt);
112052 + for (i = 0; i < len; i++) {
112053 + tree arg, new_arg;
112054 +
112055 + arg = gimple_phi_arg_def(oldstmt, i);
112056 + new_arg = expand(visited, caller_node, arg);
112057 +
112058 + if (ssa_name_var == NULL_TREE && new_arg != NULL_TREE)
112059 + ssa_name_var = SSA_NAME_VAR(new_arg);
112060 +
112061 + if (is_gimple_constant(arg)) {
112062 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
112063 +
112064 + new_arg = cast_a_tree(size_overflow_type, arg);
112065 + }
112066 +
112067 +#if BUILDING_GCC_VERSION <= 4007
112068 + VEC_safe_push(tree, heap, args, new_arg);
112069 +#else
112070 + vec_safe_push(args, new_arg);
112071 +#endif
112072 + }
112073 +
112074 +#if BUILDING_GCC_VERSION <= 4007
112075 + return create_new_phi_node(visited, &args, ssa_name_var, oldstmt);
112076 +#else
112077 + return create_new_phi_node(visited, args, ssa_name_var, oldstmt);
112078 +#endif
112079 +}
112080 +
112081 +static tree create_cast_assign(struct visited *visited, gimple stmt)
112082 +{
112083 + tree rhs1 = gimple_assign_rhs1(stmt);
112084 + tree lhs = gimple_assign_lhs(stmt);
112085 + const_tree rhs1_type = TREE_TYPE(rhs1);
112086 + const_tree lhs_type = TREE_TYPE(lhs);
112087 +
112088 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
112089 + return create_assign(visited, stmt, lhs, AFTER_STMT);
112090 +
112091 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
112092 +}
112093 +
112094 +static bool skip_lhs_cast_check(const_gimple stmt)
112095 +{
112096 + const_tree rhs = gimple_assign_rhs1(stmt);
112097 + const_gimple def_stmt = get_def_stmt(rhs);
112098 +
112099 + // 3.8.2 kernel/futex_compat.c compat_exit_robust_list(): get_user() 64 ulong -> int (compat_long_t), int max
112100 + if (gimple_code(def_stmt) == GIMPLE_ASM)
112101 + return true;
112102 +
112103 + if (is_const_plus_unsigned_signed_truncation(rhs))
112104 + return true;
112105 +
112106 + return false;
112107 +}
112108 +
112109 +static tree create_string_param(tree string)
112110 +{
112111 + tree i_type, a_type;
112112 + const int length = TREE_STRING_LENGTH(string);
112113 +
112114 + gcc_assert(length > 0);
112115 +
112116 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
112117 + a_type = build_array_type(char_type_node, i_type);
112118 +
112119 + TREE_TYPE(string) = a_type;
112120 + TREE_CONSTANT(string) = 1;
112121 + TREE_READONLY(string) = 1;
112122 +
112123 + return build1(ADDR_EXPR, ptr_type_node, string);
112124 +}
112125 +
112126 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
112127 +{
112128 + gimple cond_stmt;
112129 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
112130 +
112131 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
112132 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
112133 + update_stmt(cond_stmt);
112134 +}
112135 +
112136 +static void insert_cond_result(struct cgraph_node *caller_node, basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
112137 +{
112138 + gimple func_stmt;
112139 + const_gimple def_stmt;
112140 + const_tree loc_line;
112141 + tree loc_file, ssa_name, current_func;
112142 + expanded_location xloc;
112143 + char *ssa_name_buf;
112144 + int len;
112145 + struct cgraph_edge *edge;
112146 + struct cgraph_node *callee_node;
112147 + int frequency;
112148 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
112149 +
112150 + def_stmt = get_def_stmt(arg);
112151 + xloc = expand_location(gimple_location(def_stmt));
112152 +
112153 + if (!gimple_has_location(def_stmt)) {
112154 + xloc = expand_location(gimple_location(stmt));
112155 + if (!gimple_has_location(stmt))
112156 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
112157 + }
112158 +
112159 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
112160 +
112161 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
112162 + loc_file = create_string_param(loc_file);
112163 +
112164 + current_func = build_string(DECL_NAME_LENGTH(current_function_decl) + 1, DECL_NAME_POINTER(current_function_decl));
112165 + current_func = create_string_param(current_func);
112166 +
112167 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
112168 + call_count++;
112169 + 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);
112170 + gcc_assert(len > 0);
112171 + ssa_name = build_string(len + 1, ssa_name_buf);
112172 + free(ssa_name_buf);
112173 + ssa_name = create_string_param(ssa_name);
112174 +
112175 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
112176 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
112177 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
112178 +
112179 + callee_node = cgraph_get_create_node(report_size_overflow_decl);
112180 + frequency = compute_call_stmt_bb_frequency(current_function_decl, bb_true);
112181 +
112182 + edge = cgraph_create_edge(caller_node, callee_node, func_stmt, bb_true->count, frequency, bb_true->loop_depth);
112183 + gcc_assert(edge != NULL);
112184 +}
112185 +
112186 +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)
112187 +{
112188 + basic_block cond_bb, join_bb, bb_true;
112189 + edge e;
112190 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
112191 +
112192 + cond_bb = gimple_bb(stmt);
112193 + if (before)
112194 + gsi_prev(&gsi);
112195 + if (gsi_end_p(gsi))
112196 + e = split_block_after_labels(cond_bb);
112197 + else
112198 + e = split_block(cond_bb, gsi_stmt(gsi));
112199 + cond_bb = e->src;
112200 + join_bb = e->dest;
112201 + e->flags = EDGE_FALSE_VALUE;
112202 + e->probability = REG_BR_PROB_BASE;
112203 +
112204 + bb_true = create_empty_bb(cond_bb);
112205 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
112206 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
112207 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
112208 +
112209 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
112210 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
112211 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
112212 +
112213 + if (current_loops != NULL) {
112214 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
112215 + add_bb_to_loop(bb_true, cond_bb->loop_father);
112216 + }
112217 +
112218 + insert_cond(cond_bb, arg, cond_code, type_value);
112219 + insert_cond_result(caller_node, bb_true, stmt, arg, min);
112220 +
112221 +// print_the_code_insertions(stmt);
112222 +}
112223 +
112224 +void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
112225 +{
112226 + const_tree rhs_type = TREE_TYPE(rhs);
112227 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
112228 +
112229 + gcc_assert(rhs_type != NULL_TREE);
112230 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
112231 + return;
112232 +
112233 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
112234 +
112235 + if (is_const_plus_unsigned_signed_truncation(rhs))
112236 + return;
112237 +
112238 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
112239 + // typemax (-1) < typemin (0)
112240 + if (TREE_OVERFLOW(type_max))
112241 + return;
112242 +
112243 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
112244 +
112245 + cast_rhs_type = TREE_TYPE(cast_rhs);
112246 + type_max_type = TREE_TYPE(type_max);
112247 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
112248 +
112249 + insert_check_size_overflow(caller_node, stmt, GT_EXPR, cast_rhs, type_max, before, MAX_CHECK);
112250 +
112251 + // special case: get_size_overflow_type(), 32, u64->s
112252 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && TYPE_UNSIGNED(size_overflow_type) && !TYPE_UNSIGNED(rhs_type))
112253 + return;
112254 +
112255 + type_min_type = TREE_TYPE(type_min);
112256 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
112257 + insert_check_size_overflow(caller_node, stmt, LT_EXPR, cast_rhs, type_min, before, MIN_CHECK);
112258 +}
112259 +
112260 +static tree create_cast_overflow_check(struct visited *visited, struct cgraph_node *caller_node, tree new_rhs1, gimple stmt)
112261 +{
112262 + bool cast_lhs, cast_rhs;
112263 + tree lhs = gimple_assign_lhs(stmt);
112264 + tree rhs = gimple_assign_rhs1(stmt);
112265 + const_tree lhs_type = TREE_TYPE(lhs);
112266 + const_tree rhs_type = TREE_TYPE(rhs);
112267 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
112268 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
112269 + unsigned int lhs_size = GET_MODE_BITSIZE(lhs_mode);
112270 + unsigned int rhs_size = GET_MODE_BITSIZE(rhs_mode);
112271 +
112272 + static bool check_lhs[3][4] = {
112273 + // ss su us uu
112274 + { false, true, true, false }, // lhs > rhs
112275 + { false, false, false, false }, // lhs = rhs
112276 + { true, true, true, true }, // lhs < rhs
112277 + };
112278 +
112279 + static bool check_rhs[3][4] = {
112280 + // ss su us uu
112281 + { true, false, true, true }, // lhs > rhs
112282 + { true, false, true, true }, // lhs = rhs
112283 + { true, false, true, true }, // lhs < rhs
112284 + };
112285 +
112286 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast !!!!
112287 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
112288 + return create_assign(visited, stmt, lhs, AFTER_STMT);
112289 +
112290 + if (lhs_size > rhs_size) {
112291 + cast_lhs = check_lhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
112292 + cast_rhs = check_rhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
112293 + } else if (lhs_size == rhs_size) {
112294 + cast_lhs = check_lhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
112295 + cast_rhs = check_rhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
112296 + } else {
112297 + cast_lhs = check_lhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
112298 + cast_rhs = check_rhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
112299 + }
112300 +
112301 + if (!cast_lhs && !cast_rhs)
112302 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
112303 +
112304 + if (cast_lhs && !skip_lhs_cast_check(stmt))
112305 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, lhs, BEFORE_STMT);
112306 +
112307 + if (cast_rhs)
112308 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, rhs, BEFORE_STMT);
112309 +
112310 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
112311 +}
112312 +
112313 +static tree handle_unary_rhs(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
112314 +{
112315 + enum tree_code rhs_code;
112316 + tree rhs1, new_rhs1, lhs = gimple_assign_lhs(stmt);
112317 +
112318 + if (pointer_set_contains(visited->my_stmts, stmt))
112319 + return lhs;
112320 +
112321 + rhs1 = gimple_assign_rhs1(stmt);
112322 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
112323 + return create_assign(visited, stmt, lhs, AFTER_STMT);
112324 +
112325 + new_rhs1 = expand(visited, caller_node, rhs1);
112326 +
112327 + if (new_rhs1 == NULL_TREE)
112328 + return create_cast_assign(visited, stmt);
112329 +
112330 + if (pointer_set_contains(visited->no_cast_check, stmt))
112331 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
112332 +
112333 + rhs_code = gimple_assign_rhs_code(stmt);
112334 + if (rhs_code == BIT_NOT_EXPR || rhs_code == NEGATE_EXPR) {
112335 + tree size_overflow_type = get_size_overflow_type(visited, stmt, rhs1);
112336 +
112337 + new_rhs1 = cast_to_new_size_overflow_type(visited, stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
112338 + check_size_overflow(caller_node, stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
112339 + return create_assign(visited, stmt, lhs, AFTER_STMT);
112340 + }
112341 +
112342 + if (!gimple_assign_cast_p(stmt))
112343 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
112344 +
112345 + return create_cast_overflow_check(visited, caller_node, new_rhs1, stmt);
112346 +}
112347 +
112348 +static tree handle_unary_ops(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
112349 +{
112350 + tree rhs1, lhs = gimple_assign_lhs(stmt);
112351 + gimple def_stmt = get_def_stmt(lhs);
112352 +
112353 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
112354 + rhs1 = gimple_assign_rhs1(def_stmt);
112355 +
112356 + if (is_gimple_constant(rhs1))
112357 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
112358 +
112359 + switch (TREE_CODE(rhs1)) {
112360 + case SSA_NAME: {
112361 + tree ret = handle_unary_rhs(visited, caller_node, def_stmt);
112362 +
112363 + if (gimple_assign_cast_p(stmt))
112364 + unsigned_signed_cast_intentional_overflow(visited, stmt);
112365 + return ret;
112366 + }
112367 + case ARRAY_REF:
112368 + case BIT_FIELD_REF:
112369 + case ADDR_EXPR:
112370 + case COMPONENT_REF:
112371 + case INDIRECT_REF:
112372 +#if BUILDING_GCC_VERSION >= 4006
112373 + case MEM_REF:
112374 +#endif
112375 + case TARGET_MEM_REF:
112376 + case VIEW_CONVERT_EXPR:
112377 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
112378 + case PARM_DECL:
112379 + case VAR_DECL:
112380 + return create_assign(visited, stmt, lhs, AFTER_STMT);
112381 +
112382 + default:
112383 + debug_gimple_stmt(def_stmt);
112384 + debug_tree(rhs1);
112385 + gcc_unreachable();
112386 + }
112387 +}
112388 +
112389 +static void __unused print_the_code_insertions(const_gimple stmt)
112390 +{
112391 + location_t loc = gimple_location(stmt);
112392 +
112393 + inform(loc, "Integer size_overflow check applied here.");
112394 +}
112395 +
112396 +static bool is_from_cast(const_tree node)
112397 +{
112398 + gimple def_stmt = get_def_stmt(node);
112399 +
112400 + if (!def_stmt)
112401 + return false;
112402 +
112403 + if (gimple_assign_cast_p(def_stmt))
112404 + return true;
112405 +
112406 + return false;
112407 +}
112408 +
112409 +// Skip duplication when there is a minus expr and the type of rhs1 or rhs2 is a pointer_type.
112410 +static bool is_a_ptr_minus(gimple stmt)
112411 +{
112412 + const_tree rhs1, rhs2, ptr1_rhs, ptr2_rhs;
112413 +
112414 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
112415 + return false;
112416 +
112417 + rhs1 = gimple_assign_rhs1(stmt);
112418 + if (!is_from_cast(rhs1))
112419 + return false;
112420 +
112421 + rhs2 = gimple_assign_rhs2(stmt);
112422 + if (!is_from_cast(rhs2))
112423 + return false;
112424 +
112425 + ptr1_rhs = gimple_assign_rhs1(get_def_stmt(rhs1));
112426 + ptr2_rhs = gimple_assign_rhs1(get_def_stmt(rhs2));
112427 +
112428 + if (TREE_CODE(TREE_TYPE(ptr1_rhs)) != POINTER_TYPE && TREE_CODE(TREE_TYPE(ptr2_rhs)) != POINTER_TYPE)
112429 + return false;
112430 +
112431 + return true;
112432 +}
112433 +
112434 +static tree handle_binary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
112435 +{
112436 + enum intentional_overflow_type res;
112437 + tree rhs1, rhs2, new_lhs;
112438 + gimple def_stmt = get_def_stmt(lhs);
112439 + tree new_rhs1 = NULL_TREE;
112440 + tree new_rhs2 = NULL_TREE;
112441 +
112442 + if (is_a_ptr_minus(def_stmt))
112443 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
112444 +
112445 + rhs1 = gimple_assign_rhs1(def_stmt);
112446 + rhs2 = gimple_assign_rhs2(def_stmt);
112447 +
112448 + /* no DImode/TImode division in the 32/64 bit kernel */
112449 + switch (gimple_assign_rhs_code(def_stmt)) {
112450 + case RDIV_EXPR:
112451 + case TRUNC_DIV_EXPR:
112452 + case CEIL_DIV_EXPR:
112453 + case FLOOR_DIV_EXPR:
112454 + case ROUND_DIV_EXPR:
112455 + case TRUNC_MOD_EXPR:
112456 + case CEIL_MOD_EXPR:
112457 + case FLOOR_MOD_EXPR:
112458 + case ROUND_MOD_EXPR:
112459 + case EXACT_DIV_EXPR:
112460 + case POINTER_PLUS_EXPR:
112461 + case BIT_AND_EXPR:
112462 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
112463 + default:
112464 + break;
112465 + }
112466 +
112467 + new_lhs = handle_integer_truncation(visited, caller_node, lhs);
112468 + if (new_lhs != NULL_TREE)
112469 + return new_lhs;
112470 +
112471 + if (TREE_CODE(rhs1) == SSA_NAME)
112472 + new_rhs1 = expand(visited, caller_node, rhs1);
112473 + if (TREE_CODE(rhs2) == SSA_NAME)
112474 + new_rhs2 = expand(visited, caller_node, rhs2);
112475 +
112476 + res = add_mul_intentional_overflow(def_stmt);
112477 + if (res != NO_INTENTIONAL_OVERFLOW) {
112478 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
112479 + insert_cast_expr(visited, get_def_stmt(new_lhs), res);
112480 + return new_lhs;
112481 + }
112482 +
112483 + if (skip_expr_on_double_type(def_stmt)) {
112484 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
112485 + insert_cast_expr(visited, get_def_stmt(new_lhs), NO_INTENTIONAL_OVERFLOW);
112486 + return new_lhs;
112487 + }
112488 +
112489 + if (is_a_neg_overflow(def_stmt, rhs2))
112490 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs1, NULL_TREE);
112491 + if (is_a_neg_overflow(def_stmt, rhs1))
112492 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs2, new_rhs2);
112493 +
112494 +
112495 + if (is_a_constant_overflow(def_stmt, rhs2))
112496 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, NULL_TREE);
112497 + if (is_a_constant_overflow(def_stmt, rhs1))
112498 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, new_rhs2);
112499 +
112500 + // the const is between 0 and (signed) MAX
112501 + if (is_gimple_constant(rhs1))
112502 + new_rhs1 = create_assign(visited, def_stmt, rhs1, BEFORE_STMT);
112503 + if (is_gimple_constant(rhs2))
112504 + new_rhs2 = create_assign(visited, def_stmt, rhs2, BEFORE_STMT);
112505 +
112506 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
112507 +}
112508 +
112509 +#if BUILDING_GCC_VERSION >= 4006
112510 +static tree get_new_rhs(struct visited *visited, struct cgraph_node *caller_node, tree size_overflow_type, tree rhs)
112511 +{
112512 + if (is_gimple_constant(rhs))
112513 + return cast_a_tree(size_overflow_type, rhs);
112514 + if (TREE_CODE(rhs) != SSA_NAME)
112515 + return NULL_TREE;
112516 + return expand(visited, caller_node, rhs);
112517 +}
112518 +
112519 +static tree handle_ternary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
112520 +{
112521 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
112522 + gimple def_stmt = get_def_stmt(lhs);
112523 +
112524 + size_overflow_type = get_size_overflow_type(visited, def_stmt, lhs);
112525 +
112526 + rhs1 = gimple_assign_rhs1(def_stmt);
112527 + rhs2 = gimple_assign_rhs2(def_stmt);
112528 + rhs3 = gimple_assign_rhs3(def_stmt);
112529 + new_rhs1 = get_new_rhs(visited, caller_node, size_overflow_type, rhs1);
112530 + new_rhs2 = get_new_rhs(visited, caller_node, size_overflow_type, rhs2);
112531 + new_rhs3 = get_new_rhs(visited, caller_node, size_overflow_type, rhs3);
112532 +
112533 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
112534 +}
112535 +#endif
112536 +
112537 +static tree get_my_stmt_lhs(struct visited *visited, gimple stmt)
112538 +{
112539 + gimple_stmt_iterator gsi;
112540 + gimple next_stmt = NULL;
112541 +
112542 + gsi = gsi_for_stmt(stmt);
112543 +
112544 + do {
112545 + gsi_next(&gsi);
112546 + next_stmt = gsi_stmt(gsi);
112547 +
112548 + if (gimple_code(stmt) == GIMPLE_PHI && !pointer_set_contains(visited->my_stmts, next_stmt))
112549 + return NULL_TREE;
112550 +
112551 + if (pointer_set_contains(visited->my_stmts, next_stmt) && !pointer_set_contains(visited->skip_expr_casts, next_stmt))
112552 + break;
112553 +
112554 + gcc_assert(pointer_set_contains(visited->my_stmts, next_stmt));
112555 + } while (!gsi_end_p(gsi));
112556 +
112557 + gcc_assert(next_stmt);
112558 + return get_lhs(next_stmt);
112559 +}
112560 +
112561 +static tree expand_visited(struct visited *visited, gimple def_stmt)
112562 +{
112563 + gimple_stmt_iterator gsi;
112564 + enum gimple_code code = gimple_code(def_stmt);
112565 +
112566 + if (code == GIMPLE_ASM)
112567 + return NULL_TREE;
112568 +
112569 + gsi = gsi_for_stmt(def_stmt);
112570 + gsi_next(&gsi);
112571 +
112572 + if (gimple_code(def_stmt) == GIMPLE_PHI && gsi_end_p(gsi))
112573 + return NULL_TREE;
112574 + return get_my_stmt_lhs(visited, def_stmt);
112575 +}
112576 +
112577 +tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
112578 +{
112579 + gimple def_stmt;
112580 +
112581 + def_stmt = get_def_stmt(lhs);
112582 +
112583 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
112584 + return NULL_TREE;
112585 +
112586 + if (pointer_set_contains(visited->my_stmts, def_stmt))
112587 + return lhs;
112588 +
112589 + if (pointer_set_contains(visited->stmts, def_stmt))
112590 + return expand_visited(visited, def_stmt);
112591 +
112592 + switch (gimple_code(def_stmt)) {
112593 + case GIMPLE_PHI:
112594 + return handle_phi(visited, caller_node, lhs);
112595 + case GIMPLE_CALL:
112596 + case GIMPLE_ASM:
112597 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
112598 + case GIMPLE_ASSIGN:
112599 + switch (gimple_num_ops(def_stmt)) {
112600 + case 2:
112601 + return handle_unary_ops(visited, caller_node, def_stmt);
112602 + case 3:
112603 + return handle_binary_ops(visited, caller_node, lhs);
112604 +#if BUILDING_GCC_VERSION >= 4006
112605 + case 4:
112606 + return handle_ternary_ops(visited, caller_node, lhs);
112607 +#endif
112608 + }
112609 + default:
112610 + debug_gimple_stmt(def_stmt);
112611 + error("%s: unknown gimple code", __func__);
112612 + gcc_unreachable();
112613 + }
112614 +}
112615 +
112616 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
112617 new file mode 100644
112618 index 0000000..df50164
112619 --- /dev/null
112620 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_ipa.c
112621 @@ -0,0 +1,1141 @@
112622 +/*
112623 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
112624 + * Licensed under the GPL v2, or (at your option) v3
112625 + *
112626 + * Homepage:
112627 + * http://www.grsecurity.net/~ephox/overflow_plugin/
112628 + *
112629 + * Documentation:
112630 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
112631 + *
112632 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
112633 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
112634 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
112635 + *
112636 + * Usage:
112637 + * $ make
112638 + * $ make run
112639 + */
112640 +
112641 +#include "gcc-common.h"
112642 +#include "size_overflow.h"
112643 +
112644 +#define VEC_LEN 128
112645 +#define RET_CHECK NULL_TREE
112646 +#define WRONG_NODE 32
112647 +#define NOT_INTENTIONAL_ASM NULL
112648 +
112649 +unsigned int call_count;
112650 +
112651 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs);
112652 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs);
112653 +
112654 +struct visited_fns {
112655 + struct visited_fns *next;
112656 + const_tree fndecl;
112657 + unsigned int num;
112658 + const_gimple first_stmt;
112659 +};
112660 +
112661 +struct next_cgraph_node {
112662 + struct next_cgraph_node *next;
112663 + struct cgraph_node *current_function;
112664 + tree callee_fndecl;
112665 + unsigned int num;
112666 +};
112667 +
112668 +// Don't want to duplicate entries in next_cgraph_node
112669 +static bool is_in_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, const_tree fndecl, unsigned int num)
112670 +{
112671 + const_tree new_callee_fndecl;
112672 + struct next_cgraph_node *cur_node;
112673 +
112674 + if (fndecl == RET_CHECK)
112675 + new_callee_fndecl = NODE_DECL(node);
112676 + else
112677 + new_callee_fndecl = fndecl;
112678 +
112679 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
112680 + if (!operand_equal_p(NODE_DECL(cur_node->current_function), NODE_DECL(node), 0))
112681 + continue;
112682 + if (!operand_equal_p(cur_node->callee_fndecl, new_callee_fndecl, 0))
112683 + continue;
112684 + if (num == cur_node->num)
112685 + return true;
112686 + }
112687 + return false;
112688 +}
112689 +
112690 +/* Add a next_cgraph_node into the list for handle_function().
112691 + * handle_function() iterates over all the next cgraph nodes and
112692 + * starts the overflow check insertion process.
112693 + */
112694 +static struct next_cgraph_node *create_new_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, tree fndecl, unsigned int num)
112695 +{
112696 + struct next_cgraph_node *new_node;
112697 +
112698 + if (is_in_next_cgraph_node(head, node, fndecl, num))
112699 + return head;
112700 +
112701 + new_node = (struct next_cgraph_node *)xmalloc(sizeof(*new_node));
112702 + new_node->current_function = node;
112703 + new_node->next = NULL;
112704 + new_node->num = num;
112705 + if (fndecl == RET_CHECK)
112706 + new_node->callee_fndecl = NODE_DECL(node);
112707 + else
112708 + new_node->callee_fndecl = fndecl;
112709 +
112710 + if (!head)
112711 + return new_node;
112712 +
112713 + new_node->next = head;
112714 + return new_node;
112715 +}
112716 +
112717 +static struct next_cgraph_node *create_new_next_cgraph_nodes(struct next_cgraph_node *head, struct cgraph_node *node, unsigned int num)
112718 +{
112719 + struct cgraph_edge *e;
112720 +
112721 + if (num == 0)
112722 + return create_new_next_cgraph_node(head, node, RET_CHECK, num);
112723 +
112724 + for (e = node->callers; e; e = e->next_caller) {
112725 + tree fndecl = gimple_call_fndecl(e->call_stmt);
112726 +
112727 + gcc_assert(fndecl != NULL_TREE);
112728 + head = create_new_next_cgraph_node(head, e->caller, fndecl, num);
112729 + }
112730 +
112731 + return head;
112732 +}
112733 +
112734 +struct missing_functions {
112735 + struct missing_functions *next;
112736 + const_tree node;
112737 + tree fndecl;
112738 +};
112739 +
112740 +static struct missing_functions *create_new_missing_function(struct missing_functions *missing_fn_head, tree node)
112741 +{
112742 + struct missing_functions *new_function;
112743 +
112744 + new_function = (struct missing_functions *)xmalloc(sizeof(*new_function));
112745 + new_function->node = node;
112746 + new_function->next = NULL;
112747 +
112748 + if (TREE_CODE(node) == FUNCTION_DECL)
112749 + new_function->fndecl = node;
112750 + else
112751 + new_function->fndecl = current_function_decl;
112752 + gcc_assert(new_function->fndecl);
112753 +
112754 + if (!missing_fn_head)
112755 + return new_function;
112756 +
112757 + new_function->next = missing_fn_head;
112758 + return new_function;
112759 +}
112760 +
112761 +/* If the function is missing from the hash table and it is a static function
112762 + * then create a next_cgraph_node from it for handle_function()
112763 + */
112764 +static struct next_cgraph_node *check_missing_overflow_attribute_and_create_next_node(struct next_cgraph_node *cnodes, struct missing_functions *missing_fn_head)
112765 +{
112766 + unsigned int num;
112767 + const_tree orig_fndecl;
112768 + struct cgraph_node *next_node = NULL;
112769 +
112770 + orig_fndecl = DECL_ORIGIN(missing_fn_head->fndecl);
112771 +
112772 + num = get_function_num(missing_fn_head->node, orig_fndecl);
112773 + if (num == CANNOT_FIND_ARG)
112774 + return cnodes;
112775 +
112776 + if (!is_missing_function(orig_fndecl, num))
112777 + return cnodes;
112778 +
112779 + next_node = cgraph_get_node(missing_fn_head->fndecl);
112780 + if (next_node && next_node->local.local)
112781 + cnodes = create_new_next_cgraph_nodes(cnodes, next_node, num);
112782 + return cnodes;
112783 +}
112784 +
112785 +/* Search for missing size_overflow attributes on the last nodes in ipa and collect them
112786 + * into the next_cgraph_node list. They will be the next interesting returns or callees.
112787 + */
112788 +static struct next_cgraph_node *search_overflow_attribute(struct next_cgraph_node *cnodes, struct interesting_node *cur_node)
112789 +{
112790 + unsigned int i;
112791 + tree node;
112792 + struct missing_functions *cur, *missing_fn_head = NULL;
112793 +
112794 +#if BUILDING_GCC_VERSION <= 4007
112795 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, node) {
112796 +#else
112797 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, node) {
112798 +#endif
112799 + switch (TREE_CODE(node)) {
112800 + case PARM_DECL:
112801 + if (TREE_CODE(TREE_TYPE(node)) != INTEGER_TYPE)
112802 + break;
112803 + case FUNCTION_DECL:
112804 + missing_fn_head = create_new_missing_function(missing_fn_head, node);
112805 + break;
112806 + default:
112807 + break;
112808 + }
112809 + }
112810 +
112811 + while (missing_fn_head) {
112812 + cnodes = check_missing_overflow_attribute_and_create_next_node(cnodes, missing_fn_head);
112813 +
112814 + cur = missing_fn_head->next;
112815 + free(missing_fn_head);
112816 + missing_fn_head = cur;
112817 + }
112818 +
112819 + return cnodes;
112820 +}
112821 +
112822 +static void walk_phi_set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree result)
112823 +{
112824 + gimple phi = get_def_stmt(result);
112825 + unsigned int i, n = gimple_phi_num_args(phi);
112826 +
112827 + pointer_set_insert(visited, phi);
112828 + for (i = 0; i < n; i++) {
112829 + const_tree arg = gimple_phi_arg_def(phi, i);
112830 +
112831 + set_conditions(visited, interesting_conditions, arg);
112832 + }
112833 +}
112834 +
112835 +enum conditions {
112836 + FROM_CONST, NOT_UNARY, CAST, RET, PHI
112837 +};
112838 +
112839 +// Search for constants, cast assignments and binary/ternary assignments
112840 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs)
112841 +{
112842 + gimple def_stmt = get_def_stmt(lhs);
112843 +
112844 + if (is_gimple_constant(lhs)) {
112845 + interesting_conditions[FROM_CONST] = true;
112846 + return;
112847 + }
112848 +
112849 + if (!def_stmt)
112850 + return;
112851 +
112852 + if (pointer_set_contains(visited, def_stmt))
112853 + return;
112854 +
112855 + switch (gimple_code(def_stmt)) {
112856 + case GIMPLE_CALL:
112857 + if (lhs == gimple_call_lhs(def_stmt))
112858 + interesting_conditions[RET] = true;
112859 + return;
112860 + case GIMPLE_NOP:
112861 + case GIMPLE_ASM:
112862 + return;
112863 + case GIMPLE_PHI:
112864 + interesting_conditions[PHI] = true;
112865 + return walk_phi_set_conditions(visited, interesting_conditions, lhs);
112866 + case GIMPLE_ASSIGN:
112867 + if (gimple_num_ops(def_stmt) == 2) {
112868 + const_tree rhs = gimple_assign_rhs1(def_stmt);
112869 +
112870 + if (gimple_assign_cast_p(def_stmt))
112871 + interesting_conditions[CAST] = true;
112872 +
112873 + return set_conditions(visited, interesting_conditions, rhs);
112874 + } else {
112875 + interesting_conditions[NOT_UNARY] = true;
112876 + return;
112877 + }
112878 + default:
112879 + debug_gimple_stmt(def_stmt);
112880 + gcc_unreachable();
112881 + }
112882 +}
112883 +
112884 +// determine whether duplication will be necessary or not.
112885 +static void search_interesting_conditions(struct interesting_node *cur_node, bool *interesting_conditions)
112886 +{
112887 + struct pointer_set_t *visited;
112888 +
112889 + if (gimple_assign_cast_p(cur_node->first_stmt))
112890 + interesting_conditions[CAST] = true;
112891 + else if (is_gimple_assign(cur_node->first_stmt) && gimple_num_ops(cur_node->first_stmt) > 2)
112892 + interesting_conditions[NOT_UNARY] = true;
112893 +
112894 + visited = pointer_set_create();
112895 + set_conditions(visited, interesting_conditions, cur_node->node);
112896 + pointer_set_destroy(visited);
112897 +}
112898 +
112899 +// Remove the size_overflow asm stmt and create an assignment from the input and output of the asm
112900 +static void replace_size_overflow_asm_with_assign(gimple asm_stmt, tree lhs, tree rhs)
112901 +{
112902 + gimple assign;
112903 + gimple_stmt_iterator gsi;
112904 +
112905 + // already removed
112906 + if (gimple_bb(asm_stmt) == NULL)
112907 + return;
112908 + gsi = gsi_for_stmt(asm_stmt);
112909 +
112910 + assign = gimple_build_assign(lhs, rhs);
112911 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
112912 + SSA_NAME_DEF_STMT(lhs) = assign;
112913 +
112914 + gsi_remove(&gsi, true);
112915 +}
112916 +
112917 +/* Get the fndecl of an interesting stmt, the fndecl is the caller function if the interesting
112918 + * stmt is a return otherwise it is the callee function.
112919 + */
112920 +const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum)
112921 +{
112922 + const_tree fndecl;
112923 +
112924 + if (argnum == 0)
112925 + fndecl = current_function_decl;
112926 + else
112927 + fndecl = gimple_call_fndecl(stmt);
112928 +
112929 + if (fndecl == NULL_TREE)
112930 + return NULL_TREE;
112931 +
112932 + return DECL_ORIGIN(fndecl);
112933 +}
112934 +
112935 +// e.g., 3.8.2, 64, arch/x86/ia32/ia32_signal.c copy_siginfo_from_user32(): compat_ptr() u32 max
112936 +static bool skip_asm(const_tree arg)
112937 +{
112938 + gimple def_stmt = get_def_stmt(arg);
112939 +
112940 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
112941 + return false;
112942 +
112943 + def_stmt = get_def_stmt(gimple_assign_rhs1(def_stmt));
112944 + return def_stmt && gimple_code(def_stmt) == GIMPLE_ASM;
112945 +}
112946 +
112947 +static void walk_use_def_phi(struct pointer_set_t *visited, struct interesting_node *cur_node, tree result)
112948 +{
112949 + gimple phi = get_def_stmt(result);
112950 + unsigned int i, n = gimple_phi_num_args(phi);
112951 +
112952 + pointer_set_insert(visited, phi);
112953 + for (i = 0; i < n; i++) {
112954 + tree arg = gimple_phi_arg_def(phi, i);
112955 +
112956 + walk_use_def(visited, cur_node, arg);
112957 + }
112958 +}
112959 +
112960 +static void walk_use_def_binary(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
112961 +{
112962 + gimple def_stmt = get_def_stmt(lhs);
112963 + tree rhs1, rhs2;
112964 +
112965 + rhs1 = gimple_assign_rhs1(def_stmt);
112966 + rhs2 = gimple_assign_rhs2(def_stmt);
112967 +
112968 + walk_use_def(visited, cur_node, rhs1);
112969 + walk_use_def(visited, cur_node, rhs2);
112970 +}
112971 +
112972 +static void insert_last_node(struct interesting_node *cur_node, tree node)
112973 +{
112974 + unsigned int i;
112975 + tree element;
112976 + enum tree_code code;
112977 +
112978 + gcc_assert(node != NULL_TREE);
112979 +
112980 + if (is_gimple_constant(node))
112981 + return;
112982 +
112983 + code = TREE_CODE(node);
112984 + if (code == VAR_DECL) {
112985 + node = DECL_ORIGIN(node);
112986 + code = TREE_CODE(node);
112987 + }
112988 +
112989 + if (code != PARM_DECL && code != FUNCTION_DECL && code != COMPONENT_REF)
112990 + return;
112991 +
112992 +#if BUILDING_GCC_VERSION <= 4007
112993 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, element) {
112994 +#else
112995 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, element) {
112996 +#endif
112997 + if (operand_equal_p(node, element, 0))
112998 + return;
112999 + }
113000 +
113001 +#if BUILDING_GCC_VERSION <= 4007
113002 + gcc_assert(VEC_length(tree, cur_node->last_nodes) < VEC_LEN);
113003 + VEC_safe_push(tree, gc, cur_node->last_nodes, node);
113004 +#else
113005 + gcc_assert(cur_node->last_nodes->length() < VEC_LEN);
113006 + vec_safe_push(cur_node->last_nodes, node);
113007 +#endif
113008 +}
113009 +
113010 +// a size_overflow asm stmt in the control flow doesn't stop the recursion
113011 +static void handle_asm_stmt(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs, const_gimple stmt)
113012 +{
113013 + if (!is_size_overflow_asm(stmt))
113014 + walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
113015 +}
113016 +
113017 +/* collect the parm_decls and fndecls (for checking a missing size_overflow attribute (ret or arg) or intentional_overflow)
113018 + * and component refs (for checking the intentional_overflow attribute).
113019 + */
113020 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
113021 +{
113022 + const_gimple def_stmt;
113023 +
113024 + if (TREE_CODE(lhs) != SSA_NAME) {
113025 + insert_last_node(cur_node, lhs);
113026 + return;
113027 + }
113028 +
113029 + def_stmt = get_def_stmt(lhs);
113030 + if (!def_stmt)
113031 + return;
113032 +
113033 + if (pointer_set_insert(visited, def_stmt))
113034 + return;
113035 +
113036 + switch (gimple_code(def_stmt)) {
113037 + case GIMPLE_NOP:
113038 + return walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
113039 + case GIMPLE_ASM:
113040 + return handle_asm_stmt(visited, cur_node, lhs, def_stmt);
113041 + case GIMPLE_CALL: {
113042 + tree fndecl = gimple_call_fndecl(def_stmt);
113043 +
113044 + if (fndecl == NULL_TREE)
113045 + return;
113046 + insert_last_node(cur_node, fndecl);
113047 + return;
113048 + }
113049 + case GIMPLE_PHI:
113050 + return walk_use_def_phi(visited, cur_node, lhs);
113051 + case GIMPLE_ASSIGN:
113052 + switch (gimple_num_ops(def_stmt)) {
113053 + case 2:
113054 + return walk_use_def(visited, cur_node, gimple_assign_rhs1(def_stmt));
113055 + case 3:
113056 + return walk_use_def_binary(visited, cur_node, lhs);
113057 + }
113058 + default:
113059 + debug_gimple_stmt((gimple)def_stmt);
113060 + error("%s: unknown gimple code", __func__);
113061 + gcc_unreachable();
113062 + }
113063 +}
113064 +
113065 +// Collect all the last nodes for checking the intentional_overflow and size_overflow attributes
113066 +static void set_last_nodes(struct interesting_node *cur_node)
113067 +{
113068 + struct pointer_set_t *visited;
113069 +
113070 + visited = pointer_set_create();
113071 + walk_use_def(visited, cur_node, cur_node->node);
113072 + pointer_set_destroy(visited);
113073 +}
113074 +
113075 +enum precond {
113076 + NO_ATTRIBUTE_SEARCH, NO_CHECK_INSERT, NONE
113077 +};
113078 +
113079 +/* 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.
113080 + * There is only missing size_overflow attribute checking if the intentional_overflow attribute is the mark_no type.
113081 + * Stmt duplication is unnecessary if there are no binary/ternary assignements or if the unary assignment isn't a cast.
113082 + * It skips the possible error codes too.
113083 + */
113084 +static enum precond check_preconditions(struct interesting_node *cur_node)
113085 +{
113086 + bool interesting_conditions[5] = {false, false, false, false, false};
113087 +
113088 + set_last_nodes(cur_node);
113089 +
113090 + check_intentional_attribute_ipa(cur_node);
113091 + if (cur_node->intentional_attr_decl == MARK_TURN_OFF || cur_node->intentional_attr_cur_fndecl == MARK_TURN_OFF)
113092 + return NO_ATTRIBUTE_SEARCH;
113093 +
113094 + search_interesting_conditions(cur_node, interesting_conditions);
113095 +
113096 + // error code: a phi, unary assign (not cast) and returns only
113097 + if (!interesting_conditions[NOT_UNARY] && interesting_conditions[PHI] && interesting_conditions[RET] && !interesting_conditions[CAST])
113098 + return NO_ATTRIBUTE_SEARCH;
113099 +
113100 + // error code: def_stmts trace back to a constant and there are no binary/ternary assigments
113101 + if (interesting_conditions[CAST] && interesting_conditions[FROM_CONST] && !interesting_conditions[NOT_UNARY])
113102 + return NO_ATTRIBUTE_SEARCH;
113103 +
113104 + // unnecessary overflow check
113105 + if (!interesting_conditions[CAST] && !interesting_conditions[NOT_UNARY])
113106 + return NO_CHECK_INSERT;
113107 +
113108 + if (cur_node->intentional_attr_cur_fndecl != MARK_NO)
113109 + return NO_CHECK_INSERT;
113110 +
113111 + return NONE;
113112 +}
113113 +
113114 +static tree cast_to_orig_type(struct visited *visited, gimple stmt, const_tree orig_node, tree new_node)
113115 +{
113116 + const_gimple assign;
113117 + tree orig_type = TREE_TYPE(orig_node);
113118 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
113119 +
113120 + assign = build_cast_stmt(visited, orig_type, new_node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
113121 + return gimple_assign_lhs(assign);
113122 +}
113123 +
113124 +static void change_orig_node(struct visited *visited, struct interesting_node *cur_node, tree new_node)
113125 +{
113126 + void (*set_rhs)(gimple, tree);
113127 + gimple stmt = cur_node->first_stmt;
113128 + const_tree orig_node = cur_node->node;
113129 +
113130 + switch (gimple_code(stmt)) {
113131 + case GIMPLE_RETURN:
113132 + gimple_return_set_retval(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
113133 + break;
113134 + case GIMPLE_CALL:
113135 + gimple_call_set_arg(stmt, cur_node->num - 1, cast_to_orig_type(visited, stmt, orig_node, new_node));
113136 + break;
113137 + case GIMPLE_ASSIGN:
113138 + switch (cur_node->num) {
113139 + case 1:
113140 + set_rhs = &gimple_assign_set_rhs1;
113141 + break;
113142 + case 2:
113143 + set_rhs = &gimple_assign_set_rhs2;
113144 + break;
113145 +#if BUILDING_GCC_VERSION >= 4006
113146 + case 3:
113147 + set_rhs = &gimple_assign_set_rhs3;
113148 + break;
113149 +#endif
113150 + default:
113151 + gcc_unreachable();
113152 + }
113153 +
113154 + set_rhs(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
113155 + break;
113156 + default:
113157 + debug_gimple_stmt(stmt);
113158 + gcc_unreachable();
113159 + }
113160 +
113161 + update_stmt(stmt);
113162 +}
113163 +
113164 +static struct visited *create_visited(void)
113165 +{
113166 + struct visited *new_node;
113167 +
113168 + new_node = (struct visited *)xmalloc(sizeof(*new_node));
113169 + new_node->stmts = pointer_set_create();
113170 + new_node->my_stmts = pointer_set_create();
113171 + new_node->skip_expr_casts = pointer_set_create();
113172 + new_node->no_cast_check = pointer_set_create();
113173 + return new_node;
113174 +}
113175 +
113176 +static void free_visited(struct visited *visited)
113177 +{
113178 + pointer_set_destroy(visited->stmts);
113179 + pointer_set_destroy(visited->my_stmts);
113180 + pointer_set_destroy(visited->skip_expr_casts);
113181 + pointer_set_destroy(visited->no_cast_check);
113182 +
113183 + free(visited);
113184 +}
113185 +
113186 +/* This function calls the main recursion function (expand) that duplicates the stmts. Before that it checks the intentional_overflow attribute and asm stmts,
113187 + * 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
113188 + * in the original stmt (first stmt) and it inserts the overflow check for the arg of the callee or for the return value.
113189 + */
113190 +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)
113191 +{
113192 + enum precond ret;
113193 + tree new_node, orig_node = cur_node->node;
113194 +
113195 + ret = check_preconditions(cur_node);
113196 + if (ret == NO_ATTRIBUTE_SEARCH)
113197 + return cnodes;
113198 +
113199 + cnodes = search_overflow_attribute(cnodes, cur_node);
113200 +
113201 + if (ret == NO_CHECK_INSERT)
113202 + return cnodes;
113203 +
113204 + new_node = expand(visited, caller_node, orig_node);
113205 + if (new_node == NULL_TREE)
113206 + return cnodes;
113207 +
113208 + change_orig_node(visited, cur_node, new_node);
113209 + check_size_overflow(caller_node, cur_node->first_stmt, TREE_TYPE(new_node), new_node, orig_node, BEFORE_STMT);
113210 +
113211 + return cnodes;
113212 +}
113213 +
113214 +// Check visited_fns interesting nodes.
113215 +static bool is_in_interesting_node(struct interesting_node *head, const_gimple first_stmt, const_tree node, unsigned int num)
113216 +{
113217 + struct interesting_node *cur;
113218 +
113219 + for (cur = head; cur; cur = cur->next) {
113220 + if (!operand_equal_p(node, cur->node, 0))
113221 + continue;
113222 + if (num != cur->num)
113223 + continue;
113224 + if (first_stmt == cur->first_stmt)
113225 + return true;
113226 + }
113227 + return false;
113228 +}
113229 +
113230 +/* Create an interesting node. The ipa pass starts to duplicate from these stmts.
113231 + 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
113232 + 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
113233 + the intentional_overflow attribute check. They are collected by set_last_nodes().
113234 + num: arg count of a call stmt or 0 when it is a ret
113235 + node: the recursion starts from here, it is a call arg or a return value
113236 + 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.
113237 + intentional_attr_decl: intentional_overflow attribute of the callee function
113238 + intentional_attr_cur_fndecl: intentional_overflow attribute of the caller function
113239 + intentional_mark_from_gimple: the intentional overflow type of size_overflow asm stmt from gimple if it exists
113240 + */
113241 +static struct interesting_node *create_new_interesting_node(struct interesting_node *head, gimple first_stmt, tree node, unsigned int num, gimple asm_stmt)
113242 +{
113243 + struct interesting_node *new_node;
113244 + tree fndecl;
113245 + enum gimple_code code;
113246 +
113247 + gcc_assert(node != NULL_TREE);
113248 + code = gimple_code(first_stmt);
113249 + gcc_assert(code == GIMPLE_CALL || code == GIMPLE_ASM || code == GIMPLE_ASSIGN || code == GIMPLE_RETURN);
113250 +
113251 + if (num == CANNOT_FIND_ARG)
113252 + return head;
113253 +
113254 + if (skip_types(node))
113255 + return head;
113256 +
113257 + if (skip_asm(node))
113258 + return head;
113259 +
113260 + if (is_gimple_call(first_stmt))
113261 + fndecl = gimple_call_fndecl(first_stmt);
113262 + else
113263 + fndecl = current_function_decl;
113264 +
113265 + if (fndecl == NULL_TREE)
113266 + return head;
113267 +
113268 + if (is_in_interesting_node(head, first_stmt, node, num))
113269 + return head;
113270 +
113271 + new_node = (struct interesting_node *)xmalloc(sizeof(*new_node));
113272 +
113273 + new_node->next = NULL;
113274 + new_node->first_stmt = first_stmt;
113275 +#if BUILDING_GCC_VERSION <= 4007
113276 + new_node->last_nodes = VEC_alloc(tree, gc, VEC_LEN);
113277 +#else
113278 + vec_alloc(new_node->last_nodes, VEC_LEN);
113279 +#endif
113280 + new_node->num = num;
113281 + new_node->node = node;
113282 + new_node->fndecl = fndecl;
113283 + new_node->intentional_attr_decl = MARK_NO;
113284 + new_node->intentional_attr_cur_fndecl = MARK_NO;
113285 + new_node->intentional_mark_from_gimple = asm_stmt;
113286 +
113287 + if (!head)
113288 + return new_node;
113289 +
113290 + new_node->next = head;
113291 + return new_node;
113292 +}
113293 +
113294 +/* 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).
113295 + * If the ret stmt is in the next cgraph node list then it's an interesting ret.
113296 + */
113297 +static struct interesting_node *handle_stmt_by_cgraph_nodes_ret(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
113298 +{
113299 + struct next_cgraph_node *cur_node;
113300 + tree ret = gimple_return_retval(stmt);
113301 +
113302 + if (ret == NULL_TREE)
113303 + return head;
113304 +
113305 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
113306 + if (!operand_equal_p(cur_node->callee_fndecl, DECL_ORIGIN(current_function_decl), 0))
113307 + continue;
113308 + if (cur_node->num == 0)
113309 + head = create_new_interesting_node(head, stmt, ret, 0, NOT_INTENTIONAL_ASM);
113310 + }
113311 +
113312 + return head;
113313 +}
113314 +
113315 +/* 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).
113316 + * If the call stmt is in the next cgraph node list then it's an interesting call.
113317 + */
113318 +static struct interesting_node *handle_stmt_by_cgraph_nodes_call(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
113319 +{
113320 + unsigned int argnum;
113321 + tree arg;
113322 + const_tree fndecl;
113323 + struct next_cgraph_node *cur_node;
113324 +
113325 + fndecl = gimple_call_fndecl(stmt);
113326 + if (fndecl == NULL_TREE)
113327 + return head;
113328 +
113329 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
113330 + if (!operand_equal_p(cur_node->callee_fndecl, fndecl, 0))
113331 + continue;
113332 + argnum = get_correct_arg_count(cur_node->num, fndecl);
113333 + gcc_assert(argnum != CANNOT_FIND_ARG);
113334 + if (argnum == 0)
113335 + continue;
113336 +
113337 + arg = gimple_call_arg(stmt, argnum - 1);
113338 + head = create_new_interesting_node(head, stmt, arg, argnum, NOT_INTENTIONAL_ASM);
113339 + }
113340 +
113341 + return head;
113342 +}
113343 +
113344 +static unsigned int check_ops(const_tree orig_node, const_tree node, unsigned int ret_count)
113345 +{
113346 + if (!operand_equal_p(orig_node, node, 0))
113347 + return WRONG_NODE;
113348 + if (skip_types(node))
113349 + return WRONG_NODE;
113350 + return ret_count;
113351 +}
113352 +
113353 +// Get the index of the rhs node in an assignment
113354 +static unsigned int get_assign_ops_count(const_gimple stmt, tree node)
113355 +{
113356 + const_tree rhs1, rhs2;
113357 + unsigned int ret;
113358 +
113359 + gcc_assert(stmt);
113360 + gcc_assert(is_gimple_assign(stmt));
113361 +
113362 + rhs1 = gimple_assign_rhs1(stmt);
113363 + gcc_assert(rhs1 != NULL_TREE);
113364 +
113365 + switch (gimple_num_ops(stmt)) {
113366 + case 2:
113367 + return check_ops(node, rhs1, 1);
113368 + case 3:
113369 + ret = check_ops(node, rhs1, 1);
113370 + if (ret != WRONG_NODE)
113371 + return ret;
113372 +
113373 + rhs2 = gimple_assign_rhs2(stmt);
113374 + gcc_assert(rhs2 != NULL_TREE);
113375 + return check_ops(node, rhs2, 2);
113376 + default:
113377 + gcc_unreachable();
113378 + }
113379 +}
113380 +
113381 +// Find the correct arg number of a call stmt. It is needed when the interesting function is a cloned function.
113382 +static unsigned int find_arg_number_gimple(const_tree arg, const_gimple stmt)
113383 +{
113384 + unsigned int i;
113385 +
113386 + if (gimple_call_fndecl(stmt) == NULL_TREE)
113387 + return CANNOT_FIND_ARG;
113388 +
113389 + for (i = 0; i < gimple_call_num_args(stmt); i++) {
113390 + tree node;
113391 +
113392 + node = gimple_call_arg(stmt, i);
113393 + if (!operand_equal_p(arg, node, 0))
113394 + continue;
113395 + if (!skip_types(node))
113396 + return i + 1;
113397 + }
113398 +
113399 + return CANNOT_FIND_ARG;
113400 +}
113401 +
113402 +/* starting from the size_overflow asm stmt collect interesting stmts. They can be
113403 + * any of return, call or assignment stmts (because of inlining).
113404 + */
113405 +static struct interesting_node *get_interesting_ret_or_call(struct pointer_set_t *visited, struct interesting_node *head, tree node, gimple intentional_asm)
113406 +{
113407 + use_operand_p use_p;
113408 + imm_use_iterator imm_iter;
113409 + unsigned int argnum;
113410 +
113411 + gcc_assert(TREE_CODE(node) == SSA_NAME);
113412 +
113413 + if (pointer_set_insert(visited, node))
113414 + return head;
113415 +
113416 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
113417 + gimple stmt = USE_STMT(use_p);
113418 +
113419 + if (stmt == NULL)
113420 + return head;
113421 + if (is_gimple_debug(stmt))
113422 + continue;
113423 +
113424 + switch (gimple_code(stmt)) {
113425 + case GIMPLE_CALL:
113426 + argnum = find_arg_number_gimple(node, stmt);
113427 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
113428 + break;
113429 + case GIMPLE_RETURN:
113430 + head = create_new_interesting_node(head, stmt, node, 0, intentional_asm);
113431 + break;
113432 + case GIMPLE_ASSIGN:
113433 + argnum = get_assign_ops_count(stmt, node);
113434 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
113435 + break;
113436 + case GIMPLE_PHI: {
113437 + tree result = gimple_phi_result(stmt);
113438 + head = get_interesting_ret_or_call(visited, head, result, intentional_asm);
113439 + break;
113440 + }
113441 + case GIMPLE_ASM:
113442 + if (gimple_asm_noutputs(stmt) != 0)
113443 + break;
113444 + if (!is_size_overflow_asm(stmt))
113445 + break;
113446 + head = create_new_interesting_node(head, stmt, node, 1, intentional_asm);
113447 + break;
113448 + case GIMPLE_COND:
113449 + case GIMPLE_SWITCH:
113450 + break;
113451 + default:
113452 + debug_gimple_stmt(stmt);
113453 + gcc_unreachable();
113454 + break;
113455 + }
113456 + }
113457 + return head;
113458 +}
113459 +
113460 +static void remove_size_overflow_asm(gimple stmt)
113461 +{
113462 + gimple_stmt_iterator gsi;
113463 + tree input, output;
113464 +
113465 + if (!is_size_overflow_asm(stmt))
113466 + return;
113467 +
113468 + if (gimple_asm_noutputs(stmt) == 0) {
113469 + gsi = gsi_for_stmt(stmt);
113470 + ipa_remove_stmt_references(cgraph_get_create_node(current_function_decl), stmt);
113471 + gsi_remove(&gsi, true);
113472 + return;
113473 + }
113474 +
113475 + input = gimple_asm_input_op(stmt, 0);
113476 + output = gimple_asm_output_op(stmt, 0);
113477 + replace_size_overflow_asm_with_assign(stmt, TREE_VALUE(output), TREE_VALUE(input));
113478 +}
113479 +
113480 +/* handle the size_overflow asm stmts from the gimple pass and collect the interesting stmts.
113481 + * If the asm stmt is a parm_decl kind (noutputs == 0) then remove it.
113482 + * If it is a simple asm stmt then replace it with an assignment from the asm input to the asm output.
113483 + */
113484 +static struct interesting_node *handle_stmt_by_size_overflow_asm(gimple stmt, struct interesting_node *head)
113485 +{
113486 + const_tree output;
113487 + struct pointer_set_t *visited;
113488 + gimple intentional_asm = NOT_INTENTIONAL_ASM;
113489 +
113490 + if (!is_size_overflow_asm(stmt))
113491 + return head;
113492 +
113493 + if (is_size_overflow_intentional_asm_yes(stmt) || is_size_overflow_intentional_asm_turn_off(stmt))
113494 + intentional_asm = stmt;
113495 +
113496 + gcc_assert(gimple_asm_ninputs(stmt) == 1);
113497 +
113498 + if (gimple_asm_noutputs(stmt) == 0 && is_size_overflow_intentional_asm_turn_off(stmt))
113499 + return head;
113500 +
113501 + if (gimple_asm_noutputs(stmt) == 0) {
113502 + const_tree input;
113503 +
113504 + if (!is_size_overflow_intentional_asm_turn_off(stmt))
113505 + return head;
113506 +
113507 + input = gimple_asm_input_op(stmt, 0);
113508 + remove_size_overflow_asm(stmt);
113509 + if (is_gimple_constant(TREE_VALUE(input)))
113510 + return head;
113511 + visited = pointer_set_create();
113512 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(input), intentional_asm);
113513 + pointer_set_destroy(visited);
113514 + return head;
113515 + }
113516 +
113517 + if (!is_size_overflow_intentional_asm_yes(stmt) && !is_size_overflow_intentional_asm_turn_off(stmt))
113518 + remove_size_overflow_asm(stmt);
113519 +
113520 + visited = pointer_set_create();
113521 + output = gimple_asm_output_op(stmt, 0);
113522 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(output), intentional_asm);
113523 + pointer_set_destroy(visited);
113524 + return head;
113525 +}
113526 +
113527 +/* Iterate over all the stmts of a function and look for the size_overflow asm stmts (they were created in the gimple pass)
113528 + * or a call stmt or a return stmt and store them in the interesting_node list
113529 + */
113530 +static struct interesting_node *collect_interesting_stmts(struct next_cgraph_node *next_node)
113531 +{
113532 + basic_block bb;
113533 + struct interesting_node *head = NULL;
113534 +
113535 + FOR_ALL_BB_FN(bb, cfun) {
113536 + gimple_stmt_iterator gsi;
113537 +
113538 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
113539 + enum gimple_code code;
113540 + gimple stmt = gsi_stmt(gsi);
113541 +
113542 + code = gimple_code(stmt);
113543 +
113544 + if (code == GIMPLE_ASM)
113545 + head = handle_stmt_by_size_overflow_asm(stmt, head);
113546 +
113547 + if (!next_node)
113548 + continue;
113549 + if (code == GIMPLE_CALL)
113550 + head = handle_stmt_by_cgraph_nodes_call(head, stmt, next_node);
113551 + if (code == GIMPLE_RETURN)
113552 + head = handle_stmt_by_cgraph_nodes_ret(head, stmt, next_node);
113553 + }
113554 + }
113555 + return head;
113556 +}
113557 +
113558 +static void free_interesting_node(struct interesting_node *head)
113559 +{
113560 + struct interesting_node *cur;
113561 +
113562 + while (head) {
113563 + cur = head->next;
113564 +#if BUILDING_GCC_VERSION <= 4007
113565 + VEC_free(tree, gc, head->last_nodes);
113566 +#else
113567 + vec_free(head->last_nodes);
113568 +#endif
113569 + free(head);
113570 + head = cur;
113571 + }
113572 +}
113573 +
113574 +static struct visited_fns *insert_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
113575 +{
113576 + struct visited_fns *new_visited_fns;
113577 +
113578 + new_visited_fns = (struct visited_fns *)xmalloc(sizeof(*new_visited_fns));
113579 + new_visited_fns->fndecl = cur_node->fndecl;
113580 + new_visited_fns->num = cur_node->num;
113581 + new_visited_fns->first_stmt = cur_node->first_stmt;
113582 + new_visited_fns->next = NULL;
113583 +
113584 + if (!head)
113585 + return new_visited_fns;
113586 +
113587 + new_visited_fns->next = head;
113588 + return new_visited_fns;
113589 +}
113590 +
113591 +/* 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
113592 + * it is a visited_fns function.
113593 + */
113594 +static bool is_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
113595 +{
113596 + struct visited_fns *cur;
113597 +
113598 + if (!head)
113599 + return false;
113600 +
113601 + for (cur = head; cur; cur = cur->next) {
113602 + if (cur_node->first_stmt != cur->first_stmt)
113603 + continue;
113604 + if (!operand_equal_p(cur_node->fndecl, cur->fndecl, 0))
113605 + continue;
113606 + if (cur_node->num == cur->num)
113607 + return true;
113608 + }
113609 + return false;
113610 +}
113611 +
113612 +static void free_next_cgraph_node(struct next_cgraph_node *head)
113613 +{
113614 + struct next_cgraph_node *cur;
113615 +
113616 + while (head) {
113617 + cur = head->next;
113618 + free(head);
113619 + head = cur;
113620 + }
113621 +}
113622 +
113623 +static void remove_all_size_overflow_asm(void)
113624 +{
113625 + basic_block bb;
113626 +
113627 + FOR_ALL_BB_FN(bb, cfun) {
113628 + gimple_stmt_iterator si;
113629 +
113630 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
113631 + remove_size_overflow_asm(gsi_stmt(si));
113632 + }
113633 +}
113634 +
113635 +/* Main recursive walk of the ipa pass: iterate over the collected interesting stmts in a function
113636 + * (they are interesting if they have an associated size_overflow asm stmt) and recursively walk
113637 + * the newly collected interesting functions (they are interesting if there is control flow between
113638 + * the interesting stmts and them).
113639 + */
113640 +static struct visited_fns *handle_function(struct cgraph_node *node, struct next_cgraph_node *next_node, struct visited_fns *visited_fns)
113641 +{
113642 + struct visited *visited;
113643 + struct interesting_node *head, *cur_node;
113644 + struct next_cgraph_node *cur_cnodes, *cnodes_head = NULL;
113645 +
113646 + set_current_function_decl(NODE_DECL(node));
113647 + call_count = 0;
113648 +
113649 + head = collect_interesting_stmts(next_node);
113650 +
113651 + visited = create_visited();
113652 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
113653 + if (is_visited_fns_function(visited_fns, cur_node))
113654 + continue;
113655 + cnodes_head = handle_interesting_stmt(visited, cnodes_head, cur_node, node);
113656 + visited_fns = insert_visited_fns_function(visited_fns, cur_node);
113657 + }
113658 +
113659 + free_visited(visited);
113660 + free_interesting_node(head);
113661 + remove_all_size_overflow_asm();
113662 + unset_current_function_decl();
113663 +
113664 + for (cur_cnodes = cnodes_head; cur_cnodes; cur_cnodes = cur_cnodes->next)
113665 + visited_fns = handle_function(cur_cnodes->current_function, cur_cnodes, visited_fns);
113666 +
113667 + free_next_cgraph_node(cnodes_head);
113668 + return visited_fns;
113669 +}
113670 +
113671 +static void free_visited_fns(struct visited_fns *head)
113672 +{
113673 + struct visited_fns *cur;
113674 +
113675 + while (head) {
113676 + cur = head->next;
113677 + free(head);
113678 + head = cur;
113679 + }
113680 +}
113681 +
113682 +// Main entry point of the ipa pass: erases the plf flag of all stmts and iterates over all the functions
113683 +unsigned int search_function(void)
113684 +{
113685 + struct cgraph_node *node;
113686 + struct visited_fns *visited_fns = NULL;
113687 +
113688 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
113689 + gcc_assert(cgraph_function_flags_ready);
113690 +#if BUILDING_GCC_VERSION <= 4007
113691 + gcc_assert(node->reachable);
113692 +#endif
113693 +
113694 + visited_fns = handle_function(node, NULL, visited_fns);
113695 + }
113696 +
113697 + free_visited_fns(visited_fns);
113698 + return 0;
113699 +}
113700 +
113701 +#if BUILDING_GCC_VERSION >= 4009
113702 +static const struct pass_data insert_size_overflow_check_data = {
113703 +#else
113704 +static struct ipa_opt_pass_d insert_size_overflow_check = {
113705 + .pass = {
113706 +#endif
113707 + .type = SIMPLE_IPA_PASS,
113708 + .name = "size_overflow",
113709 +#if BUILDING_GCC_VERSION >= 4008
113710 + .optinfo_flags = OPTGROUP_NONE,
113711 +#endif
113712 +#if BUILDING_GCC_VERSION >= 4009
113713 + .has_gate = false,
113714 + .has_execute = true,
113715 +#else
113716 + .gate = NULL,
113717 + .execute = search_function,
113718 + .sub = NULL,
113719 + .next = NULL,
113720 + .static_pass_number = 0,
113721 +#endif
113722 + .tv_id = TV_NONE,
113723 + .properties_required = 0,
113724 + .properties_provided = 0,
113725 + .properties_destroyed = 0,
113726 + .todo_flags_start = 0,
113727 + .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,
113728 +#if BUILDING_GCC_VERSION < 4009
113729 + },
113730 + .generate_summary = NULL,
113731 + .write_summary = NULL,
113732 + .read_summary = NULL,
113733 +#if BUILDING_GCC_VERSION >= 4006
113734 + .write_optimization_summary = NULL,
113735 + .read_optimization_summary = NULL,
113736 +#endif
113737 + .stmt_fixup = NULL,
113738 + .function_transform_todo_flags_start = 0,
113739 + .function_transform = NULL,
113740 + .variable_transform = NULL,
113741 +#endif
113742 +};
113743 +
113744 +#if BUILDING_GCC_VERSION >= 4009
113745 +namespace {
113746 +class insert_size_overflow_check : public ipa_opt_pass_d {
113747 +public:
113748 + insert_size_overflow_check() : ipa_opt_pass_d(insert_size_overflow_check_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
113749 + unsigned int execute() { return search_function(); }
113750 +};
113751 +}
113752 +#endif
113753 +
113754 +struct opt_pass *make_insert_size_overflow_check(void)
113755 +{
113756 +#if BUILDING_GCC_VERSION >= 4009
113757 + return new insert_size_overflow_check();
113758 +#else
113759 + return &insert_size_overflow_check.pass;
113760 +#endif
113761 +}
113762 +
113763 diff --git a/tools/gcc/size_overflow_plugin/intentional_overflow.c b/tools/gcc/size_overflow_plugin/intentional_overflow.c
113764 new file mode 100644
113765 index 0000000..d71d72a
113766 --- /dev/null
113767 +++ b/tools/gcc/size_overflow_plugin/intentional_overflow.c
113768 @@ -0,0 +1,736 @@
113769 +/*
113770 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
113771 + * Licensed under the GPL v2, or (at your option) v3
113772 + *
113773 + * Homepage:
113774 + * http://www.grsecurity.net/~ephox/overflow_plugin/
113775 + *
113776 + * Documentation:
113777 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
113778 + *
113779 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
113780 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
113781 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
113782 + *
113783 + * Usage:
113784 + * $ make
113785 + * $ make run
113786 + */
113787 +
113788 +#include "gcc-common.h"
113789 +#include "size_overflow.h"
113790 +
113791 +/* Get the param of the intentional_overflow attribute.
113792 + * * 0: MARK_NOT_INTENTIONAL
113793 + * * 1..MAX_PARAM: MARK_YES
113794 + * * -1: MARK_TURN_OFF
113795 + */
113796 +static tree get_attribute_param(const_tree decl)
113797 +{
113798 + const_tree attr;
113799 +
113800 + if (decl == NULL_TREE)
113801 + return NULL_TREE;
113802 +
113803 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(decl));
113804 + if (!attr || !TREE_VALUE(attr))
113805 + return NULL_TREE;
113806 +
113807 + return TREE_VALUE(attr);
113808 +}
113809 +
113810 +// MARK_TURN_OFF
113811 +bool is_turn_off_intentional_attr(const_tree decl)
113812 +{
113813 + const_tree param_head;
113814 +
113815 + param_head = get_attribute_param(decl);
113816 + if (param_head == NULL_TREE)
113817 + return false;
113818 +
113819 + if (TREE_INT_CST_HIGH(TREE_VALUE(param_head)) == -1)
113820 + return true;
113821 + return false;
113822 +}
113823 +
113824 +// MARK_NOT_INTENTIONAL
113825 +bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum)
113826 +{
113827 + const_tree param_head;
113828 +
113829 + if (argnum == 0)
113830 + return false;
113831 +
113832 + param_head = get_attribute_param(decl);
113833 + if (param_head == NULL_TREE)
113834 + return false;
113835 +
113836 + if (!TREE_INT_CST_LOW(TREE_VALUE(param_head)))
113837 + return true;
113838 + return false;
113839 +}
113840 +
113841 +// MARK_YES
113842 +bool is_yes_intentional_attr(const_tree decl, unsigned int argnum)
113843 +{
113844 + tree param, param_head;
113845 +
113846 + if (argnum == 0)
113847 + return false;
113848 +
113849 + param_head = get_attribute_param(decl);
113850 + for (param = param_head; param; param = TREE_CHAIN(param))
113851 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(param)))
113852 + return true;
113853 + return false;
113854 +}
113855 +
113856 +void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum)
113857 +{
113858 + location_t loc;
113859 +
113860 + if (caller_attr == MARK_NO || caller_attr == MARK_NOT_INTENTIONAL || caller_attr == MARK_TURN_OFF)
113861 + return;
113862 +
113863 + if (callee_attr == MARK_NOT_INTENTIONAL || callee_attr == MARK_YES)
113864 + return;
113865 +
113866 + loc = DECL_SOURCE_LOCATION(decl);
113867 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", DECL_NAME_POINTER(decl), argnum);
113868 +}
113869 +
113870 +// Get the field decl of a component ref for intentional_overflow checking
113871 +static const_tree search_field_decl(const_tree comp_ref)
113872 +{
113873 + const_tree field = NULL_TREE;
113874 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
113875 +
113876 + for (i = 0; i < len; i++) {
113877 + field = TREE_OPERAND(comp_ref, i);
113878 + if (TREE_CODE(field) == FIELD_DECL)
113879 + break;
113880 + }
113881 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
113882 + return field;
113883 +}
113884 +
113885 +/* Get the type of the intentional_overflow attribute of a node
113886 + * * MARK_TURN_OFF
113887 + * * MARK_YES
113888 + * * MARK_NO
113889 + * * MARK_NOT_INTENTIONAL
113890 + */
113891 +enum mark get_intentional_attr_type(const_tree node)
113892 +{
113893 + const_tree cur_decl;
113894 +
113895 + if (node == NULL_TREE)
113896 + return MARK_NO;
113897 +
113898 + switch (TREE_CODE(node)) {
113899 + case COMPONENT_REF:
113900 + cur_decl = search_field_decl(node);
113901 + if (is_turn_off_intentional_attr(cur_decl))
113902 + return MARK_TURN_OFF;
113903 + if (is_end_intentional_intentional_attr(cur_decl, 1))
113904 + return MARK_YES;
113905 + break;
113906 + case PARM_DECL: {
113907 + unsigned int argnum;
113908 +
113909 + cur_decl = DECL_ORIGIN(current_function_decl);
113910 + argnum = find_arg_number_tree(node, cur_decl);
113911 + if (argnum == CANNOT_FIND_ARG)
113912 + return MARK_NO;
113913 + if (is_yes_intentional_attr(cur_decl, argnum))
113914 + return MARK_YES;
113915 + if (is_end_intentional_intentional_attr(cur_decl, argnum))
113916 + return MARK_NOT_INTENTIONAL;
113917 + break;
113918 + }
113919 + case FUNCTION_DECL:
113920 + if (is_turn_off_intentional_attr(DECL_ORIGIN(node)))
113921 + return MARK_TURN_OFF;
113922 + break;
113923 + default:
113924 + break;
113925 + }
113926 + return MARK_NO;
113927 +}
113928 +
113929 +// Search for the intentional_overflow attribute on the last nodes
113930 +static enum mark search_last_nodes_intentional(struct interesting_node *cur_node)
113931 +{
113932 + unsigned int i;
113933 + tree last_node;
113934 + enum mark mark = MARK_NO;
113935 +
113936 +#if BUILDING_GCC_VERSION <= 4007
113937 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, last_node) {
113938 +#else
113939 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, last_node) {
113940 +#endif
113941 + mark = get_intentional_attr_type(last_node);
113942 + if (mark != MARK_NO)
113943 + break;
113944 + }
113945 + return mark;
113946 +}
113947 +
113948 +/* Check the intentional kind of size_overflow asm stmt (created by the gimple pass) and
113949 + * set the appropriate intentional_overflow type. Delete the asm stmt in the end.
113950 + */
113951 +static bool is_intentional_attribute_from_gimple(struct interesting_node *cur_node)
113952 +{
113953 + if (!cur_node->intentional_mark_from_gimple)
113954 + return false;
113955 +
113956 + if (is_size_overflow_intentional_asm_yes(cur_node->intentional_mark_from_gimple))
113957 + cur_node->intentional_attr_cur_fndecl = MARK_YES;
113958 + else
113959 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
113960 +
113961 + // skip param decls
113962 + if (gimple_asm_noutputs(cur_node->intentional_mark_from_gimple) == 0)
113963 + return true;
113964 + return true;
113965 +}
113966 +
113967 +/* Search intentional_overflow attribute on caller and on callee too.
113968 + * 0</MARK_YES: no dup, search size_overflow and intentional_overflow attributes
113969 + * 0/MARK_NOT_INTENTIONAL: no dup, search size_overflow attribute (int)
113970 + * -1/MARK_TURN_OFF: no dup, no search, current_function_decl -> no dup
113971 +*/
113972 +void check_intentional_attribute_ipa(struct interesting_node *cur_node)
113973 +{
113974 + const_tree fndecl;
113975 +
113976 + if (is_intentional_attribute_from_gimple(cur_node))
113977 + return;
113978 +
113979 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
113980 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
113981 + return;
113982 + }
113983 +
113984 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASM) {
113985 + cur_node->intentional_attr_cur_fndecl = MARK_NOT_INTENTIONAL;
113986 + return;
113987 + }
113988 +
113989 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASSIGN)
113990 + return;
113991 +
113992 + fndecl = get_interesting_orig_fndecl(cur_node->first_stmt, cur_node->num);
113993 + if (is_turn_off_intentional_attr(fndecl)) {
113994 + cur_node->intentional_attr_decl = MARK_TURN_OFF;
113995 + return;
113996 + }
113997 +
113998 + if (is_end_intentional_intentional_attr(fndecl, cur_node->num))
113999 + cur_node->intentional_attr_decl = MARK_NOT_INTENTIONAL;
114000 + else if (is_yes_intentional_attr(fndecl, cur_node->num))
114001 + cur_node->intentional_attr_decl = MARK_YES;
114002 +
114003 + cur_node->intentional_attr_cur_fndecl = search_last_nodes_intentional(cur_node);
114004 + print_missing_intentional(cur_node->intentional_attr_decl, cur_node->intentional_attr_cur_fndecl, cur_node->fndecl, cur_node->num);
114005 +}
114006 +
114007 +bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
114008 +{
114009 + const_tree rhs1, lhs, rhs1_type, lhs_type;
114010 + enum machine_mode lhs_mode, rhs_mode;
114011 + gimple def_stmt = get_def_stmt(no_const_rhs);
114012 +
114013 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
114014 + return false;
114015 +
114016 + rhs1 = gimple_assign_rhs1(def_stmt);
114017 + lhs = gimple_assign_lhs(def_stmt);
114018 + rhs1_type = TREE_TYPE(rhs1);
114019 + lhs_type = TREE_TYPE(lhs);
114020 + rhs_mode = TYPE_MODE(rhs1_type);
114021 + lhs_mode = TYPE_MODE(lhs_type);
114022 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
114023 + return false;
114024 +
114025 + return true;
114026 +}
114027 +
114028 +static unsigned int uses_num(tree node)
114029 +{
114030 + imm_use_iterator imm_iter;
114031 + use_operand_p use_p;
114032 + unsigned int num = 0;
114033 +
114034 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
114035 + gimple use_stmt = USE_STMT(use_p);
114036 +
114037 + if (use_stmt == NULL)
114038 + return num;
114039 + if (is_gimple_debug(use_stmt))
114040 + continue;
114041 + if (gimple_assign_cast_p(use_stmt) && is_size_overflow_type(gimple_assign_lhs(use_stmt)))
114042 + continue;
114043 + num++;
114044 + }
114045 + return num;
114046 +}
114047 +
114048 +static bool no_uses(tree node)
114049 +{
114050 + return !uses_num(node);
114051 +}
114052 +
114053 +// 3.8.5 mm/page-writeback.c __ilog2_u64(): ret, uint + uintmax; uint -> int; int max
114054 +bool is_const_plus_unsigned_signed_truncation(const_tree lhs)
114055 +{
114056 + tree rhs1, lhs_type, rhs_type, rhs2, not_const_rhs;
114057 + gimple def_stmt = get_def_stmt(lhs);
114058 +
114059 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
114060 + return false;
114061 +
114062 + rhs1 = gimple_assign_rhs1(def_stmt);
114063 + rhs_type = TREE_TYPE(rhs1);
114064 + lhs_type = TREE_TYPE(lhs);
114065 + if (TYPE_UNSIGNED(lhs_type) || !TYPE_UNSIGNED(rhs_type))
114066 + return false;
114067 + if (TYPE_MODE(lhs_type) != TYPE_MODE(rhs_type))
114068 + return false;
114069 +
114070 + def_stmt = get_def_stmt(rhs1);
114071 + if (!def_stmt || !is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 3)
114072 + return false;
114073 +
114074 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR)
114075 + return false;
114076 +
114077 + rhs1 = gimple_assign_rhs1(def_stmt);
114078 + rhs2 = gimple_assign_rhs2(def_stmt);
114079 + if (!is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
114080 + return false;
114081 +
114082 + if (is_gimple_constant(rhs2))
114083 + not_const_rhs = rhs1;
114084 + else
114085 + not_const_rhs = rhs2;
114086 +
114087 + return no_uses(not_const_rhs);
114088 +}
114089 +
114090 +static bool is_lt_signed_type_max(const_tree rhs)
114091 +{
114092 + const_tree new_type, type_max, type = TREE_TYPE(rhs);
114093 +
114094 + if (!TYPE_UNSIGNED(type))
114095 + return true;
114096 +
114097 + switch (TYPE_MODE(type)) {
114098 + case QImode:
114099 + new_type = intQI_type_node;
114100 + break;
114101 + case HImode:
114102 + new_type = intHI_type_node;
114103 + break;
114104 + case SImode:
114105 + new_type = intSI_type_node;
114106 + break;
114107 + case DImode:
114108 + new_type = intDI_type_node;
114109 + break;
114110 + default:
114111 + debug_tree((tree)type);
114112 + gcc_unreachable();
114113 + }
114114 +
114115 + type_max = TYPE_MAX_VALUE(new_type);
114116 + if (!tree_int_cst_lt(type_max, rhs))
114117 + return true;
114118 +
114119 + return false;
114120 +}
114121 +
114122 +static bool is_gt_zero(const_tree rhs)
114123 +{
114124 + const_tree type = TREE_TYPE(rhs);
114125 +
114126 + if (TYPE_UNSIGNED(type))
114127 + return true;
114128 +
114129 + if (!tree_int_cst_lt(rhs, integer_zero_node))
114130 + return true;
114131 +
114132 + return false;
114133 +}
114134 +
114135 +bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
114136 +{
114137 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
114138 + return false;
114139 + if (!is_gimple_constant(rhs))
114140 + return false;
114141 +
114142 + // If the const is between 0 and the max value of the signed type of the same bitsize then there is no intentional overflow
114143 + if (is_lt_signed_type_max(rhs) && is_gt_zero(rhs))
114144 + return false;
114145 +
114146 + return true;
114147 +}
114148 +
114149 +static tree change_assign_rhs(struct visited *visited, gimple stmt, const_tree orig_rhs, tree new_rhs)
114150 +{
114151 + gimple assign;
114152 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
114153 + tree origtype = TREE_TYPE(orig_rhs);
114154 +
114155 + gcc_assert(is_gimple_assign(stmt));
114156 +
114157 + assign = build_cast_stmt(visited, origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
114158 + pointer_set_insert(visited->my_stmts, assign);
114159 + return gimple_assign_lhs(assign);
114160 +}
114161 +
114162 +tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2)
114163 +{
114164 + tree new_rhs, orig_rhs;
114165 + void (*gimple_assign_set_rhs)(gimple, tree);
114166 + tree rhs1 = gimple_assign_rhs1(stmt);
114167 + tree rhs2 = gimple_assign_rhs2(stmt);
114168 + tree lhs = gimple_assign_lhs(stmt);
114169 +
114170 + if (!check_overflow)
114171 + return create_assign(visited, stmt, lhs, AFTER_STMT);
114172 +
114173 + if (change_rhs == NULL_TREE)
114174 + return create_assign(visited, stmt, lhs, AFTER_STMT);
114175 +
114176 + if (new_rhs2 == NULL_TREE) {
114177 + orig_rhs = rhs1;
114178 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
114179 + } else {
114180 + orig_rhs = rhs2;
114181 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
114182 + }
114183 +
114184 + check_size_overflow(caller_node, stmt, TREE_TYPE(change_rhs), change_rhs, orig_rhs, BEFORE_STMT);
114185 +
114186 + new_rhs = change_assign_rhs(visited, stmt, orig_rhs, change_rhs);
114187 + gimple_assign_set_rhs(stmt, new_rhs);
114188 + update_stmt(stmt);
114189 +
114190 + return create_assign(visited, stmt, lhs, AFTER_STMT);
114191 +}
114192 +
114193 +static bool is_subtraction_special(struct visited *visited, const_gimple stmt)
114194 +{
114195 + gimple rhs1_def_stmt, rhs2_def_stmt;
114196 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
114197 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
114198 + const_tree rhs1 = gimple_assign_rhs1(stmt);
114199 + const_tree rhs2 = gimple_assign_rhs2(stmt);
114200 +
114201 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
114202 + return false;
114203 +
114204 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
114205 +
114206 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
114207 + return false;
114208 +
114209 + rhs1_def_stmt = get_def_stmt(rhs1);
114210 + rhs2_def_stmt = get_def_stmt(rhs2);
114211 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
114212 + return false;
114213 +
114214 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
114215 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
114216 + rhs1_def_stmt_lhs = gimple_assign_lhs(rhs1_def_stmt);
114217 + rhs2_def_stmt_lhs = gimple_assign_lhs(rhs2_def_stmt);
114218 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
114219 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
114220 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
114221 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
114222 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
114223 + return false;
114224 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
114225 + return false;
114226 +
114227 + pointer_set_insert(visited->no_cast_check, rhs1_def_stmt);
114228 + pointer_set_insert(visited->no_cast_check, rhs2_def_stmt);
114229 + return true;
114230 +}
114231 +
114232 +static gimple create_binary_assign(struct visited *visited, enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
114233 +{
114234 + gimple assign;
114235 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
114236 + tree type = TREE_TYPE(rhs1);
114237 + tree lhs = create_new_var(type);
114238 +
114239 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
114240 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
114241 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
114242 +
114243 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
114244 + update_stmt(assign);
114245 + pointer_set_insert(visited->my_stmts, assign);
114246 + return assign;
114247 +}
114248 +
114249 +static tree cast_to_TI_type(struct visited *visited, gimple stmt, tree node)
114250 +{
114251 + gimple_stmt_iterator gsi;
114252 + gimple cast_stmt;
114253 + tree type = TREE_TYPE(node);
114254 +
114255 + if (types_compatible_p(type, intTI_type_node))
114256 + return node;
114257 +
114258 + gsi = gsi_for_stmt(stmt);
114259 + cast_stmt = build_cast_stmt(visited, intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
114260 + pointer_set_insert(visited->my_stmts, cast_stmt);
114261 + return gimple_assign_lhs(cast_stmt);
114262 +}
114263 +
114264 +static tree get_def_stmt_rhs(struct visited *visited, const_tree var)
114265 +{
114266 + tree rhs1, def_stmt_rhs1;
114267 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
114268 +
114269 + def_stmt = get_def_stmt(var);
114270 + if (!gimple_assign_cast_p(def_stmt))
114271 + return NULL_TREE;
114272 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && pointer_set_contains(visited->my_stmts, def_stmt) && gimple_assign_cast_p(def_stmt));
114273 +
114274 + rhs1 = gimple_assign_rhs1(def_stmt);
114275 + rhs1_def_stmt = get_def_stmt(rhs1);
114276 + if (!gimple_assign_cast_p(rhs1_def_stmt))
114277 + return rhs1;
114278 +
114279 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
114280 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
114281 +
114282 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
114283 + case GIMPLE_CALL:
114284 + case GIMPLE_NOP:
114285 + case GIMPLE_ASM:
114286 + case GIMPLE_PHI:
114287 + return def_stmt_rhs1;
114288 + case GIMPLE_ASSIGN:
114289 + return rhs1;
114290 + default:
114291 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
114292 + gcc_unreachable();
114293 + }
114294 +}
114295 +
114296 +tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs)
114297 +{
114298 + tree new_rhs1, new_rhs2;
114299 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
114300 + gimple assign, stmt = get_def_stmt(lhs);
114301 + tree rhs1 = gimple_assign_rhs1(stmt);
114302 + tree rhs2 = gimple_assign_rhs2(stmt);
114303 +
114304 + if (!is_subtraction_special(visited, stmt))
114305 + return NULL_TREE;
114306 +
114307 + new_rhs1 = expand(visited, caller_node, rhs1);
114308 + new_rhs2 = expand(visited, caller_node, rhs2);
114309 +
114310 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs1);
114311 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs2);
114312 +
114313 + if (new_rhs1_def_stmt_rhs1 == NULL_TREE || new_rhs2_def_stmt_rhs1 == NULL_TREE)
114314 + return NULL_TREE;
114315 +
114316 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
114317 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs1_def_stmt_rhs1);
114318 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs2_def_stmt_rhs1);
114319 + }
114320 +
114321 + assign = create_binary_assign(visited, MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
114322 + new_lhs = gimple_assign_lhs(assign);
114323 + check_size_overflow(caller_node, assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
114324 +
114325 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
114326 +}
114327 +
114328 +bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
114329 +{
114330 + const_gimple def_stmt;
114331 +
114332 + if (TREE_CODE(rhs) != SSA_NAME)
114333 + return false;
114334 +
114335 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
114336 + return false;
114337 +
114338 + def_stmt = get_def_stmt(rhs);
114339 + if (!is_gimple_assign(def_stmt) || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
114340 + return false;
114341 +
114342 + return true;
114343 +}
114344 +
114345 +/* e.g., drivers/acpi/acpica/utids.c acpi_ut_execute_CID()
114346 + * ((count - 1) * sizeof(struct acpi_pnp_dee_id_list) -> (count + fffffff) * 16
114347 + * fffffff * 16 > signed max -> truncate
114348 + */
114349 +static bool look_for_mult_and_add(const_gimple stmt)
114350 +{
114351 + const_tree res;
114352 + tree rhs1, rhs2, def_rhs1, def_rhs2, const_rhs, def_const_rhs;
114353 + const_gimple def_stmt;
114354 +
114355 + if (!stmt || gimple_code(stmt) == GIMPLE_NOP)
114356 + return false;
114357 + if (!is_gimple_assign(stmt))
114358 + return false;
114359 + if (gimple_assign_rhs_code(stmt) != MULT_EXPR)
114360 + return false;
114361 +
114362 + rhs1 = gimple_assign_rhs1(stmt);
114363 + rhs2 = gimple_assign_rhs2(stmt);
114364 + if (is_gimple_constant(rhs1)) {
114365 + const_rhs = rhs1;
114366 + def_stmt = get_def_stmt(rhs2);
114367 + } else if (is_gimple_constant(rhs2)) {
114368 + const_rhs = rhs2;
114369 + def_stmt = get_def_stmt(rhs1);
114370 + } else
114371 + return false;
114372 +
114373 + if (!is_gimple_assign(def_stmt))
114374 + return false;
114375 +
114376 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR && gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
114377 + return false;
114378 +
114379 + def_rhs1 = gimple_assign_rhs1(def_stmt);
114380 + def_rhs2 = gimple_assign_rhs2(def_stmt);
114381 + if (is_gimple_constant(def_rhs1))
114382 + def_const_rhs = def_rhs1;
114383 + else if (is_gimple_constant(def_rhs2))
114384 + def_const_rhs = def_rhs2;
114385 + else
114386 + return false;
114387 +
114388 + res = fold_binary_loc(gimple_location(def_stmt), MULT_EXPR, TREE_TYPE(const_rhs), const_rhs, def_const_rhs);
114389 + if (is_lt_signed_type_max(res) && is_gt_zero(res))
114390 + return false;
114391 + return true;
114392 +}
114393 +
114394 +enum intentional_overflow_type add_mul_intentional_overflow(const_gimple stmt)
114395 +{
114396 + const_gimple def_stmt_1, def_stmt_2;
114397 + const_tree rhs1, rhs2;
114398 + bool add_mul_rhs1, add_mul_rhs2;
114399 +
114400 + rhs1 = gimple_assign_rhs1(stmt);
114401 + def_stmt_1 = get_def_stmt(rhs1);
114402 + add_mul_rhs1 = look_for_mult_and_add(def_stmt_1);
114403 +
114404 + rhs2 = gimple_assign_rhs2(stmt);
114405 + def_stmt_2 = get_def_stmt(rhs2);
114406 + add_mul_rhs2 = look_for_mult_and_add(def_stmt_2);
114407 +
114408 + if (add_mul_rhs1)
114409 + return RHS1_INTENTIONAL_OVERFLOW;
114410 + if (add_mul_rhs2)
114411 + return RHS2_INTENTIONAL_OVERFLOW;
114412 + return NO_INTENTIONAL_OVERFLOW;
114413 +}
114414 +
114415 +static gimple get_dup_stmt(struct visited *visited, gimple stmt)
114416 +{
114417 + gimple my_stmt;
114418 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
114419 +
114420 + gsi_next(&gsi);
114421 + my_stmt = gsi_stmt(gsi);
114422 +
114423 + gcc_assert(pointer_set_contains(visited->my_stmts, my_stmt));
114424 + gcc_assert(gimple_assign_rhs_code(stmt) == gimple_assign_rhs_code(my_stmt));
114425 +
114426 + return my_stmt;
114427 +}
114428 +
114429 +/* unsigned type -> unary or binary assign (rhs1 or rhs2 is constant)
114430 + * unsigned type cast to signed type, unsigned type: no more uses
114431 + * e.g., lib/vsprintf.c:simple_strtol()
114432 + * _10 = (unsigned long int) _9
114433 + * _11 = -_10;
114434 + * _12 = (long int) _11; (_11_ no more uses)
114435 + */
114436 +static bool is_call_or_cast(gimple stmt)
114437 +{
114438 + return gimple_assign_cast_p(stmt) || is_gimple_call(stmt);
114439 +}
114440 +
114441 +static bool is_unsigned_cast_or_call_def_stmt(const_tree node)
114442 +{
114443 + const_tree rhs;
114444 + gimple def_stmt;
114445 +
114446 + if (node == NULL_TREE)
114447 + return true;
114448 + if (is_gimple_constant(node))
114449 + return true;
114450 +
114451 + def_stmt = get_def_stmt(node);
114452 + if (!def_stmt)
114453 + return false;
114454 +
114455 + if (is_call_or_cast(def_stmt))
114456 + return true;
114457 +
114458 + if (!is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 2)
114459 + return false;
114460 + rhs = gimple_assign_rhs1(def_stmt);
114461 + def_stmt = get_def_stmt(rhs);
114462 + if (!def_stmt)
114463 + return false;
114464 + return is_call_or_cast(def_stmt);
114465 +}
114466 +
114467 +void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt)
114468 +{
114469 + unsigned int use_num;
114470 + gimple so_stmt;
114471 + const_gimple def_stmt;
114472 + const_tree rhs1, rhs2;
114473 + tree rhs = gimple_assign_rhs1(stmt);
114474 + tree lhs_type = TREE_TYPE(gimple_assign_lhs(stmt));
114475 + const_tree rhs_type = TREE_TYPE(rhs);
114476 +
114477 + if (!(TYPE_UNSIGNED(rhs_type) && !TYPE_UNSIGNED(lhs_type)))
114478 + return;
114479 + if (GET_MODE_BITSIZE(TYPE_MODE(rhs_type)) != GET_MODE_BITSIZE(TYPE_MODE(lhs_type)))
114480 + return;
114481 + use_num = uses_num(rhs);
114482 + if (use_num != 1)
114483 + return;
114484 +
114485 + def_stmt = get_def_stmt(rhs);
114486 + if (!def_stmt)
114487 + return;
114488 + if (!is_gimple_assign(def_stmt))
114489 + return;
114490 +
114491 + rhs1 = gimple_assign_rhs1(def_stmt);
114492 + if (!is_unsigned_cast_or_call_def_stmt(rhs1))
114493 + return;
114494 +
114495 + rhs2 = gimple_assign_rhs2(def_stmt);
114496 + if (!is_unsigned_cast_or_call_def_stmt(rhs2))
114497 + return;
114498 + if (gimple_num_ops(def_stmt) == 3 && !is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
114499 + return;
114500 +
114501 + so_stmt = get_dup_stmt(visited, stmt);
114502 + create_up_and_down_cast(visited, so_stmt, lhs_type, gimple_assign_rhs1(so_stmt));
114503 +}
114504 +
114505 diff --git a/tools/gcc/size_overflow_plugin/misc.c b/tools/gcc/size_overflow_plugin/misc.c
114506 new file mode 100644
114507 index 0000000..4bddad2
114508 --- /dev/null
114509 +++ b/tools/gcc/size_overflow_plugin/misc.c
114510 @@ -0,0 +1,203 @@
114511 +/*
114512 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
114513 + * Licensed under the GPL v2, or (at your option) v3
114514 + *
114515 + * Homepage:
114516 + * http://www.grsecurity.net/~ephox/overflow_plugin/
114517 + *
114518 + * Documentation:
114519 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
114520 + *
114521 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
114522 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
114523 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
114524 + *
114525 + * Usage:
114526 + * $ make
114527 + * $ make run
114528 + */
114529 +
114530 +#include "gcc-common.h"
114531 +#include "size_overflow.h"
114532 +
114533 +void set_current_function_decl(tree fndecl)
114534 +{
114535 + gcc_assert(fndecl != NULL_TREE);
114536 +
114537 + push_cfun(DECL_STRUCT_FUNCTION(fndecl));
114538 + calculate_dominance_info(CDI_DOMINATORS);
114539 + current_function_decl = fndecl;
114540 +}
114541 +
114542 +void unset_current_function_decl(void)
114543 +{
114544 + free_dominance_info(CDI_DOMINATORS);
114545 + pop_cfun();
114546 + current_function_decl = NULL_TREE;
114547 +}
114548 +
114549 +static bool is_bool(const_tree node)
114550 +{
114551 + const_tree type;
114552 +
114553 + if (node == NULL_TREE)
114554 + return false;
114555 +
114556 + type = TREE_TYPE(node);
114557 + if (!INTEGRAL_TYPE_P(type))
114558 + return false;
114559 + if (TREE_CODE(type) == BOOLEAN_TYPE)
114560 + return true;
114561 + if (TYPE_PRECISION(type) == 1)
114562 + return true;
114563 + return false;
114564 +}
114565 +
114566 +bool skip_types(const_tree var)
114567 +{
114568 + tree type;
114569 + enum tree_code code;
114570 +
114571 + if (is_gimple_constant(var))
114572 + return true;
114573 +
114574 + switch (TREE_CODE(var)) {
114575 + case ADDR_EXPR:
114576 +#if BUILDING_GCC_VERSION >= 4006
114577 + case MEM_REF:
114578 +#endif
114579 + case ARRAY_REF:
114580 + case BIT_FIELD_REF:
114581 + case INDIRECT_REF:
114582 + case TARGET_MEM_REF:
114583 + case COMPONENT_REF:
114584 + case VAR_DECL:
114585 + case VIEW_CONVERT_EXPR:
114586 + return true;
114587 + default:
114588 + break;
114589 + }
114590 +
114591 + code = TREE_CODE(var);
114592 + gcc_assert(code == SSA_NAME || code == PARM_DECL);
114593 +
114594 + type = TREE_TYPE(var);
114595 + switch (TREE_CODE(type)) {
114596 + case INTEGER_TYPE:
114597 + case ENUMERAL_TYPE:
114598 + return false;
114599 + case BOOLEAN_TYPE:
114600 + return is_bool(var);
114601 + default:
114602 + return true;
114603 + }
114604 +}
114605 +
114606 +gimple get_def_stmt(const_tree node)
114607 +{
114608 + gcc_assert(node != NULL_TREE);
114609 +
114610 + if (skip_types(node))
114611 + return NULL;
114612 +
114613 + if (TREE_CODE(node) != SSA_NAME)
114614 + return NULL;
114615 + return SSA_NAME_DEF_STMT(node);
114616 +}
114617 +
114618 +tree create_new_var(tree type)
114619 +{
114620 + tree new_var = create_tmp_var(type, "cicus");
114621 +
114622 + add_referenced_var(new_var);
114623 + return new_var;
114624 +}
114625 +
114626 +static bool skip_cast(tree dst_type, const_tree rhs, bool force)
114627 +{
114628 + const_gimple def_stmt = get_def_stmt(rhs);
114629 +
114630 + if (force)
114631 + return false;
114632 +
114633 + if (is_gimple_constant(rhs))
114634 + return false;
114635 +
114636 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
114637 + return false;
114638 +
114639 + if (!types_compatible_p(dst_type, TREE_TYPE(rhs)))
114640 + return false;
114641 +
114642 + // DI type can be on 32 bit (from create_assign) but overflow type stays DI
114643 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
114644 + return false;
114645 +
114646 + return true;
114647 +}
114648 +
114649 +tree cast_a_tree(tree type, tree var)
114650 +{
114651 + gcc_assert(type != NULL_TREE);
114652 + gcc_assert(var != NULL_TREE);
114653 + gcc_assert(fold_convertible_p(type, var));
114654 +
114655 + return fold_convert(type, var);
114656 +}
114657 +
114658 +gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force)
114659 +{
114660 + gimple assign, def_stmt;
114661 +
114662 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
114663 + gcc_assert(!is_gimple_constant(rhs));
114664 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
114665 + gcc_unreachable();
114666 +
114667 + def_stmt = get_def_stmt(rhs);
114668 + if (def_stmt && gimple_code(def_stmt) != GIMPLE_NOP && skip_cast(dst_type, rhs, force) && pointer_set_contains(visited->my_stmts, def_stmt))
114669 + return def_stmt;
114670 +
114671 + if (lhs == CREATE_NEW_VAR)
114672 + lhs = create_new_var(dst_type);
114673 +
114674 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
114675 +
114676 + if (!gsi_end_p(*gsi)) {
114677 + location_t loc = gimple_location(gsi_stmt(*gsi));
114678 + gimple_set_location(assign, loc);
114679 + }
114680 +
114681 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
114682 +
114683 + if (before)
114684 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
114685 + else
114686 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
114687 + update_stmt(assign);
114688 + return assign;
114689 +}
114690 +
114691 +bool is_size_overflow_type(const_tree var)
114692 +{
114693 + const char *name;
114694 + const_tree type_name, type;
114695 +
114696 + if (var == NULL_TREE)
114697 + return false;
114698 +
114699 + type = TREE_TYPE(var);
114700 + type_name = TYPE_NAME(type);
114701 + if (type_name == NULL_TREE)
114702 + return false;
114703 +
114704 + if (DECL_P(type_name))
114705 + name = DECL_NAME_POINTER(type_name);
114706 + else
114707 + name = IDENTIFIER_POINTER(type_name);
114708 +
114709 + if (!strncmp(name, "size_overflow_type", 18))
114710 + return true;
114711 + return false;
114712 +}
114713 +
114714 diff --git a/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
114715 new file mode 100644
114716 index 0000000..7c9e6d1
114717 --- /dev/null
114718 +++ b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
114719 @@ -0,0 +1,138 @@
114720 +/*
114721 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
114722 + * Licensed under the GPL v2, or (at your option) v3
114723 + *
114724 + * Homepage:
114725 + * http://www.grsecurity.net/~ephox/overflow_plugin/
114726 + *
114727 + * Documentation:
114728 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
114729 + *
114730 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
114731 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
114732 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
114733 + *
114734 + * Usage:
114735 + * $ make
114736 + * $ make run
114737 + */
114738 +
114739 +#include "gcc-common.h"
114740 +#include "size_overflow.h"
114741 +
114742 +bool skip_expr_on_double_type(const_gimple stmt)
114743 +{
114744 + enum tree_code code = gimple_assign_rhs_code(stmt);
114745 +
114746 + switch (code) {
114747 + case RSHIFT_EXPR:
114748 + case TRUNC_DIV_EXPR:
114749 + case CEIL_DIV_EXPR:
114750 + case FLOOR_DIV_EXPR:
114751 + case ROUND_DIV_EXPR:
114752 + case EXACT_DIV_EXPR:
114753 + case RDIV_EXPR:
114754 + case TRUNC_MOD_EXPR:
114755 + case CEIL_MOD_EXPR:
114756 + case FLOOR_MOD_EXPR:
114757 + case ROUND_MOD_EXPR:
114758 + return true;
114759 + default:
114760 + return false;
114761 + }
114762 +}
114763 +
114764 +void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs)
114765 +{
114766 + const_tree orig_rhs1;
114767 + tree down_lhs, new_lhs, dup_type = TREE_TYPE(rhs);
114768 + gimple down_cast, up_cast;
114769 + gimple_stmt_iterator gsi = gsi_for_stmt(use_stmt);
114770 +
114771 + down_cast = build_cast_stmt(visited, orig_type, rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
114772 + down_lhs = gimple_assign_lhs(down_cast);
114773 +
114774 + gsi = gsi_for_stmt(use_stmt);
114775 + up_cast = build_cast_stmt(visited, dup_type, down_lhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
114776 + new_lhs = gimple_assign_lhs(up_cast);
114777 +
114778 + orig_rhs1 = gimple_assign_rhs1(use_stmt);
114779 + if (operand_equal_p(orig_rhs1, rhs, 0))
114780 + gimple_assign_set_rhs1(use_stmt, new_lhs);
114781 + else
114782 + gimple_assign_set_rhs2(use_stmt, new_lhs);
114783 + update_stmt(use_stmt);
114784 +
114785 + pointer_set_insert(visited->my_stmts, up_cast);
114786 + pointer_set_insert(visited->my_stmts, down_cast);
114787 + pointer_set_insert(visited->skip_expr_casts, up_cast);
114788 + pointer_set_insert(visited->skip_expr_casts, down_cast);
114789 +}
114790 +
114791 +static tree get_proper_unsigned_half_type(const_tree node)
114792 +{
114793 + tree new_type, type;
114794 +
114795 + gcc_assert(is_size_overflow_type(node));
114796 +
114797 + type = TREE_TYPE(node);
114798 + switch (TYPE_MODE(type)) {
114799 + case HImode:
114800 + new_type = unsigned_intQI_type_node;
114801 + break;
114802 + case SImode:
114803 + new_type = unsigned_intHI_type_node;
114804 + break;
114805 + case DImode:
114806 + new_type = unsigned_intSI_type_node;
114807 + break;
114808 + case TImode:
114809 + new_type = unsigned_intDI_type_node;
114810 + break;
114811 + default:
114812 + gcc_unreachable();
114813 + }
114814 +
114815 + if (TYPE_QUALS(type) != 0)
114816 + return build_qualified_type(new_type, TYPE_QUALS(type));
114817 + return new_type;
114818 +}
114819 +
114820 +static void insert_cast_rhs(struct visited *visited, gimple stmt, tree rhs)
114821 +{
114822 + tree type;
114823 +
114824 + if (rhs == NULL_TREE)
114825 + return;
114826 + if (!is_size_overflow_type(rhs))
114827 + return;
114828 +
114829 + type = get_proper_unsigned_half_type(rhs);
114830 + if (is_gimple_constant(rhs))
114831 + return;
114832 + create_up_and_down_cast(visited, stmt, type, rhs);
114833 +}
114834 +
114835 +static void insert_cast(struct visited *visited, gimple stmt, tree rhs)
114836 +{
114837 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && !is_size_overflow_type(rhs))
114838 + return;
114839 + gcc_assert(is_size_overflow_type(rhs));
114840 + insert_cast_rhs(visited, stmt, rhs);
114841 +}
114842 +
114843 +void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type)
114844 +{
114845 + tree rhs1, rhs2;
114846 +
114847 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS1_INTENTIONAL_OVERFLOW) {
114848 + rhs1 = gimple_assign_rhs1(stmt);
114849 + insert_cast(visited, stmt, rhs1);
114850 + }
114851 +
114852 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS2_INTENTIONAL_OVERFLOW) {
114853 + rhs2 = gimple_assign_rhs2(stmt);
114854 + insert_cast(visited, stmt, rhs2);
114855 + }
114856 +}
114857 +
114858 diff --git a/tools/gcc/size_overflow_plugin/size_overflow.h b/tools/gcc/size_overflow_plugin/size_overflow.h
114859 new file mode 100644
114860 index 0000000..e5b4e50
114861 --- /dev/null
114862 +++ b/tools/gcc/size_overflow_plugin/size_overflow.h
114863 @@ -0,0 +1,127 @@
114864 +#ifndef SIZE_OVERFLOW_H
114865 +#define SIZE_OVERFLOW_H
114866 +
114867 +#define CREATE_NEW_VAR NULL_TREE
114868 +#define CANNOT_FIND_ARG 32
114869 +#define MAX_PARAM 31
114870 +#define BEFORE_STMT true
114871 +#define AFTER_STMT false
114872 +
114873 +#define TURN_OFF_ASM_STR "# size_overflow MARK_TURN_OFF "
114874 +#define YES_ASM_STR "# size_overflow MARK_YES "
114875 +#define OK_ASM_STR "# size_overflow "
114876 +
114877 +enum mark {
114878 + MARK_NO, MARK_YES, MARK_NOT_INTENTIONAL, MARK_TURN_OFF
114879 +};
114880 +
114881 +enum intentional_overflow_type {
114882 + NO_INTENTIONAL_OVERFLOW, RHS1_INTENTIONAL_OVERFLOW, RHS2_INTENTIONAL_OVERFLOW
114883 +};
114884 +
114885 +struct visited {
114886 + struct pointer_set_t *stmts;
114887 + struct pointer_set_t *my_stmts;
114888 + struct pointer_set_t *skip_expr_casts;
114889 + struct pointer_set_t *no_cast_check;
114890 +};
114891 +
114892 +// size_overflow_plugin.c
114893 +extern tree report_size_overflow_decl;
114894 +extern tree size_overflow_type_HI;
114895 +extern tree size_overflow_type_SI;
114896 +extern tree size_overflow_type_DI;
114897 +extern tree size_overflow_type_TI;
114898 +
114899 +
114900 +// size_overflow_plugin_hash.c
114901 +struct size_overflow_hash {
114902 + const struct size_overflow_hash * const next;
114903 + const char * const name;
114904 + const unsigned int param;
114905 +};
114906 +
114907 +struct interesting_node {
114908 + struct interesting_node *next;
114909 + gimple first_stmt;
114910 + const_tree fndecl;
114911 + tree node;
114912 +#if BUILDING_GCC_VERSION <= 4007
114913 + VEC(tree, gc) *last_nodes;
114914 +#else
114915 + vec<tree, va_gc> *last_nodes;
114916 +#endif
114917 + unsigned int num;
114918 + enum mark intentional_attr_decl;
114919 + enum mark intentional_attr_cur_fndecl;
114920 + gimple intentional_mark_from_gimple;
114921 +};
114922 +
114923 +extern bool is_size_overflow_asm(const_gimple stmt);
114924 +extern unsigned int get_function_num(const_tree node, const_tree orig_fndecl);
114925 +extern unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl);
114926 +extern bool is_missing_function(const_tree orig_fndecl, unsigned int num);
114927 +extern bool is_a_return_check(const_tree node);
114928 +extern const struct size_overflow_hash *get_function_hash(const_tree fndecl);
114929 +extern unsigned int find_arg_number_tree(const_tree arg, const_tree func);
114930 +
114931 +
114932 +// size_overflow_debug.c
114933 +extern struct opt_pass *make_dump_pass(void);
114934 +
114935 +
114936 +// intentional_overflow.c
114937 +extern enum mark get_intentional_attr_type(const_tree node);
114938 +extern bool is_size_overflow_intentional_asm_yes(const_gimple stmt);
114939 +extern bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt);
114940 +extern bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum);
114941 +extern bool is_yes_intentional_attr(const_tree decl, unsigned int argnum);
114942 +extern bool is_turn_off_intentional_attr(const_tree decl);
114943 +extern void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum);
114944 +extern void check_intentional_attribute_ipa(struct interesting_node *cur_node);
114945 +extern bool is_a_cast_and_const_overflow(const_tree no_const_rhs);
114946 +extern bool is_const_plus_unsigned_signed_truncation(const_tree lhs);
114947 +extern bool is_a_constant_overflow(const_gimple stmt, const_tree rhs);
114948 +extern tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2);
114949 +extern tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs);
114950 +extern bool is_a_neg_overflow(const_gimple stmt, const_tree rhs);
114951 +extern enum intentional_overflow_type add_mul_intentional_overflow(const_gimple def_stmt);
114952 +extern void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt);
114953 +
114954 +
114955 +// insert_size_overflow_check_ipa.c
114956 +extern unsigned int search_function(void);
114957 +extern unsigned int call_count;
114958 +extern struct opt_pass *make_insert_size_overflow_check(void);
114959 +extern const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum);
114960 +
114961 +
114962 +// insert_size_overflow_asm.c
114963 +extern struct opt_pass *make_insert_size_overflow_asm_pass(void);
114964 +
114965 +
114966 +// misc.c
114967 +extern void set_current_function_decl(tree fndecl);
114968 +extern void unset_current_function_decl(void);
114969 +extern gimple get_def_stmt(const_tree node);
114970 +extern tree create_new_var(tree type);
114971 +extern gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force);
114972 +extern bool skip_types(const_tree var);
114973 +extern tree cast_a_tree(tree type, tree var);
114974 +extern bool is_size_overflow_type(const_tree var);
114975 +
114976 +
114977 +// insert_size_overflow_check_core.c
114978 +extern tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs);
114979 +extern void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
114980 +extern tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
114981 +extern tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before);
114982 +
114983 +
114984 +// remove_unnecessary_dup.c
114985 +extern struct opt_pass *make_remove_unnecessary_dup_pass(void);
114986 +extern void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type);
114987 +extern bool skip_expr_on_double_type(const_gimple stmt);
114988 +extern void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs);
114989 +
114990 +#endif
114991 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_debug.c b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
114992 new file mode 100644
114993 index 0000000..4378111
114994 --- /dev/null
114995 +++ b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
114996 @@ -0,0 +1,116 @@
114997 +/*
114998 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
114999 + * Licensed under the GPL v2, or (at your option) v3
115000 + *
115001 + * Homepage:
115002 + * http://www.grsecurity.net/~ephox/overflow_plugin/
115003 + *
115004 + * Documentation:
115005 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
115006 + *
115007 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
115008 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
115009 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
115010 + *
115011 + * Usage:
115012 + * $ make
115013 + * $ make run
115014 + */
115015 +
115016 +#include "gcc-common.h"
115017 +
115018 +static unsigned int dump_functions(void)
115019 +{
115020 + struct cgraph_node *node;
115021 +
115022 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
115023 + basic_block bb;
115024 +
115025 + push_cfun(DECL_STRUCT_FUNCTION(NODE_DECL(node)));
115026 + current_function_decl = NODE_DECL(node);
115027 +
115028 + fprintf(stderr, "-----------------------------------------\n%s\n-----------------------------------------\n", DECL_NAME_POINTER(current_function_decl));
115029 +
115030 + FOR_ALL_BB_FN(bb, cfun) {
115031 + gimple_stmt_iterator si;
115032 +
115033 + fprintf(stderr, "<bb %u>:\n", bb->index);
115034 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
115035 + debug_gimple_stmt(gsi_stmt(si));
115036 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
115037 + debug_gimple_stmt(gsi_stmt(si));
115038 + fprintf(stderr, "\n");
115039 + }
115040 +
115041 + fprintf(stderr, "-------------------------------------------------------------------------\n");
115042 +
115043 + pop_cfun();
115044 + current_function_decl = NULL_TREE;
115045 + }
115046 +
115047 + fprintf(stderr, "###############################################################################\n");
115048 +
115049 + return 0;
115050 +}
115051 +
115052 +#if BUILDING_GCC_VERSION >= 4009
115053 +static const struct pass_data dump_pass_data = {
115054 +#else
115055 +static struct ipa_opt_pass_d dump_pass = {
115056 + .pass = {
115057 +#endif
115058 + .type = SIMPLE_IPA_PASS,
115059 + .name = "dump",
115060 +#if BUILDING_GCC_VERSION >= 4008
115061 + .optinfo_flags = OPTGROUP_NONE,
115062 +#endif
115063 +#if BUILDING_GCC_VERSION >= 4009
115064 + .has_gate = false,
115065 + .has_execute = true,
115066 +#else
115067 + .gate = NULL,
115068 + .execute = dump_functions,
115069 + .sub = NULL,
115070 + .next = NULL,
115071 + .static_pass_number = 0,
115072 +#endif
115073 + .tv_id = TV_NONE,
115074 + .properties_required = 0,
115075 + .properties_provided = 0,
115076 + .properties_destroyed = 0,
115077 + .todo_flags_start = 0,
115078 + .todo_flags_finish = 0,
115079 +#if BUILDING_GCC_VERSION < 4009
115080 + },
115081 + .generate_summary = NULL,
115082 + .write_summary = NULL,
115083 + .read_summary = NULL,
115084 +#if BUILDING_GCC_VERSION >= 4006
115085 + .write_optimization_summary = NULL,
115086 + .read_optimization_summary = NULL,
115087 +#endif
115088 + .stmt_fixup = NULL,
115089 + .function_transform_todo_flags_start = 0,
115090 + .function_transform = NULL,
115091 + .variable_transform = NULL,
115092 +#endif
115093 +};
115094 +
115095 +#if BUILDING_GCC_VERSION >= 4009
115096 +namespace {
115097 +class dump_pass : public ipa_opt_pass_d {
115098 +public:
115099 + dump_pass() : ipa_opt_pass_d(dump_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
115100 + unsigned int execute() { return dump_functions(); }
115101 +};
115102 +}
115103 +#endif
115104 +
115105 +struct opt_pass *make_dump_pass(void)
115106 +{
115107 +#if BUILDING_GCC_VERSION >= 4009
115108 + return new dump_pass();
115109 +#else
115110 + return &dump_pass.pass;
115111 +#endif
115112 +}
115113 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash.data b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
115114 new file mode 100644
115115 index 0000000..386792a
115116 --- /dev/null
115117 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
115118 @@ -0,0 +1,5808 @@
115119 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
115120 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
115121 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
115122 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
115123 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
115124 +padzero_55 padzero 1 55 &sel_read_policyvers_55
115125 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
115126 +__skb_to_sgvec_72 __skb_to_sgvec 0 72 NULL
115127 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
115128 +load_msg_95 load_msg 2 95 NULL
115129 +ipath_verbs_send_117 ipath_verbs_send 5-3 117 NULL
115130 +init_q_132 init_q 4 132 NULL
115131 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
115132 +hva_to_gfn_memslot_149 hva_to_gfn_memslot 0-1 149 NULL
115133 +ping_v6_sendmsg_152 ping_v6_sendmsg 4 152 NULL
115134 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 NULL nohasharray
115135 +ext4_ext_get_actual_len_153 ext4_ext_get_actual_len 0 153 &tracing_trace_options_write_153
115136 +pci_request_selected_regions_169 pci_request_selected_regions 0 169 NULL
115137 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
115138 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
115139 +ll_xattr_cache_seq_write_250 ll_xattr_cache_seq_write 3 250 NULL
115140 +br_port_info_size_268 br_port_info_size 0 268 NULL
115141 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
115142 +SYSC_connect_304 SYSC_connect 3 304 NULL
115143 +syslog_print_307 syslog_print 2 307 NULL
115144 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
115145 +mlx5_core_access_reg_361 mlx5_core_access_reg 3-5 361 NULL
115146 +aio_read_events_ring_410 aio_read_events_ring 3 410 NULL
115147 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
115148 +snd_ca0106_ptr_read_467 snd_ca0106_ptr_read 0 467 NULL
115149 +cfs_trace_set_debug_mb_usrstr_486 cfs_trace_set_debug_mb_usrstr 2 486 NULL
115150 +nvme_trans_modesel_data_488 nvme_trans_modesel_data 4 488 NULL
115151 +iwl_dbgfs_protection_mode_write_502 iwl_dbgfs_protection_mode_write 3 502 NULL
115152 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
115153 +ocfs2_validate_meta_ecc_bhs_527 ocfs2_validate_meta_ecc_bhs 0 527 NULL
115154 +zlib_deflate_workspacesize_537 zlib_deflate_workspacesize 0-1-2 537 NULL
115155 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
115156 +sco_sock_setsockopt_552 sco_sock_setsockopt 5 552 NULL
115157 +lpfc_nlp_state_name_556 lpfc_nlp_state_name 2 556 NULL
115158 +snd_aw2_saa7146_get_hw_ptr_playback_558 snd_aw2_saa7146_get_hw_ptr_playback 0 558 NULL
115159 +start_isoc_chain_565 start_isoc_chain 2 565 NULL nohasharray
115160 +dev_hard_header_565 dev_hard_header 0 565 &start_isoc_chain_565
115161 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
115162 +btrfs_stack_file_extent_offset_607 btrfs_stack_file_extent_offset 0 607 NULL
115163 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
115164 +fuse_request_alloc_nofs_617 fuse_request_alloc_nofs 1 617 NULL
115165 +ptlrpc_lprocfs_nrs_seq_write_621 ptlrpc_lprocfs_nrs_seq_write 3 621 NULL
115166 +viafb_dfpl_proc_write_627 viafb_dfpl_proc_write 3 627 NULL
115167 +ceph_osdc_new_request_635 ceph_osdc_new_request 6 635 NULL
115168 +cfs_hash_bkt_size_643 cfs_hash_bkt_size 0 643 NULL
115169 +unlink_queued_645 unlink_queued 4 645 NULL
115170 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
115171 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
115172 +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
115173 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
115174 +dvb_video_write_754 dvb_video_write 3 754 NULL
115175 +cfs_trace_allocate_string_buffer_781 cfs_trace_allocate_string_buffer 2 781 NULL
115176 +ath6kl_disconnect_timeout_write_794 ath6kl_disconnect_timeout_write 3 794 NULL
115177 +snd_pcm_drain_811 snd_pcm_drain 0 811 NULL
115178 +if_writecmd_815 if_writecmd 2 815 NULL
115179 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
115180 +error_state_read_859 error_state_read 6 859 NULL
115181 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
115182 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
115183 +snd_pcm_action_single_905 snd_pcm_action_single 0 905 NULL
115184 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
115185 +__nodes_weight_956 __nodes_weight 0 956 NULL
115186 +bnx2x_fill_fw_str_968 bnx2x_fill_fw_str 3 968 NULL
115187 +mnt_want_write_975 mnt_want_write 0 975 NULL
115188 +usnic_ib_qp_grp_dump_hdr_989 usnic_ib_qp_grp_dump_hdr 2 989 NULL
115189 +memcmp_990 memcmp 0 990 NULL
115190 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
115191 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
115192 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
115193 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
115194 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
115195 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
115196 +nfs4_init_nonuniform_client_string_1097 nfs4_init_nonuniform_client_string 3 1097 NULL
115197 +cfg80211_report_obss_beacon_1133 cfg80211_report_obss_beacon 3 1133 NULL
115198 +i2400m_rx_ctl_1157 i2400m_rx_ctl 4 1157 NULL
115199 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
115200 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
115201 +pstore_ftrace_knob_write_1198 pstore_ftrace_knob_write 3 1198 NULL
115202 +i2400m_rx_ctl_ack_1199 i2400m_rx_ctl_ack 3 1199 NULL
115203 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
115204 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
115205 +lov_ost_pool_init_1215 lov_ost_pool_init 2 1215 NULL
115206 +fsync_buffers_list_1219 fsync_buffers_list 0 1219 NULL
115207 +kernfs_file_direct_read_1238 kernfs_file_direct_read 3 1238 NULL
115208 +acpi_battery_write_alarm_1240 acpi_battery_write_alarm 3 1240 NULL
115209 +drm_primary_helper_create_plane_1262 drm_primary_helper_create_plane 3 1262 NULL
115210 +ocfs2_extend_file_1266 ocfs2_extend_file 3 1266 NULL
115211 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
115212 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
115213 +SyS_flistxattr_1287 SyS_flistxattr 3 1287 NULL
115214 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
115215 +posix_acl_xattr_set_1301 posix_acl_xattr_set 4 1301 NULL
115216 +ffs_1322 ffs 0 1322 NULL
115217 +qlcnic_pci_sriov_configure_1327 qlcnic_pci_sriov_configure 2 1327 NULL
115218 +btrfs_submit_compressed_write_1347 btrfs_submit_compressed_write 5 1347 NULL
115219 +snd_pcm_lib_write1_1358 snd_pcm_lib_write1 0-3 1358 NULL
115220 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
115221 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
115222 +ocfs2_prepare_inode_for_write_1372 ocfs2_prepare_inode_for_write 3 1372 NULL
115223 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
115224 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
115225 +SYSC_io_getevents_1392 SYSC_io_getevents 3 1392 NULL
115226 +cfs_trace_copyout_string_1416 cfs_trace_copyout_string 2 1416 NULL
115227 +init_rs_internal_1436 init_rs_internal 1 1436 NULL
115228 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
115229 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
115230 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
115231 +SYSC_syslog_1477 SYSC_syslog 3 1477 NULL
115232 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
115233 +fpregs_set_1497 fpregs_set 4 1497 NULL
115234 +tomoyo_round2_1518 tomoyo_round2 0 1518 NULL
115235 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
115236 +ath6kl_init_get_fwcaps_1557 ath6kl_init_get_fwcaps 3 1557 NULL
115237 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
115238 +ipath_ht_handle_hwerrors_1592 ipath_ht_handle_hwerrors 3 1592 NULL
115239 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
115240 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
115241 +v9fs_fid_xattr_get_1618 v9fs_fid_xattr_get 0 1618 NULL
115242 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
115243 +mei_cl_recv_1665 mei_cl_recv 3 1665 NULL
115244 +rmap_add_1677 rmap_add 3 1677 NULL
115245 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
115246 +iwl_dbgfs_d0i3_refs_read_1705 iwl_dbgfs_d0i3_refs_read 3 1705 NULL
115247 +pdu_write_u_1710 pdu_write_u 3 1710 NULL
115248 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
115249 +btrfs_dir_data_len_1714 btrfs_dir_data_len 0 1714 NULL
115250 +internal_create_group_1733 internal_create_group 0 1733 NULL
115251 +dev_irnet_read_1741 dev_irnet_read 3 1741 NULL
115252 +usb_ep_align_maybe_1743 usb_ep_align_maybe 0-3 1743 NULL
115253 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
115254 +cosa_write_1774 cosa_write 3 1774 NULL
115255 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
115256 +__nodelist_scnprintf_1815 __nodelist_scnprintf 2-0 1815 NULL
115257 +sb_issue_zeroout_1884 sb_issue_zeroout 3 1884 NULL
115258 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
115259 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
115260 +SyS_add_key_1900 SyS_add_key 4 1900 NULL
115261 +uhid_char_read_1920 uhid_char_read 3 1920 NULL
115262 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
115263 +bdev_erase_1933 bdev_erase 3 1933 NULL
115264 +ext3_fiemap_1936 ext3_fiemap 4 1936 NULL
115265 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL
115266 +ieee80211_if_fmt_dot11MeshConfirmTimeout_1945 ieee80211_if_fmt_dot11MeshConfirmTimeout 3 1945 NULL
115267 +__assign_irq_vector_1961 __assign_irq_vector 0 1961 NULL
115268 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
115269 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
115270 +gpio_power_write_1991 gpio_power_write 3 1991 NULL
115271 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
115272 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
115273 +ocfs2_global_qinit_alloc_2018 ocfs2_global_qinit_alloc 0 2018 NULL
115274 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
115275 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
115276 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
115277 +ocfs2_expand_inline_dir_2063 ocfs2_expand_inline_dir 3 2063 NULL
115278 +__generic_copy_from_user_intel_2073 __generic_copy_from_user_intel 0-3 2073 NULL
115279 +diva_set_driver_dbg_mask_2077 diva_set_driver_dbg_mask 0 2077 NULL
115280 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
115281 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
115282 +__set_print_fmt_2106 __set_print_fmt 0 2106 NULL
115283 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
115284 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
115285 +btrfs_file_extent_inline_len_2116 btrfs_file_extent_inline_len 0 2116 NULL
115286 +enable_read_2117 enable_read 3 2117 NULL
115287 +pcf50633_write_block_2124 pcf50633_write_block 2-3 2124 NULL
115288 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
115289 +iov_iter_count_2152 iov_iter_count 0 2152 NULL
115290 +__copy_to_user_ll_2157 __copy_to_user_ll 0-3 2157 NULL
115291 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
115292 +bio_integrity_alloc_2194 bio_integrity_alloc 3 2194 NULL
115293 +picolcd_debug_reset_write_2195 picolcd_debug_reset_write 3 2195 NULL
115294 +u32_array_read_2219 u32_array_read 3 2219 NULL nohasharray
115295 +mei_dbgfs_read_meclients_2219 mei_dbgfs_read_meclients 3 2219 &u32_array_read_2219
115296 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
115297 +netlbl_secattr_catmap_walk_2255 netlbl_secattr_catmap_walk 0-2 2255 NULL
115298 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
115299 +do_update_counters_2259 do_update_counters 4 2259 NULL
115300 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
115301 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
115302 +sr_read_cmd_2299 sr_read_cmd 5 2299 NULL
115303 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
115304 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
115305 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 NULL nohasharray
115306 +hfsplus_find_init_2318 hfsplus_find_init 0 2318 &picolcd_fb_write_2318
115307 +dice_hwdep_read_2326 dice_hwdep_read 3 2326 NULL
115308 +__erst_read_to_erange_2341 __erst_read_to_erange 0 2341 NULL
115309 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
115310 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
115311 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
115312 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
115313 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
115314 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
115315 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
115316 +raid1_size_2419 raid1_size 0-2 2419 NULL
115317 +arch_msi_check_device_2449 arch_msi_check_device 0 2449 NULL
115318 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
115319 +wiphy_new_2482 wiphy_new 2 2482 NULL
115320 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
115321 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
115322 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
115323 +ext4_get_inode_loc_2516 ext4_get_inode_loc 0 2516 NULL
115324 +batadv_tvlv_container_list_size_2524 batadv_tvlv_container_list_size 0 2524 NULL
115325 +smk_write_syslog_2529 smk_write_syslog 3 2529 NULL
115326 +__ceph_setxattr_2532 __ceph_setxattr 4 2532 NULL
115327 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
115328 +pcm_sanity_check_2574 pcm_sanity_check 0 2574 NULL
115329 +mdc_max_rpcs_in_flight_seq_write_2594 mdc_max_rpcs_in_flight_seq_write 3 2594 NULL
115330 +slot_bytes_2609 slot_bytes 0 2609 NULL
115331 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
115332 +switch_status_2629 switch_status 5 2629 NULL
115333 +tcp_xmit_size_goal_2661 tcp_xmit_size_goal 2 2661 NULL
115334 +osc_build_ppga_2670 osc_build_ppga 2 2670 NULL
115335 +ffs_ep0_read_2672 ffs_ep0_read 3 2672 NULL
115336 +oti6858_write_2692 oti6858_write 4 2692 NULL
115337 +nfc_llcp_send_ui_frame_2702 nfc_llcp_send_ui_frame 5 2702 NULL
115338 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
115339 +lprocfs_stats_counter_size_2708 lprocfs_stats_counter_size 0 2708 NULL
115340 +xfs_readdir_2767 xfs_readdir 3 2767 NULL
115341 +fsl_edma_alloc_desc_2769 fsl_edma_alloc_desc 2 2769 NULL
115342 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
115343 +set_msr_hyperv_pw_2785 set_msr_hyperv_pw 3 2785 NULL
115344 +device_add_attrs_2789 device_add_attrs 0 2789 NULL
115345 +iwl_dbgfs_clear_ucode_statistics_write_2804 iwl_dbgfs_clear_ucode_statistics_write 3 2804 NULL
115346 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
115347 +vb2_dc_get_userptr_2829 vb2_dc_get_userptr 2-3 2829 NULL nohasharray
115348 +snd_pcm_reset_2829 snd_pcm_reset 0 2829 &vb2_dc_get_userptr_2829
115349 +wait_for_avail_2847 wait_for_avail 0 2847 NULL
115350 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
115351 +irnet_ctrl_read_2863 irnet_ctrl_read 4 2863 NULL
115352 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
115353 +nla_padlen_2883 nla_padlen 1 2883 NULL
115354 +cmm_write_2896 cmm_write 3 2896 NULL
115355 +osc_import_seq_write_2923 osc_import_seq_write 3 2923 NULL
115356 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
115357 +nes_read_indexed_2946 nes_read_indexed 0 2946 NULL
115358 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
115359 +i40e_dbg_prep_dump_buf_2951 i40e_dbg_prep_dump_buf 2 2951 NULL
115360 +set_fast_connectable_2952 set_fast_connectable 4 2952 NULL
115361 +free_area_init_core_2962 free_area_init_core 2-3 2962 NULL
115362 +bio_setup_sector_2970 bio_setup_sector 3 2970 NULL
115363 +do_strnlen_user_2976 do_strnlen_user 0-2 2976 NULL
115364 +p9_nr_pages_2992 p9_nr_pages 0-2 2992 NULL
115365 +lov_stripetype_seq_write_3013 lov_stripetype_seq_write 3 3013 NULL
115366 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
115367 +depth_write_3021 depth_write 3 3021 NULL
115368 +snd_azf3328_codec_inl_3022 snd_azf3328_codec_inl 0 3022 NULL
115369 +nvme_split_and_submit_3027 nvme_split_and_submit 3 3027 NULL
115370 +kvm_unmap_hva_3028 kvm_unmap_hva 2 3028 NULL
115371 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
115372 +lpfc_idiag_mbxacc_write_3038 lpfc_idiag_mbxacc_write 3 3038 NULL nohasharray
115373 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 &lpfc_idiag_mbxacc_write_3038
115374 +nr_free_buffer_pages_3044 nr_free_buffer_pages 0 3044 NULL
115375 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
115376 +qp_alloc_ppn_set_3068 qp_alloc_ppn_set 2-4 3068 NULL
115377 +__blk_end_bidi_request_3070 __blk_end_bidi_request 3-4 3070 NULL
115378 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 NULL
115379 +read_file_antenna_diversity_3077 read_file_antenna_diversity 3 3077 NULL
115380 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
115381 +rb_alloc_3102 rb_alloc 1 3102 NULL
115382 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
115383 +print_time_3132 print_time 0 3132 NULL
115384 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
115385 +CIFSSMBSetPosixACL_3154 CIFSSMBSetPosixACL 5 3154 NULL
115386 +uv_num_possible_blades_3177 uv_num_possible_blades 0 3177 NULL
115387 +uinput_ioctl_handler_3181 uinput_ioctl_handler 2 3181 NULL nohasharray
115388 +uvc_video_stats_dump_3181 uvc_video_stats_dump 3 3181 &uinput_ioctl_handler_3181
115389 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
115390 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
115391 +alloc_context_3194 alloc_context 1 3194 NULL
115392 +shmem_pread_slow_3198 shmem_pread_slow 3-2 3198 NULL
115393 +codec_reg_write_file_3204 codec_reg_write_file 3 3204 NULL
115394 +SyS_sendto_3219 SyS_sendto 6 3219 NULL
115395 +btrfs_prealloc_file_range_3227 btrfs_prealloc_file_range 3 3227 NULL
115396 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
115397 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
115398 +ext3_xattr_find_entry_3237 ext3_xattr_find_entry 0 3237 NULL
115399 +key_key_read_3241 key_key_read 3 3241 NULL
115400 +__ilog2_u64_3284 __ilog2_u64 0 3284 NULL
115401 +ieee80211_if_write_beacon_loss_3296 ieee80211_if_write_beacon_loss 3 3296 NULL
115402 +cgroup_name_3300 cgroup_name 3 3300 NULL
115403 +__set_extent_bit_3305 __set_extent_bit 0 3305 NULL
115404 +__iovec_copy_from_user_inatomic_3314 __iovec_copy_from_user_inatomic 4-3-0 3314 NULL
115405 +_iwl_dbgfs_d3_sram_write_3315 _iwl_dbgfs_d3_sram_write 3 3315 NULL
115406 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
115407 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
115408 +sysfs_create_group_3339 sysfs_create_group 0 3339 NULL
115409 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
115410 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
115411 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
115412 +scnprintf_3360 scnprintf 0-2 3360 NULL
115413 +sr_read_3366 sr_read 3 3366 NULL
115414 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
115415 +isdn_readbchan_3401 isdn_readbchan 0-5 3401 NULL
115416 +mei_io_cb_alloc_resp_buf_3414 mei_io_cb_alloc_resp_buf 2 3414 NULL
115417 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
115418 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
115419 +SyS_msgsnd_3436 SyS_msgsnd 3 3436 NULL
115420 +softsynth_write_3455 softsynth_write 3 3455 NULL
115421 +snd_pcm_lib_readv_transfer_3464 snd_pcm_lib_readv_transfer 5-4-2 3464 NULL
115422 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
115423 +xfrm_migrate_msgsize_3496 xfrm_migrate_msgsize 1 3496 NULL
115424 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL
115425 +SyS_semtimedop_3532 SyS_semtimedop 3 3532 NULL
115426 +SyS_readv_3539 SyS_readv 3 3539 NULL
115427 +btrfs_dir_name_len_3549 btrfs_dir_name_len 0 3549 NULL
115428 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
115429 +evtchn_read_3569 evtchn_read 3 3569 NULL
115430 +ll_track_ppid_seq_write_3582 ll_track_ppid_seq_write 3 3582 NULL
115431 +vc_resize_3585 vc_resize 3-2 3585 NULL
115432 +kvm_mmu_notifier_change_pte_3596 kvm_mmu_notifier_change_pte 3 3596 NULL
115433 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
115434 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
115435 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
115436 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
115437 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
115438 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
115439 +_iwl_dbgfs_tx_flush_write_3675 _iwl_dbgfs_tx_flush_write 3 3675 NULL
115440 +snd_m3_assp_read_3703 snd_m3_assp_read 0 3703 NULL
115441 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
115442 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
115443 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
115444 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
115445 +hfsplus_direct_IO_3835 hfsplus_direct_IO 4 3835 NULL
115446 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
115447 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
115448 +get_fd_set_3866 get_fd_set 1 3866 NULL
115449 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
115450 +efivarfs_file_read_3893 efivarfs_file_read 3 3893 NULL
115451 +nvram_write_3894 nvram_write 3 3894 NULL
115452 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
115453 +comedi_buf_read_n_available_3899 comedi_buf_read_n_available 0 3899 NULL
115454 +vcs_write_3910 vcs_write 3 3910 NULL
115455 +SyS_move_pages_3920 SyS_move_pages 2 3920 NULL
115456 +brcmf_debugfs_fws_stats_read_3947 brcmf_debugfs_fws_stats_read 3 3947 NULL
115457 +mite_bytes_written_to_memory_lb_3987 mite_bytes_written_to_memory_lb 0 3987 NULL
115458 +do_add_counters_3992 do_add_counters 3 3992 NULL
115459 +obd_alloc_memmd_4002 obd_alloc_memmd 0 4002 NULL
115460 +userspace_status_4004 userspace_status 4 4004 NULL
115461 +mei_write_4005 mei_write 3 4005 NULL nohasharray
115462 +xfs_check_block_4005 xfs_check_block 4 4005 &mei_write_4005
115463 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
115464 +blk_end_request_4024 blk_end_request 3 4024 NULL
115465 +ext4_xattr_find_entry_4025 ext4_xattr_find_entry 0 4025 NULL
115466 +mtip_hw_read_registers_4037 mtip_hw_read_registers 3 4037 NULL
115467 +read_file_queues_4078 read_file_queues 3 4078 NULL
115468 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
115469 +tm6000_read_4151 tm6000_read 3 4151 NULL
115470 +mpt_raid_phys_disk_get_num_paths_4155 mpt_raid_phys_disk_get_num_paths 0 4155 NULL
115471 +msg_bits_4158 msg_bits 0-3-4 4158 NULL
115472 +get_alua_req_4166 get_alua_req 3 4166 NULL
115473 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
115474 +read_file_bool_4180 read_file_bool 3 4180 NULL
115475 +vring_new_virtqueue_4199 vring_new_virtqueue 2 4199 NULL
115476 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
115477 +__snd_gf1_read_addr_4210 __snd_gf1_read_addr 0 4210 NULL
115478 +ath6kl_force_roam_write_4282 ath6kl_force_roam_write 3 4282 NULL
115479 +goldfish_audio_write_4284 goldfish_audio_write 3 4284 NULL
115480 +get_connectors_for_crtc_4291 get_connectors_for_crtc 0 4291 NULL
115481 +__usbnet_read_cmd_4299 __usbnet_read_cmd 7 4299 NULL
115482 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
115483 +count_strings_4315 count_strings 0 4315 NULL
115484 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
115485 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
115486 +ima_eventdigest_init_common_4338 ima_eventdigest_init_common 2 4338 NULL
115487 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 3-0 4365 NULL
115488 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
115489 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 NULL nohasharray
115490 +access_process_vm_4412 access_process_vm 0 4412 &cxacru_cm_get_array_4412
115491 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
115492 +rtw_android_get_rssi_4421 rtw_android_get_rssi 0 4421 NULL
115493 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
115494 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
115495 +snd_seq_expand_var_event_4481 snd_seq_expand_var_event 0-5 4481 NULL
115496 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
115497 +set_link_security_4502 set_link_security 4 4502 NULL
115498 +ll_max_readahead_per_file_mb_seq_write_4531 ll_max_readahead_per_file_mb_seq_write 3 4531 NULL
115499 +tty_register_device_4544 tty_register_device 2 4544 NULL
115500 +fsl_edma_prep_slave_sg_4555 fsl_edma_prep_slave_sg 3 4555 NULL
115501 +btrfs_file_extent_inline_item_len_4575 btrfs_file_extent_inline_item_len 0 4575 NULL
115502 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
115503 +bch_alloc_4593 bch_alloc 1 4593 NULL
115504 +ll_rw_extents_stats_seq_write_4633 ll_rw_extents_stats_seq_write 3 4633 NULL
115505 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
115506 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
115507 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
115508 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
115509 +kone_receive_4690 kone_receive 4 4690 NULL
115510 +hash_netportnet6_expire_4702 hash_netportnet6_expire 4 4702 NULL
115511 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
115512 +show_header_4722 show_header 3 4722 NULL nohasharray
115513 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 &show_header_4722
115514 +ll_rw_offset_stats_seq_write_4736 ll_rw_offset_stats_seq_write 3 4736 NULL nohasharray
115515 +bitmap_startwrite_4736 bitmap_startwrite 2 4736 &ll_rw_offset_stats_seq_write_4736
115516 +lu_buf_alloc_4753 lu_buf_alloc 2 4753 NULL
115517 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
115518 +create_subvol_4791 create_subvol 4 4791 NULL
115519 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
115520 +C_SYSC_setsockopt_4806 C_SYSC_setsockopt 5 4806 NULL
115521 +repair_io_failure_4815 repair_io_failure 4-3 4815 NULL
115522 +comedi_buf_write_free_4847 comedi_buf_write_free 2 4847 NULL
115523 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
115524 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
115525 +ocfs2_defrag_extent_4873 ocfs2_defrag_extent 2 4873 NULL
115526 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
115527 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
115528 +ieee80211_if_fmt_ave_beacon_4941 ieee80211_if_fmt_ave_beacon 3 4941 NULL
115529 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
115530 +ath10k_read_chip_id_4969 ath10k_read_chip_id 3 4969 NULL
115531 +skb_network_header_len_4971 skb_network_header_len 0 4971 NULL
115532 +ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval_4976 ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval 3 4976 NULL
115533 +compat_SyS_ipc_5000 compat_SyS_ipc 3 5000 NULL
115534 +do_mincore_5018 do_mincore 0-2-1 5018 NULL
115535 +btrfs_punch_hole_5041 btrfs_punch_hole 2 5041 NULL
115536 +cfg80211_rx_mgmt_5056 cfg80211_rx_mgmt 5 5056 NULL
115537 +ocfs2_check_range_for_holes_5066 ocfs2_check_range_for_holes 2-3 5066 NULL
115538 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
115539 +snd_emu10k1_ptr20_read_5087 snd_emu10k1_ptr20_read 0 5087 NULL
115540 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3-4-0 5091 NULL nohasharray
115541 +get_random_bytes_5091 get_random_bytes 2 5091 &kfifo_copy_from_user_5091 nohasharray
115542 +blk_rq_sectors_5091 blk_rq_sectors 0 5091 &get_random_bytes_5091
115543 +sound_write_5102 sound_write 3 5102 NULL
115544 +i40e_dbg_netdev_ops_write_5117 i40e_dbg_netdev_ops_write 3 5117 NULL
115545 +qib_7220_handle_hwerrors_5142 qib_7220_handle_hwerrors 3 5142 NULL
115546 +__uwb_addr_print_5161 __uwb_addr_print 2 5161 NULL
115547 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
115548 +acpi_pcc_get_sqty_5176 acpi_pcc_get_sqty 0 5176 NULL
115549 +trf7970a_read_cont_5179 trf7970a_read_cont 4 5179 NULL
115550 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
115551 +dwc2_hcd_urb_alloc_5217 dwc2_hcd_urb_alloc 2 5217 NULL
115552 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
115553 +r592_write_fifo_pio_5315 r592_write_fifo_pio 3 5315 NULL
115554 +sbc_get_write_same_sectors_5317 sbc_get_write_same_sectors 0 5317 NULL
115555 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
115556 +uinput_ioctl_5342 uinput_ioctl 2 5342 NULL
115557 +cq_free_res_5355 cq_free_res 5 5355 NULL
115558 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
115559 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
115560 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
115561 +ll_xattr_cache_refill_5468 ll_xattr_cache_refill 0 5468 NULL
115562 +kernfs_fop_write_5471 kernfs_fop_write 3 5471 NULL
115563 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
115564 +pci_enable_msix_exact_5482 pci_enable_msix_exact 3-0 5482 NULL
115565 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
115566 +tty_write_5494 tty_write 3 5494 NULL
115567 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL nohasharray
115568 +ieee80211_if_fmt_last_beacon_5498 ieee80211_if_fmt_last_beacon 3 5498 &tomoyo_update_domain_5498
115569 +__max_nr_grant_frames_5505 __max_nr_grant_frames 0 5505 NULL
115570 +ieee80211_if_fmt_auto_open_plinks_5534 ieee80211_if_fmt_auto_open_plinks 3 5534 NULL
115571 +get_entry_msg_len_5552 get_entry_msg_len 0 5552 NULL
115572 +le_readq_5557 le_readq 0 5557 NULL
115573 +inw_5558 inw 0 5558 NULL
115574 +bioset_create_5580 bioset_create 1 5580 NULL
115575 +oz_ep_alloc_5587 oz_ep_alloc 1 5587 NULL
115576 +__remove_suid_5618 __remove_suid 0 5618 NULL
115577 +SYSC_fsetxattr_5639 SYSC_fsetxattr 4 5639 NULL
115578 +ext4_xattr_get_5661 ext4_xattr_get 0 5661 NULL
115579 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
115580 +get_arg_5694 get_arg 3 5694 NULL
115581 +subbuf_read_actor_5708 subbuf_read_actor 3 5708 NULL
115582 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
115583 +rts51x_transfer_data_partial_5735 rts51x_transfer_data_partial 6 5735 NULL
115584 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
115585 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
115586 +nvme_trans_bdev_char_page_5797 nvme_trans_bdev_char_page 3 5797 NULL
115587 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
115588 +nv50_disp_pioc_create__5812 nv50_disp_pioc_create_ 5 5812 NULL
115589 +ceph_x_encrypt_buflen_5829 ceph_x_encrypt_buflen 0-1 5829 NULL
115590 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
115591 +setup_req_5848 setup_req 3 5848 NULL
115592 +ria_page_count_5849 ria_page_count 0 5849 NULL
115593 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
115594 +uinput_compat_ioctl_5861 uinput_compat_ioctl 2 5861 NULL
115595 +lprocfs_fid_width_seq_write_5889 lprocfs_fid_width_seq_write 3 5889 NULL
115596 +port_show_regs_5904 port_show_regs 3 5904 NULL
115597 +rbd_segment_length_5907 rbd_segment_length 0-3-2 5907 NULL
115598 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
115599 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
115600 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
115601 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
115602 +ll_statahead_one_5962 ll_statahead_one 3 5962 NULL
115603 +__apu_get_register_5967 __apu_get_register 0 5967 NULL
115604 +ieee80211_if_fmt_rc_rateidx_mask_5ghz_5971 ieee80211_if_fmt_rc_rateidx_mask_5ghz 3 5971 NULL
115605 +SyS_semop_5980 SyS_semop 3 5980 NULL
115606 +alloc_msg_6072 alloc_msg 1 6072 NULL
115607 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
115608 +rts51x_ms_rw_multi_sector_6076 rts51x_ms_rw_multi_sector 3-4 6076 NULL
115609 +__mnt_want_write_6091 __mnt_want_write 0 6091 NULL
115610 +ipmi_addr_length_6110 ipmi_addr_length 0 6110 NULL nohasharray
115611 +force_static_address_read_6110 force_static_address_read 3 6110 &ipmi_addr_length_6110
115612 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
115613 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
115614 +ieee80211_if_fmt_beacon_timeout_6153 ieee80211_if_fmt_beacon_timeout 3 6153 NULL
115615 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
115616 +maybe_insert_hole_6167 maybe_insert_hole 3 6167 NULL
115617 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
115618 +SyS_setgroups_6182 SyS_setgroups 1 6182 NULL
115619 +mxt_show_instance_6207 mxt_show_instance 2-0 6207 NULL
115620 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
115621 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
115622 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
115623 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
115624 +of_gpio_count_6270 of_gpio_count 0 6270 NULL
115625 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
115626 +snd_hda_override_conn_list_6282 snd_hda_override_conn_list 3-0 6282 NULL nohasharray
115627 +xenbus_file_write_6282 xenbus_file_write 3 6282 &snd_hda_override_conn_list_6282
115628 +posix_acl_fix_xattr_to_user_6283 posix_acl_fix_xattr_to_user 2 6283 NULL
115629 +serial_port_in_6291 serial_port_in 0 6291 NULL
115630 +qlcnic_sriov_alloc_bc_msg_6309 qlcnic_sriov_alloc_bc_msg 2 6309 NULL
115631 +hfa384x_inw_6329 hfa384x_inw 0 6329 NULL nohasharray
115632 +SyS_mincore_6329 SyS_mincore 1-2 6329 &hfa384x_inw_6329
115633 +fuse_get_req_for_background_6337 fuse_get_req_for_background 2 6337 NULL
115634 +ucs2_strnlen_6342 ucs2_strnlen 0 6342 NULL
115635 +regcache_sync_block_raw_6350 regcache_sync_block_raw 5-4 6350 NULL
115636 +mei_dbgfs_read_devstate_6352 mei_dbgfs_read_devstate 3 6352 NULL
115637 +_proc_do_string_6376 _proc_do_string 2 6376 NULL
115638 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL
115639 +posix_acl_fix_xattr_userns_6420 posix_acl_fix_xattr_userns 4 6420 NULL
115640 +add_transaction_credits_6422 add_transaction_credits 2-3 6422 NULL
115641 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
115642 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
115643 +ieee80211_if_fmt_dot11MeshMaxRetries_6476 ieee80211_if_fmt_dot11MeshMaxRetries 3 6476 NULL
115644 +qp_memcpy_from_queue_6479 qp_memcpy_from_queue 5-4 6479 NULL
115645 +cipso_v4_map_lvl_hton_6490 cipso_v4_map_lvl_hton 0 6490 NULL
115646 +dbg_intr_buf_6501 dbg_intr_buf 2 6501 NULL
115647 +mei_read_6507 mei_read 3 6507 NULL
115648 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
115649 +wdm_read_6549 wdm_read 3 6549 NULL
115650 +dm_stats_create_6551 dm_stats_create 4-2-3 6551 NULL
115651 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
115652 +SyS_semtimedop_6563 SyS_semtimedop 3 6563 NULL
115653 +snd_pcm_hw_refine_old_user_6586 snd_pcm_hw_refine_old_user 0 6586 NULL
115654 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
115655 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
115656 +pvscsi_allocate_rings_6689 pvscsi_allocate_rings 0 6689 NULL
115657 +btrfs_lookup_csums_range_6696 btrfs_lookup_csums_range 2-3 6696 NULL
115658 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
115659 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
115660 +mpeg_read_6708 mpeg_read 3 6708 NULL
115661 +ibmpex_query_sensor_count_6709 ibmpex_query_sensor_count 0 6709 NULL
115662 +video_proc_write_6724 video_proc_write 3 6724 NULL
115663 +posix_acl_xattr_count_6725 posix_acl_xattr_count 0-1 6725 NULL
115664 +kobject_add_varg_6781 kobject_add_varg 0 6781 NULL
115665 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
115666 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
115667 +zone_spanned_pages_in_node_6787 zone_spanned_pages_in_node 0-3-4 6787 NULL
115668 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
115669 +ll_xattr_cache_find_6798 ll_xattr_cache_find 0 6798 NULL
115670 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
115671 +lbs_rdrf_write_6826 lbs_rdrf_write 3 6826 NULL
115672 +calc_pages_for_6838 calc_pages_for 0-2-1 6838 NULL
115673 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
115674 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
115675 +perf_output_sample_ustack_6868 perf_output_sample_ustack 2 6868 NULL
115676 +dio_complete_6879 dio_complete 0-3-2 6879 NULL
115677 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL nohasharray
115678 +ieee80211_if_fmt_path_refresh_time_6888 ieee80211_if_fmt_path_refresh_time 3 6888 &raw_seticmpfilter_6888
115679 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
115680 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 NULL nohasharray
115681 +spi_show_regs_6911 spi_show_regs 3 6911 &proc_sessionid_read_6911 nohasharray
115682 +acm_alloc_minor_6911 acm_alloc_minor 0 6911 &spi_show_regs_6911
115683 +__kfifo_dma_in_finish_r_6913 __kfifo_dma_in_finish_r 2-3 6913 NULL
115684 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
115685 +ipath_verbs_send_dma_6929 ipath_verbs_send_dma 6 6929 NULL
115686 +qsfp_cks_6945 qsfp_cks 2-0 6945 NULL
115687 +tg3_nvram_write_block_unbuffered_6955 tg3_nvram_write_block_unbuffered 3 6955 NULL
115688 +pch_uart_hal_read_6961 pch_uart_hal_read 0 6961 NULL
115689 +i40e_dbg_dump_write_6973 i40e_dbg_dump_write 3 6973 NULL nohasharray
115690 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 &i40e_dbg_dump_write_6973
115691 +request_key_async_6990 request_key_async 4 6990 NULL
115692 +tpl_write_6998 tpl_write 3 6998 NULL
115693 +r871x_set_wpa_ie_7000 r871x_set_wpa_ie 3 7000 NULL
115694 +cipso_v4_gentag_enum_7006 cipso_v4_gentag_enum 0 7006 NULL
115695 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
115696 +ld_usb_write_7022 ld_usb_write 3 7022 NULL
115697 +wimax_msg_7030 wimax_msg 4 7030 NULL
115698 +ceph_kvmalloc_7033 ceph_kvmalloc 1 7033 NULL
115699 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
115700 +snd_pcm_oss_bytes_7051 snd_pcm_oss_bytes 2 7051 NULL
115701 +nouveau_device_create__7063 nouveau_device_create_ 7 7063 NULL
115702 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
115703 +event_enable_read_7074 event_enable_read 3 7074 NULL
115704 +tipc_send_packet_7091 tipc_send_packet 4 7091 NULL nohasharray
115705 +beacon_interval_read_7091 beacon_interval_read 3 7091 &tipc_send_packet_7091
115706 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
115707 +osc_resend_count_seq_write_7120 osc_resend_count_seq_write 3 7120 NULL
115708 +qib_format_hwerrors_7133 qib_format_hwerrors 5 7133 NULL
115709 +kvm_mmu_notifier_test_young_7139 kvm_mmu_notifier_test_young 3 7139 NULL
115710 +qlcnic_enable_msix_7144 qlcnic_enable_msix 2 7144 NULL
115711 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
115712 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL
115713 +security_inode_need_killpriv_7322 security_inode_need_killpriv 0 7322 NULL
115714 +pci_vpd_info_field_size_7324 pci_vpd_info_field_size 0 7324 NULL
115715 +mgmt_control_7349 mgmt_control 3 7349 NULL
115716 +at_est2timeout_7365 at_est2timeout 0-1 7365 NULL
115717 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
115718 +ath10k_read_fw_stats_7387 ath10k_read_fw_stats 3 7387 NULL
115719 +hweight_long_7388 hweight_long 0 7388 NULL
115720 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
115721 +_ore_add_stripe_unit_7399 _ore_add_stripe_unit 6-3 7399 NULL
115722 +audmux_read_file_7400 audmux_read_file 3 7400 NULL
115723 +readb_7401 readb 0 7401 NULL
115724 +tipc_recvmsg_7402 tipc_recvmsg 4 7402 NULL
115725 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
115726 +__copy_to_user_nocheck_7443 __copy_to_user_nocheck 0-3 7443 NULL
115727 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
115728 +SYSC_setgroups_7454 SYSC_setgroups 1 7454 NULL
115729 +rt2x00debug_read_queue_stats_7455 rt2x00debug_read_queue_stats 3 7455 NULL
115730 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
115731 +garp_request_join_7471 garp_request_join 4 7471 NULL
115732 +snd_pcm_lib_read1_7491 snd_pcm_lib_read1 0-3 7491 NULL
115733 +ahash_instance_headroom_7509 ahash_instance_headroom 0 7509 NULL nohasharray
115734 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 &ahash_instance_headroom_7509
115735 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
115736 +sk_convert_filter_7541 sk_convert_filter 2 7541 NULL
115737 +ath10k_read_htt_stats_mask_7557 ath10k_read_htt_stats_mask 3 7557 NULL
115738 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
115739 +netvsc_get_slots_7565 netvsc_get_slots 0 7565 NULL
115740 +cfs_cpt_num_estimate_7571 cfs_cpt_num_estimate 0 7571 NULL
115741 +groups_alloc_7614 groups_alloc 1 7614 NULL nohasharray
115742 +create_dir_7614 create_dir 0 7614 &groups_alloc_7614
115743 +_rtw_zmalloc_7636 _rtw_zmalloc 1 7636 NULL
115744 +fault_inject_write_7662 fault_inject_write 3 7662 NULL
115745 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 NULL
115746 +acpi_ns_get_pathname_length_7699 acpi_ns_get_pathname_length 0 7699 NULL
115747 +dev_write_7708 dev_write 3 7708 NULL
115748 +pci_raw_set_power_state_7729 pci_raw_set_power_state 0 7729 NULL
115749 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
115750 +ubi_io_read_vid_hdr_7766 ubi_io_read_vid_hdr 0 7766 NULL
115751 +iwl_dbgfs_bt_cmd_read_7770 iwl_dbgfs_bt_cmd_read 3 7770 NULL
115752 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
115753 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
115754 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
115755 +lustre_packed_msg_size_7792 lustre_packed_msg_size 0 7792 NULL nohasharray
115756 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 &lustre_packed_msg_size_7792
115757 +cfs_trace_dump_debug_buffer_usrstr_7861 cfs_trace_dump_debug_buffer_usrstr 2 7861 NULL
115758 +tipc_alloc_entry_7875 tipc_alloc_entry 2 7875 NULL
115759 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
115760 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
115761 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
115762 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
115763 +integrity_digsig_verify_7956 integrity_digsig_verify 3-0 7956 NULL
115764 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
115765 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
115766 +vcs_read_8017 vcs_read 3 8017 NULL
115767 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
115768 +ms_read_multiple_pages_8052 ms_read_multiple_pages 5-4 8052 NULL
115769 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
115770 +spi_write_then_read_8073 spi_write_then_read 5-3 8073 NULL
115771 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 NULL
115772 +venus_lookup_8121 venus_lookup 4 8121 NULL
115773 +ieee80211_if_fmt_num_buffered_multicast_8127 ieee80211_if_fmt_num_buffered_multicast 3 8127 NULL
115774 +__sk_mem_schedule_8185 __sk_mem_schedule 2 8185 NULL
115775 +ieee80211_if_fmt_dot11MeshHoldingTimeout_8187 ieee80211_if_fmt_dot11MeshHoldingTimeout 3 8187 NULL
115776 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
115777 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
115778 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
115779 +play_iframe_8219 play_iframe 3 8219 NULL
115780 +kvm_mmu_page_set_gfn_8225 kvm_mmu_page_set_gfn 2 8225 NULL
115781 +sctp_ssnmap_size_8228 sctp_ssnmap_size 0-1-2 8228 NULL
115782 +check_xattr_ref_inode_8244 check_xattr_ref_inode 0 8244 NULL
115783 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
115784 +init_cdev_8274 init_cdev 1 8274 NULL
115785 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
115786 +qib_decode_7220_err_8315 qib_decode_7220_err 3 8315 NULL
115787 +snd_pcm_update_state_8320 snd_pcm_update_state 0 8320 NULL
115788 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
115789 +rtw_cfg80211_rx_action_8329 rtw_cfg80211_rx_action 3 8329 NULL
115790 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
115791 +ieee80211_if_fmt_ht_opmode_8347 ieee80211_if_fmt_ht_opmode 3 8347 NULL
115792 +generic_write_sync_8358 generic_write_sync 0 8358 NULL
115793 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
115794 +ath6kl_lrssi_roam_write_8362 ath6kl_lrssi_roam_write 3 8362 NULL
115795 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
115796 +zd_rf_scnprint_id_8406 zd_rf_scnprint_id 0-3 8406 NULL
115797 +smk_write_change_rule_8411 smk_write_change_rule 3 8411 NULL nohasharray
115798 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 &smk_write_change_rule_8411
115799 +roccat_common2_sysfs_read_8431 roccat_common2_sysfs_read 6 8431 NULL
115800 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
115801 +fore200e_chunk_alloc_8501 fore200e_chunk_alloc 4-3 8501 NULL
115802 +batadv_tt_len_8502 batadv_tt_len 0-1 8502 NULL
115803 +dev_config_8506 dev_config 3 8506 NULL
115804 +ACL_to_cifs_posix_8509 ACL_to_cifs_posix 3 8509 NULL
115805 +opticon_process_data_packet_8524 opticon_process_data_packet 3 8524 NULL
115806 +user_on_off_8552 user_on_off 2 8552 NULL
115807 +profile_remove_8556 profile_remove 3 8556 NULL
115808 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL nohasharray
115809 +pci_msi_check_device_8570 pci_msi_check_device 0 8570 &cache_slow_downcall_8570
115810 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
115811 +tower_write_8580 tower_write 3 8580 NULL
115812 +cfs_cpt_number_8618 cfs_cpt_number 0 8618 NULL
115813 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
115814 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
115815 +scsi_dma_map_8632 scsi_dma_map 0 8632 NULL
115816 +fuse_send_write_pages_8636 fuse_send_write_pages 0-5 8636 NULL
115817 +mlx5_vzalloc_8663 mlx5_vzalloc 1 8663 NULL
115818 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
115819 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
115820 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
115821 +skb_frag_size_8695 skb_frag_size 0 8695 NULL
115822 +arcfb_write_8702 arcfb_write 3 8702 NULL
115823 +i_size_read_8703 i_size_read 0 8703 NULL nohasharray
115824 +init_header_8703 init_header 0 8703 &i_size_read_8703
115825 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
115826 +tracing_max_lat_write_8728 tracing_max_lat_write 3 8728 NULL
115827 +jffs2_acl_count_8729 jffs2_acl_count 0-1 8729 NULL
115828 +__create_irqs_8733 __create_irqs 2 8733 NULL
115829 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
115830 +compound_order_8750 compound_order 0 8750 NULL
115831 +yurex_write_8761 yurex_write 3 8761 NULL
115832 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
115833 +kstrtoint_from_user_8778 kstrtoint_from_user 2 8778 NULL
115834 +paging32_prefetch_gpte_8783 paging32_prefetch_gpte 4 8783 NULL
115835 +ext4_try_to_write_inline_data_8785 ext4_try_to_write_inline_data 3-4 8785 NULL
115836 +__bitmap_weight_8796 __bitmap_weight 0 8796 NULL
115837 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
115838 +SyS_llistxattr_8824 SyS_llistxattr 3 8824 NULL
115839 +extent_read_full_page_8826 extent_read_full_page 0 8826 NULL
115840 +ll_xattr_cache_get_8829 ll_xattr_cache_get 0 8829 NULL
115841 +get_queue_depth_8833 get_queue_depth 0 8833 NULL
115842 +dvb_ringbuffer_pkt_next_8834 dvb_ringbuffer_pkt_next 0-2 8834 NULL
115843 +usb_ep_queue_8839 usb_ep_queue 0 8839 NULL
115844 +iwl_rx_packet_len_8854 iwl_rx_packet_len 0 8854 NULL
115845 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
115846 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
115847 +radeon_drm_ioctl_8875 radeon_drm_ioctl 2 8875 NULL
115848 +compressed_bio_size_8887 compressed_bio_size 0-2 8887 NULL
115849 +ab3100_get_set_reg_8890 ab3100_get_set_reg 3 8890 NULL nohasharray
115850 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 &ab3100_get_set_reg_8890
115851 +sdio_max_byte_size_8907 sdio_max_byte_size 0 8907 NULL
115852 +sysfs_merge_group_8917 sysfs_merge_group 0 8917 NULL
115853 +write_file_ani_8918 write_file_ani 3 8918 NULL
115854 +layout_commit_8926 layout_commit 3 8926 NULL
115855 +cp2112_hid_get_8933 cp2112_hid_get 4 8933 NULL
115856 +adjust_priv_size_8935 adjust_priv_size 0-1 8935 NULL
115857 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
115858 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
115859 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
115860 +qib_qsfp_dump_8966 qib_qsfp_dump 0-3 8966 NULL
115861 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
115862 +seq_open_net_8968 seq_open_net 4 8968 NULL nohasharray
115863 +vol_cdev_read_8968 vol_cdev_read 3 8968 &seq_open_net_8968
115864 +bio_integrity_get_tag_8974 bio_integrity_get_tag 3 8974 NULL
115865 +sony_register_touchpad_8981 sony_register_touchpad 2 8981 NULL
115866 +jbd2_journal_blocks_per_page_9004 jbd2_journal_blocks_per_page 0 9004 NULL
115867 +il_dbgfs_clear_ucode_stats_write_9016 il_dbgfs_clear_ucode_stats_write 3 9016 NULL
115868 +snd_emu10k1_ptr_read_9026 snd_emu10k1_ptr_read 0-2 9026 NULL
115869 +nla_put_9042 nla_put 3 9042 NULL
115870 +sta_tx_latency_stat_header_9050 sta_tx_latency_stat_header 0-3-4 9050 NULL
115871 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
115872 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
115873 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
115874 +create_queues_9088 create_queues 2-3 9088 NULL
115875 +ftdi_prepare_write_buffer_9093 ftdi_prepare_write_buffer 3 9093 NULL
115876 +adxl34x_spi_read_block_9108 adxl34x_spi_read_block 3 9108 NULL
115877 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 NULL nohasharray
115878 +gfn_to_rmap_9110 gfn_to_rmap 2-3 9110 &caif_stream_sendmsg_9110
115879 +udf_direct_IO_9111 udf_direct_IO 4 9111 NULL
115880 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
115881 +vb2_dma_sg_alloc_9157 vb2_dma_sg_alloc 2 9157 NULL
115882 +dbg_command_buf_9165 dbg_command_buf 2 9165 NULL
115883 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
115884 +count_leading_zeros_9183 count_leading_zeros 0 9183 NULL
115885 +altera_swap_ir_9194 altera_swap_ir 2 9194 NULL
115886 +snd_m3_get_pointer_9206 snd_m3_get_pointer 0 9206 NULL
115887 +iwl_dbgfs_frame_stats_read_9211 iwl_dbgfs_frame_stats_read 3 9211 NULL
115888 +virtqueue_add_9217 virtqueue_add 4-5 9217 NULL
115889 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
115890 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
115891 +hfsplus_bnode_read_u16_9262 hfsplus_bnode_read_u16 0 9262 NULL
115892 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
115893 +flakey_status_9274 flakey_status 5 9274 NULL
115894 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
115895 +ceph_sync_setxattr_9310 ceph_sync_setxattr 4 9310 NULL
115896 +ieee80211_if_fmt_txpower_9334 ieee80211_if_fmt_txpower 3 9334 NULL
115897 +nvme_trans_fmt_get_parm_header_9340 nvme_trans_fmt_get_parm_header 2 9340 NULL
115898 +ocfs2_orphan_for_truncate_9342 ocfs2_orphan_for_truncate 4 9342 NULL
115899 +ll_direct_rw_pages_9361 ll_direct_rw_pages 0 9361 NULL
115900 +sta_beacon_loss_count_read_9370 sta_beacon_loss_count_read 3 9370 NULL
115901 +virtqueue_add_outbuf_9395 virtqueue_add_outbuf 3 9395 NULL
115902 +read_9397 read 3 9397 NULL
115903 +hash_ipportip4_expire_9415 hash_ipportip4_expire 4 9415 NULL
115904 +btrfs_drop_extents_9423 btrfs_drop_extents 4 9423 NULL
115905 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
115906 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
115907 +ieee80211_if_fmt_fwded_unicast_9454 ieee80211_if_fmt_fwded_unicast 3 9454 NULL
115908 +get_registers_9470 get_registers 4 9470 NULL nohasharray
115909 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 &get_registers_9470
115910 +crypt_status_9492 crypt_status 5 9492 NULL
115911 +lbs_threshold_write_9502 lbs_threshold_write 5 9502 NULL
115912 +lp_write_9511 lp_write 3 9511 NULL
115913 +mext_calc_swap_extents_9517 mext_calc_swap_extents 4 9517 NULL
115914 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
115915 +ll_max_read_ahead_whole_mb_seq_write_9528 ll_max_read_ahead_whole_mb_seq_write 3 9528 NULL
115916 +read_file_dma_9530 read_file_dma 3 9530 NULL
115917 +iwl_dbgfs_bf_params_read_9542 iwl_dbgfs_bf_params_read 3 9542 NULL
115918 +il_dbgfs_missed_beacon_write_9546 il_dbgfs_missed_beacon_write 3 9546 NULL
115919 +compat_SyS_pwritev64_9548 compat_SyS_pwritev64 3 9548 NULL
115920 +fw_node_create_9559 fw_node_create 2 9559 NULL
115921 +kobj_map_9566 kobj_map 2-3 9566 NULL
115922 +f2fs_read_data_pages_9574 f2fs_read_data_pages 4 9574 NULL
115923 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5-6 9605 NULL
115924 +lov_ost_pool_add_9626 lov_ost_pool_add 3 9626 NULL
115925 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
115926 +ceph_copy_user_to_page_vector_9635 ceph_copy_user_to_page_vector 4-3 9635 NULL
115927 +acpi_ex_insert_into_field_9638 acpi_ex_insert_into_field 3 9638 NULL
115928 +ll_checksum_seq_write_9648 ll_checksum_seq_write 3 9648 NULL
115929 +ocfs2_xattr_get_rec_9652 ocfs2_xattr_get_rec 0 9652 NULL
115930 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
115931 +tipc_port_mcast_xmit_9663 tipc_port_mcast_xmit 4 9663 NULL
115932 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
115933 +dns_query_9676 dns_query 3 9676 NULL
115934 +qib_7322_handle_hwerrors_9678 qib_7322_handle_hwerrors 3 9678 NULL
115935 +__erst_read_from_storage_9690 __erst_read_from_storage 0 9690 NULL
115936 +vx_transfer_end_9701 vx_transfer_end 0 9701 NULL
115937 +fuse_iter_npages_9705 fuse_iter_npages 0 9705 NULL nohasharray
115938 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 &fuse_iter_npages_9705
115939 +cfg80211_tx_mlme_mgmt_9715 cfg80211_tx_mlme_mgmt 3 9715 NULL
115940 +parse_uac2_sample_rate_range_9718 parse_uac2_sample_rate_range 0 9718 NULL
115941 +btrfs_stack_file_extent_num_bytes_9720 btrfs_stack_file_extent_num_bytes 0 9720 NULL
115942 +SYSC_ppoll_9721 SYSC_ppoll 2 9721 NULL
115943 +nla_get_u8_9736 nla_get_u8 0 9736 NULL
115944 +ieee80211_if_fmt_num_mcast_sta_9738 ieee80211_if_fmt_num_mcast_sta 3 9738 NULL
115945 +ddb_input_read_9743 ddb_input_read 3-0 9743 NULL
115946 +regmap_multi_reg_write_bypassed_9751 regmap_multi_reg_write_bypassed 3 9751 NULL nohasharray
115947 +sta_last_ack_signal_read_9751 sta_last_ack_signal_read 3 9751 &regmap_multi_reg_write_bypassed_9751
115948 +btrfs_super_root_9763 btrfs_super_root 0 9763 NULL
115949 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
115950 +kvm_age_hva_9795 kvm_age_hva 2 9795 NULL
115951 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 NULL nohasharray
115952 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 &udpv6_recvmsg_9813
115953 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
115954 +btrfs_free_reserved_extent_9867 btrfs_free_reserved_extent 2 9867 NULL
115955 +wil_read_file_ioblob_9878 wil_read_file_ioblob 3 9878 NULL
115956 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 NULL nohasharray
115957 +bm_register_write_9893 bm_register_write 3 9893 &snd_midi_event_new_9893
115958 +snd_gf1_pcm_playback_copy_9895 snd_gf1_pcm_playback_copy 3-5 9895 NULL
115959 +nonpaging_page_fault_9908 nonpaging_page_fault 2 9908 NULL
115960 +iwl_dbgfs_prph_reg_read_9928 iwl_dbgfs_prph_reg_read 3 9928 NULL
115961 +root_nfs_parse_options_9937 root_nfs_parse_options 3 9937 NULL
115962 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
115963 +read_file_misc_9948 read_file_misc 3 9948 NULL
115964 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
115965 +SyS_gethostname_9964 SyS_gethostname 2 9964 NULL
115966 +get_free_serial_index_9969 get_free_serial_index 0 9969 NULL
115967 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
115968 +SYSC_move_pages_9986 SYSC_move_pages 2 9986 NULL
115969 +aat2870_dump_reg_10019 aat2870_dump_reg 0 10019 NULL
115970 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
115971 +get_elem_size_10110 get_elem_size 0-2 10110 NULL nohasharray
115972 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 &get_elem_size_10110
115973 +gfs2_meta_read_10112 gfs2_meta_read 0 10112 NULL
115974 +SyS_migrate_pages_10134 SyS_migrate_pages 2 10134 NULL
115975 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
115976 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL
115977 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
115978 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
115979 +kstrtol_from_user_10168 kstrtol_from_user 2 10168 NULL
115980 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
115981 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
115982 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
115983 +__qlcnic_pci_sriov_enable_10281 __qlcnic_pci_sriov_enable 2 10281 NULL
115984 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
115985 +ubi_leb_change_10289 ubi_leb_change 0 10289 NULL
115986 +read_emulate_10310 read_emulate 2-4 10310 NULL
115987 +read_file_spectral_count_10320 read_file_spectral_count 3 10320 NULL
115988 +compat_SyS_writev_10327 compat_SyS_writev 3 10327 NULL
115989 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
115990 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
115991 +dbAllocAny_10354 dbAllocAny 0 10354 NULL
115992 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
115993 +ms_write_multiple_pages_10362 ms_write_multiple_pages 6-5 10362 NULL
115994 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
115995 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
115996 +led_classdev_register_10384 led_classdev_register 0 10384 NULL
115997 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
115998 +fwtty_rx_10434 fwtty_rx 3 10434 NULL
115999 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
116000 +hash_ipportip6_expire_10478 hash_ipportip6_expire 4 10478 NULL
116001 +nouveau_pwr_create__10483 nouveau_pwr_create_ 4 10483 NULL
116002 +ext4_itable_unused_count_10501 ext4_itable_unused_count 0 10501 NULL
116003 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
116004 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
116005 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
116006 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
116007 +qlcnic_pci_sriov_enable_10519 qlcnic_pci_sriov_enable 2 10519 NULL
116008 +snd_pcm_hw_params_user_10520 snd_pcm_hw_params_user 0 10520 NULL
116009 +kstrtouint_from_user_10536 kstrtouint_from_user 2 10536 NULL nohasharray
116010 +snd_pcm_lib_read_10536 snd_pcm_lib_read 0-3 10536 &kstrtouint_from_user_10536
116011 +ext4_write_begin_10576 ext4_write_begin 3-4 10576 NULL
116012 +scrub_remap_extent_10588 scrub_remap_extent 2 10588 NULL
116013 +otp_read_10594 otp_read 2-4-5 10594 NULL
116014 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
116015 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
116016 +fq_alloc_node_10633 fq_alloc_node 1 10633 NULL
116017 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL nohasharray
116018 +ubi_io_write_vid_hdr_10660 ubi_io_write_vid_hdr 0 10660 &nfs_idmap_lookup_id_10660
116019 +efx_max_tx_len_10662 efx_max_tx_len 0-2 10662 NULL
116020 +parport_write_10669 parport_write 0 10669 NULL
116021 +edge_write_10692 edge_write 4 10692 NULL
116022 +ubi_wl_get_peb_10699 ubi_wl_get_peb 0 10699 NULL
116023 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL nohasharray
116024 +inl_10708 inl 0 10708 &selinux_inode_setxattr_10708
116025 +shash_async_setkey_10720 shash_async_setkey 3 10720 NULL nohasharray
116026 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 &shash_async_setkey_10720
116027 +spi_sync_10731 spi_sync 0 10731 NULL
116028 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL nohasharray
116029 +apu_get_register_10737 apu_get_register 0 10737 &sctp_getsockopt_maxseg_10737
116030 +SyS_io_getevents_10756 SyS_io_getevents 3 10756 NULL
116031 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
116032 +rd_build_prot_space_10761 rd_build_prot_space 2-3 10761 NULL
116033 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
116034 +__qp_memcpy_to_queue_10779 __qp_memcpy_to_queue 2-4 10779 NULL
116035 +diva_set_trace_filter_10820 diva_set_trace_filter 0-1 10820 NULL
116036 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
116037 +ida_get_new_above_10853 ida_get_new_above 0 10853 NULL
116038 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
116039 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
116040 +wiidebug_drm_write_10879 wiidebug_drm_write 3 10879 NULL
116041 +get_scq_10897 get_scq 2 10897 NULL
116042 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
116043 +lprocfs_wr_atomic_10912 lprocfs_wr_atomic 3 10912 NULL
116044 +__copy_from_user_10918 __copy_from_user 0-3 10918 NULL
116045 +kobject_add_10919 kobject_add 0 10919 NULL
116046 +ar9003_dump_modal_eeprom_10959 ar9003_dump_modal_eeprom 3-2-0 10959 NULL
116047 +ci_port_test_write_10962 ci_port_test_write 3 10962 NULL
116048 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
116049 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
116050 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
116051 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
116052 +SetLineNumber_11023 SetLineNumber 0 11023 NULL
116053 +pci_msi_vec_count_11046 pci_msi_vec_count 0 11046 NULL
116054 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
116055 +qlcnic_83xx_calculate_msix_vector_11063 qlcnic_83xx_calculate_msix_vector 0 11063 NULL nohasharray
116056 +insert_inline_extent_backref_11063 insert_inline_extent_backref 8 11063 &qlcnic_83xx_calculate_msix_vector_11063
116057 +tcp_send_mss_11079 tcp_send_mss 0 11079 NULL
116058 +snd_pcm_delay_11081 snd_pcm_delay 0 11081 NULL
116059 +count_argc_11083 count_argc 0 11083 NULL
116060 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
116061 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
116062 +page_offset_11120 page_offset 0 11120 NULL
116063 +cea_db_payload_len_11124 cea_db_payload_len 0 11124 NULL nohasharray
116064 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 &cea_db_payload_len_11124
116065 +alloc_alien_cache_11127 alloc_alien_cache 2 11127 NULL
116066 +snd_gf1_pcm_playback_silence_11172 snd_gf1_pcm_playback_silence 3-4 11172 NULL
116067 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
116068 +comedi_alloc_spriv_11234 comedi_alloc_spriv 2 11234 NULL
116069 +of_irq_count_11253 of_irq_count 0 11253 NULL
116070 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
116071 +ath6kl_power_params_write_11274 ath6kl_power_params_write 3 11274 NULL
116072 +__proc_daemon_file_11305 __proc_daemon_file 5 11305 NULL
116073 +ext4_xattr_check_names_11314 ext4_xattr_check_names 0 11314 NULL
116074 +bcache_dev_sectors_dirty_add_11315 bcache_dev_sectors_dirty_add 3-4 11315 NULL
116075 +sk_filter_size_11316 sk_filter_size 0 11316 NULL nohasharray
116076 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 &sk_filter_size_11316
116077 +construct_key_11329 construct_key 3 11329 NULL nohasharray
116078 +__kfifo_out_peek_11329 __kfifo_out_peek 0-3 11329 &construct_key_11329
116079 +next_segment_11330 next_segment 0-2-1 11330 NULL
116080 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
116081 +ext4_get_inline_size_11349 ext4_get_inline_size 0 11349 NULL
116082 +sel_write_create_11353 sel_write_create 3 11353 NULL nohasharray
116083 +nl80211_send_mgmt_11353 nl80211_send_mgmt 7 11353 &sel_write_create_11353
116084 +of_get_available_child_count_11361 of_get_available_child_count 0 11361 NULL
116085 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
116086 +tcf_register_action_11381 tcf_register_action 2 11381 NULL nohasharray
116087 +nft_value_dump_11381 nft_value_dump 3 11381 &tcf_register_action_11381
116088 +isku_sysfs_read_keys_capslock_11392 isku_sysfs_read_keys_capslock 6 11392 NULL
116089 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
116090 +lprocfs_wr_evict_client_11402 lprocfs_wr_evict_client 3 11402 NULL
116091 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
116092 +str_to_user_11411 str_to_user 2 11411 NULL
116093 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
116094 +ath6kl_wmi_test_rx_11414 ath6kl_wmi_test_rx 3 11414 NULL
116095 +adis16480_show_firmware_revision_11417 adis16480_show_firmware_revision 3 11417 NULL
116096 +trace_options_read_11419 trace_options_read 3 11419 NULL
116097 +i40e_dbg_command_write_11421 i40e_dbg_command_write 3 11421 NULL
116098 +xd_read_multiple_pages_11422 xd_read_multiple_pages 5-4 11422 NULL
116099 +bttv_read_11432 bttv_read 3 11432 NULL
116100 +create_zero_mask_11453 create_zero_mask 0-1 11453 NULL
116101 +do_blockdev_direct_IO_11455 do_blockdev_direct_IO 0-6 11455 NULL
116102 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 NULL nohasharray
116103 +pci_set_power_state_11479 pci_set_power_state 0 11479 &sca3000_read_first_n_hw_rb_11479
116104 +xfs_file_buffered_aio_write_11492 xfs_file_buffered_aio_write 4 11492 NULL
116105 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
116106 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
116107 +ll_direct_IO_26_seg_11518 ll_direct_IO_26_seg 0 11518 NULL
116108 +twl_direction_in_11527 twl_direction_in 2 11527 NULL
116109 +skb_cow_data_11565 skb_cow_data 0 11565 NULL
116110 +lpfc_idiag_ctlacc_write_11576 lpfc_idiag_ctlacc_write 3 11576 NULL
116111 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
116112 +batadv_iv_ogm_orig_add_if_11586 batadv_iv_ogm_orig_add_if 2 11586 NULL
116113 +snd_pcm_action_11589 snd_pcm_action 0 11589 NULL
116114 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
116115 +batadv_iv_ogm_orig_del_if_11604 batadv_iv_ogm_orig_del_if 2 11604 NULL
116116 +SYSC_mq_timedsend_11607 SYSC_mq_timedsend 3 11607 NULL
116117 +C_SYSC_migrate_pages_11618 C_SYSC_migrate_pages 2 11618 NULL
116118 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
116119 +nla_total_size_11658 nla_total_size 1-0 11658 NULL
116120 +slab_ksize_11664 slab_ksize 0 11664 NULL
116121 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
116122 +compat_SyS_msgsnd_11675 compat_SyS_msgsnd 3 11675 NULL
116123 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
116124 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
116125 +split_11691 split 2 11691 NULL
116126 +compat_SyS_keyctl_11695 compat_SyS_keyctl 4 11695 NULL nohasharray
116127 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 &compat_SyS_keyctl_11695
116128 +blk_rq_cur_bytes_11723 blk_rq_cur_bytes 0 11723 NULL
116129 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
116130 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
116131 +ieee80211_get_num_supported_channels_11768 ieee80211_get_num_supported_channels 0 11768 NULL
116132 +tipc_sendmsg_11769 tipc_sendmsg 4 11769 NULL
116133 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
116134 +btrfs_key_blockptr_11786 btrfs_key_blockptr 0 11786 NULL
116135 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
116136 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
116137 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
116138 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
116139 +unix_stream_connect_11844 unix_stream_connect 3 11844 NULL
116140 +pci_enable_msix_range_11852 pci_enable_msix_range 0-4 11852 NULL
116141 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
116142 +ieee80211_rx_bss_info_11887 ieee80211_rx_bss_info 3 11887 NULL
116143 +mdc_rename_11899 mdc_rename 4-6 11899 NULL
116144 +xstateregs_get_11906 xstateregs_get 4 11906 NULL
116145 +ti_write_11916 ti_write 4 11916 NULL
116146 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
116147 +atomic_sub_return_11939 atomic_sub_return 0-1 11939 NULL
116148 +r1_sync_page_io_11963 r1_sync_page_io 3 11963 NULL
116149 +read_and_add_raw_conns_11987 read_and_add_raw_conns 0 11987 NULL
116150 +ftdi_elan_total_command_size_12045 ftdi_elan_total_command_size 0 12045 NULL
116151 +ieee80211_if_read_user_power_level_12050 ieee80211_if_read_user_power_level 3 12050 NULL
116152 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
116153 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
116154 +batadv_tt_global_size_mod_12085 batadv_tt_global_size_mod 3 12085 NULL
116155 +rtw_malloc2d_12102 rtw_malloc2d 1-2-3 12102 NULL
116156 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
116157 +set_powered_12129 set_powered 4 12129 NULL
116158 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
116159 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
116160 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
116161 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
116162 +get_idx_gc_leb_12148 get_idx_gc_leb 0 12148 NULL
116163 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
116164 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
116165 +fnic_reset_stats_write_12177 fnic_reset_stats_write 3 12177 NULL
116166 +LNetEQAlloc_12178 LNetEQAlloc 1 12178 NULL
116167 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
116168 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
116169 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
116170 +snd_pcm_kernel_ioctl_12219 snd_pcm_kernel_ioctl 0 12219 NULL
116171 +fuse_get_req_12221 fuse_get_req 2 12221 NULL nohasharray
116172 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 &fuse_get_req_12221
116173 +__alloc_bootmem_low_nopanic_12235 __alloc_bootmem_low_nopanic 1 12235 NULL
116174 +usnic_ib_qp_grp_dump_rows_12239 usnic_ib_qp_grp_dump_rows 3 12239 NULL
116175 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
116176 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
116177 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
116178 +SYSC_vm86_12279 SYSC_vm86 2 12279 NULL
116179 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
116180 +roundup_to_multiple_of_64_12288 roundup_to_multiple_of_64 0-1 12288 NULL nohasharray
116181 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 &roundup_to_multiple_of_64_12288
116182 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
116183 +usnic_transport_sock_to_str_12322 usnic_transport_sock_to_str 2-0 12322 NULL
116184 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
116185 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
116186 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
116187 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
116188 +write_file_dump_12391 write_file_dump 3 12391 NULL nohasharray
116189 +populate_dir_12391 populate_dir 0 12391 &write_file_dump_12391
116190 +hbucket_elem_add_12416 hbucket_elem_add 3 12416 NULL
116191 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
116192 +cfs_array_alloc_12441 cfs_array_alloc 2 12441 NULL
116193 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
116194 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
116195 +fnic_trace_ctrl_read_12497 fnic_trace_ctrl_read 3 12497 NULL
116196 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
116197 +write_inode_now_12565 write_inode_now 0 12565 NULL
116198 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
116199 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
116200 +_iwl_dbgfs_prph_reg_write_12597 _iwl_dbgfs_prph_reg_write 3 12597 NULL
116201 +tlbflush_write_file_12598 tlbflush_write_file 3 12598 NULL
116202 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
116203 +sdhci_pltfm_init_12627 sdhci_pltfm_init 3 12627 NULL
116204 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
116205 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
116206 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
116207 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
116208 +rtw_android_get_link_speed_12655 rtw_android_get_link_speed 0 12655 NULL
116209 +ocfs2_read_block_12659 ocfs2_read_block 0 12659 NULL
116210 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
116211 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
116212 +ext4_writepage_trans_blocks_12674 ext4_writepage_trans_blocks 0 12674 NULL
116213 +iwl_dbgfs_calib_disabled_write_12707 iwl_dbgfs_calib_disabled_write 3 12707 NULL
116214 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
116215 +ivtv_write_12721 ivtv_write 3 12721 NULL
116216 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
116217 +__mei_cl_async_send_12737 __mei_cl_async_send 3 12737 NULL
116218 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
116219 +listxattr_12769 listxattr 3 12769 NULL
116220 +sctp_ssnmap_init_12772 sctp_ssnmap_init 3-2 12772 NULL
116221 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
116222 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
116223 +SyS_add_key_12834 SyS_add_key 4 12834 NULL
116224 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
116225 +spidev_sync_12842 spidev_sync 0 12842 NULL
116226 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
116227 +ath9k_dump_4k_modal_eeprom_12883 ath9k_dump_4k_modal_eeprom 3-2 12883 NULL
116228 +get_leb_cnt_12892 get_leb_cnt 0-2 12892 NULL
116229 +get_virtual_node_size_12908 get_virtual_node_size 0 12908 NULL
116230 +rds_pages_in_vec_12922 rds_pages_in_vec 0 12922 NULL
116231 +do_inode_permission_12946 do_inode_permission 0 12946 NULL
116232 +bm_status_write_12964 bm_status_write 3 12964 NULL
116233 +raid56_parity_recover_12987 raid56_parity_recover 5 12987 NULL
116234 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
116235 +sk_peek_offset_12991 sk_peek_offset 0 12991 NULL
116236 +__btrfs_direct_write_13007 __btrfs_direct_write 4-0 13007 NULL
116237 +bset_prev_bytes_13020 bset_prev_bytes 0 13020 NULL
116238 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
116239 +generic_segment_checks_13041 generic_segment_checks 0 13041 NULL
116240 +ocfs2_write_begin_13045 ocfs2_write_begin 3-4 13045 NULL
116241 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL nohasharray
116242 +ptlrpc_lprocfs_threads_min_seq_write_13060 ptlrpc_lprocfs_threads_min_seq_write 3 13060 &__dn_setsockopt_13060
116243 +biovec_create_pool_13079 biovec_create_pool 2 13079 NULL
116244 +xattr_getsecurity_13090 xattr_getsecurity 0 13090 NULL
116245 +ttm_dma_pool_alloc_new_pages_13105 ttm_dma_pool_alloc_new_pages 3 13105 NULL
116246 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
116247 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
116248 +blk_update_request_13146 blk_update_request 3 13146 NULL
116249 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
116250 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
116251 +ucs2_strlen_13178 ucs2_strlen 0 13178 NULL
116252 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
116253 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
116254 +comedi_read_13199 comedi_read 3 13199 NULL
116255 +hash_ipport4_expire_13201 hash_ipport4_expire 4 13201 NULL
116256 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
116257 +svm_msrpm_offset_13220 svm_msrpm_offset 0-1 13220 NULL
116258 +fnic_trace_ctrl_write_13229 fnic_trace_ctrl_write 3 13229 NULL
116259 +_iwl_dbgfs_disable_power_off_write_13243 _iwl_dbgfs_disable_power_off_write 3 13243 NULL
116260 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
116261 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
116262 +bio_integrity_trim_13259 bio_integrity_trim 3-2 13259 NULL
116263 +simple_attr_write_13260 simple_attr_write 3 13260 NULL
116264 +pmcraid_notify_aen_13274 pmcraid_notify_aen 3 13274 NULL
116265 +il4965_stats_flag_13281 il4965_stats_flag 0-3 13281 NULL
116266 +lpfc_idiag_mbxacc_get_setup_13282 lpfc_idiag_mbxacc_get_setup 0 13282 NULL
116267 +sd_major_13294 sd_major 0-1 13294 NULL
116268 +read_file_phy_err_13318 read_file_phy_err 3 13318 NULL
116269 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
116270 +round_event_name_len_13348 round_event_name_len 0 13348 NULL
116271 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
116272 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
116273 +ext4_meta_trans_blocks_13380 ext4_meta_trans_blocks 0-3-2 13380 NULL
116274 +lov_mds_md_size_13388 lov_mds_md_size 0-1 13388 NULL nohasharray
116275 +dis_bypass_write_13388 dis_bypass_write 3 13388 &lov_mds_md_size_13388
116276 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
116277 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL
116278 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 7-8-9 13443 NULL
116279 +sb_init_dio_done_wq_13482 sb_init_dio_done_wq 0 13482 NULL
116280 +data_read_13494 data_read 3 13494 NULL
116281 +core_status_13515 core_status 4 13515 NULL
116282 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
116283 +bm_init_13529 bm_init 2 13529 NULL
116284 +request_any_context_irq_13530 request_any_context_irq 0 13530 NULL
116285 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
116286 +SyS_vm86_13557 SyS_vm86 2 13557 NULL
116287 +ieee80211_if_read_ap_power_level_13558 ieee80211_if_read_ap_power_level 3 13558 NULL
116288 +hash_net4_expire_13559 hash_net4_expire 4 13559 NULL
116289 +ubifs_get_idx_gc_leb_13566 ubifs_get_idx_gc_leb 0 13566 NULL
116290 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
116291 +cache_write_13589 cache_write 3 13589 NULL
116292 +Rd_Indx_13602 Rd_Indx 3-2 13602 NULL
116293 +wm8994_bulk_write_13615 wm8994_bulk_write 2-3 13615 NULL
116294 +pmcraid_get_minor_13619 pmcraid_get_minor 0 13619 NULL
116295 +packet_snd_13634 packet_snd 3 13634 NULL
116296 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
116297 +cache_downcall_13666 cache_downcall 3 13666 NULL
116298 +ext3_xattr_list_entries_13682 ext3_xattr_list_entries 0 13682 NULL
116299 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
116300 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
116301 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
116302 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
116303 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
116304 +random_read_13815 random_read 3 13815 NULL
116305 +mutex_lock_interruptible_nested_13817 mutex_lock_interruptible_nested 0 13817 NULL
116306 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
116307 +___mei_cl_send_13821 ___mei_cl_send 3 13821 NULL
116308 +enc_pools_insert_13849 enc_pools_insert 3 13849 NULL
116309 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
116310 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL
116311 +qp_memcpy_to_queue_13886 qp_memcpy_to_queue 5-2 13886 NULL
116312 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
116313 +cfg80211_inform_bss_width_13933 cfg80211_inform_bss_width 9 13933 NULL
116314 +ext3_xattr_block_get_13936 ext3_xattr_block_get 0 13936 NULL
116315 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL nohasharray
116316 +ocfs2_xa_value_truncate_13940 ocfs2_xa_value_truncate 2 13940 &ieee80211_if_read_dot11MeshForwarding_13940
116317 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
116318 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
116319 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL nohasharray
116320 +pagecache_write_end_13950 pagecache_write_end 0 13950 &lpfc_idiag_queacc_read_13950
116321 +osc_grant_shrink_interval_seq_write_13952 osc_grant_shrink_interval_seq_write 3 13952 NULL
116322 +snd_pcm_plug_slave_size_13967 snd_pcm_plug_slave_size 0-2 13967 NULL
116323 +qcam_read_13977 qcam_read 3 13977 NULL
116324 +dsp_read_13980 dsp_read 2 13980 NULL
116325 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
116326 +sddr09_write_data_14014 sddr09_write_data 3 14014 NULL
116327 +btrfs_get_blocks_direct_14016 btrfs_get_blocks_direct 2 14016 NULL
116328 +dmi_format_ids_14018 dmi_format_ids 2 14018 NULL
116329 +iscsi_create_flashnode_conn_14022 iscsi_create_flashnode_conn 4 14022 NULL
116330 +pci_add_ext_cap_save_buffer_14032 pci_add_ext_cap_save_buffer 3 14032 NULL
116331 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
116332 +read_def_modal_eeprom_14041 read_def_modal_eeprom 3 14041 NULL
116333 +ieee80211_if_fmt_aid_14055 ieee80211_if_fmt_aid 3 14055 NULL
116334 +ovs_nla_alloc_flow_actions_14056 ovs_nla_alloc_flow_actions 1 14056 NULL
116335 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
116336 +lov_stripeoffset_seq_write_14078 lov_stripeoffset_seq_write 3 14078 NULL
116337 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
116338 +ext4_journal_blocks_per_page_14127 ext4_journal_blocks_per_page 0 14127 NULL
116339 +isku_sysfs_read_light_14140 isku_sysfs_read_light 6 14140 NULL
116340 +em_canid_change_14150 em_canid_change 3 14150 NULL
116341 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
116342 +midi_alloc_ep_req_14159 midi_alloc_ep_req 2 14159 NULL
116343 +print_input_mask_14168 print_input_mask 3-0 14168 NULL
116344 +ocfs2_xattr_value_truncate_14183 ocfs2_xattr_value_truncate 3 14183 NULL
116345 +datafab_read_data_14186 datafab_read_data 4 14186 NULL
116346 +hfsplus_brec_find_14200 hfsplus_brec_find 0 14200 NULL
116347 +alloc_async_14208 alloc_async 1 14208 NULL
116348 +ath6kl_regread_write_14220 ath6kl_regread_write 3 14220 NULL
116349 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
116350 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4 14244 NULL
116351 +btrfs_token_file_extent_ram_bytes_14247 btrfs_token_file_extent_ram_bytes 0 14247 NULL
116352 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
116353 +rr_status_14293 rr_status 5 14293 NULL
116354 +read_default_ldt_14302 read_default_ldt 2 14302 NULL
116355 +oo_objects_14319 oo_objects 0 14319 NULL
116356 +ll_get_user_pages_14328 ll_get_user_pages 3-2-0 14328 NULL
116357 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
116358 +alloc_tx_struct_14349 alloc_tx_struct 1 14349 NULL
116359 +hash_ipportnet4_expire_14354 hash_ipportnet4_expire 4 14354 NULL
116360 +snd_pcm_lib_readv_14363 snd_pcm_lib_readv 0-3 14363 NULL
116361 +lowpan_read_14369 lowpan_read 3 14369 NULL
116362 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
116363 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
116364 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
116365 +get_kcore_size_14425 get_kcore_size 0 14425 NULL
116366 +_iwl_dbgfs_sram_write_14439 _iwl_dbgfs_sram_write 3 14439 NULL
116367 +block_size_14443 block_size 0 14443 NULL
116368 +lmv_user_md_size_14456 lmv_user_md_size 0-1 14456 NULL
116369 +snd_emu10k1_proc_spdif_status_14457 snd_emu10k1_proc_spdif_status 4-5 14457 NULL
116370 +ath10k_write_htt_stats_mask_14458 ath10k_write_htt_stats_mask 3 14458 NULL
116371 +lustre_msg_size_v2_14470 lustre_msg_size_v2 0 14470 NULL
116372 +dma_transfer_size_14473 dma_transfer_size 0 14473 NULL
116373 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
116374 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
116375 +split_state_14491 split_state 0 14491 NULL
116376 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
116377 +dataflash_read_user_otp_14536 dataflash_read_user_otp 3-2 14536 NULL nohasharray
116378 +ep0_write_14536 ep0_write 3 14536 &dataflash_read_user_otp_14536
116379 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
116380 +qp_host_alloc_queue_14566 qp_host_alloc_queue 1 14566 NULL
116381 +SyS_setdomainname_14569 SyS_setdomainname 2 14569 NULL
116382 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
116383 +ceph_osdc_alloc_request_14597 ceph_osdc_alloc_request 3 14597 NULL
116384 +dbJoin_14644 dbJoin 0 14644 NULL
116385 +profile_replace_14652 profile_replace 3 14652 NULL
116386 +usnic_vnic_dump_14662 usnic_vnic_dump 3 14662 NULL
116387 +min_bytes_needed_14675 min_bytes_needed 0 14675 NULL
116388 +nvme_trans_log_info_exceptions_14677 nvme_trans_log_info_exceptions 3 14677 NULL
116389 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
116390 +ieee80211_if_fmt_rc_rateidx_mask_2ghz_14683 ieee80211_if_fmt_rc_rateidx_mask_2ghz 3 14683 NULL
116391 +SyS_fsetxattr_14702 SyS_fsetxattr 4 14702 NULL
116392 +persistent_ram_ecc_string_14704 persistent_ram_ecc_string 0 14704 NULL
116393 +u_audio_playback_14709 u_audio_playback 3 14709 NULL
116394 +rtw_cbuf_alloc_14710 rtw_cbuf_alloc 1 14710 NULL
116395 +vfd_write_14717 vfd_write 3 14717 NULL
116396 +__blk_end_request_14729 __blk_end_request 3 14729 NULL
116397 +raid1_resize_14740 raid1_resize 2 14740 NULL
116398 +i915_error_state_buf_init_14742 i915_error_state_buf_init 2 14742 NULL
116399 +btrfs_inode_extref_name_len_14752 btrfs_inode_extref_name_len 0 14752 NULL
116400 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
116401 +regmap_range_read_file_14775 regmap_range_read_file 3 14775 NULL
116402 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
116403 +keys_proc_write_14792 keys_proc_write 3 14792 NULL
116404 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
116405 +__kfifo_in_14797 __kfifo_in 3-0 14797 NULL
116406 +hpet_readl_14801 hpet_readl 0 14801 NULL nohasharray
116407 +snd_als300_gcr_read_14801 snd_als300_gcr_read 0 14801 &hpet_readl_14801
116408 +do_tune_cpucache_14828 do_tune_cpucache 2 14828 NULL
116409 +mrp_attr_create_14853 mrp_attr_create 3 14853 NULL
116410 +lcd_write_14857 lcd_write 3 14857 NULL
116411 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
116412 +gmux_index_read8_14890 gmux_index_read8 0 14890 NULL
116413 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
116414 +SYSC_readv_14901 SYSC_readv 3 14901 NULL
116415 +__arch_hweight64_14923 __arch_hweight64 0 14923 NULL nohasharray
116416 +qp_memcpy_to_queue_iov_14923 qp_memcpy_to_queue_iov 5-2 14923 &__arch_hweight64_14923
116417 +ocfs2_expand_nonsparse_inode_14936 ocfs2_expand_nonsparse_inode 3-4 14936 NULL
116418 +queue_cnt_14951 queue_cnt 0 14951 NULL
116419 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
116420 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
116421 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
116422 +setkey_14987 setkey 3 14987 NULL nohasharray
116423 +gpio_twl4030_write_14987 gpio_twl4030_write 1 14987 &setkey_14987
116424 +blk_integrity_tuple_size_15027 blk_integrity_tuple_size 0 15027 NULL
116425 +read_file_node_aggr_15040 read_file_node_aggr 3 15040 NULL
116426 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
116427 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
116428 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
116429 +ntfs_copy_from_user_15072 ntfs_copy_from_user 0-5-3 15072 NULL
116430 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
116431 +smscore_load_firmware_family2_15086 smscore_load_firmware_family2 3 15086 NULL
116432 +btrfs_readpage_15094 btrfs_readpage 0 15094 NULL
116433 +compat_SyS_pwritev_15118 compat_SyS_pwritev 3 15118 NULL
116434 +hex_dump_to_buffer_15121 hex_dump_to_buffer 6 15121 NULL
116435 +start_port_15124 start_port 0 15124 NULL
116436 +ipwireless_ppp_mru_15153 ipwireless_ppp_mru 0 15153 NULL
116437 +self_check_not_bad_15175 self_check_not_bad 0 15175 NULL
116438 +SYSC_setdomainname_15180 SYSC_setdomainname 2 15180 NULL
116439 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
116440 +mtt_alloc_res_15211 mtt_alloc_res 5 15211 NULL
116441 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
116442 +iwl_dbgfs_sram_write_15239 iwl_dbgfs_sram_write 3 15239 NULL
116443 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
116444 +simple_strtol_15273 simple_strtol 0 15273 NULL
116445 +fw_realloc_buffer_15280 fw_realloc_buffer 2 15280 NULL
116446 +kovaplus_sysfs_read_15337 kovaplus_sysfs_read 6 15337 NULL
116447 +ioread16_15342 ioread16 0 15342 NULL
116448 +ept_prefetch_gpte_15348 ept_prefetch_gpte 4 15348 NULL
116449 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
116450 +ext4_direct_IO_15369 ext4_direct_IO 4 15369 NULL
116451 +graph_depth_read_15371 graph_depth_read 3 15371 NULL
116452 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
116453 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
116454 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
116455 +get_modalias_15406 get_modalias 2 15406 NULL
116456 +blockdev_direct_IO_15408 blockdev_direct_IO 5 15408 NULL
116457 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4-0 15423 NULL
116458 +rtw_cfg80211_rx_action_p2p_15432 rtw_cfg80211_rx_action_p2p 3 15432 NULL
116459 +tcp_mtu_to_mss_15438 tcp_mtu_to_mss 2-0 15438 NULL
116460 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
116461 +insert_old_idx_znode_15500 insert_old_idx_znode 0 15500 NULL
116462 +zd_chip_is_zd1211b_15518 zd_chip_is_zd1211b 0 15518 NULL
116463 +ifx_spi_write_15531 ifx_spi_write 3 15531 NULL
116464 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
116465 +xfrm_state_mtu_15548 xfrm_state_mtu 0-2 15548 NULL
116466 +snd_pcm_channel_info_15572 snd_pcm_channel_info 0 15572 NULL
116467 +persistent_status_15574 persistent_status 4 15574 NULL
116468 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
116469 +vme_user_write_15587 vme_user_write 3 15587 NULL
116470 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
116471 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
116472 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
116473 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &tomoyo_scan_bprm_15642 nohasharray
116474 +sk_memory_allocated_add_15642 sk_memory_allocated_add 2 15642 &pipeline_hs_tx_stat_fifo_int_read_15642
116475 +joydev_handle_JSIOCSBTNMAP_15643 joydev_handle_JSIOCSBTNMAP 3 15643 NULL
116476 +fs_path_add_15648 fs_path_add 3 15648 NULL
116477 +__do_readpage_15652 __do_readpage 0 15652 NULL
116478 +xsd_read_15653 xsd_read 3 15653 NULL
116479 +unix_bind_15668 unix_bind 3 15668 NULL
116480 +dm_read_15674 dm_read 3 15674 NULL nohasharray
116481 +SyS_connect_15674 SyS_connect 3 15674 &dm_read_15674
116482 +uinput_str_to_user_15695 uinput_str_to_user 3 15695 NULL
116483 +__sk_migrate_realloc_15709 __sk_migrate_realloc 3 15709 NULL
116484 +tracing_snapshot_write_15719 tracing_snapshot_write 3 15719 NULL
116485 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
116486 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
116487 +gnttab_expand_15817 gnttab_expand 1 15817 NULL nohasharray
116488 +nameseq_list_15817 nameseq_list 3-0 15817 &gnttab_expand_15817
116489 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
116490 +table_size_15851 table_size 0-1-2 15851 NULL
116491 +write_file_tx99_15856 write_file_tx99 3 15856 NULL
116492 +media_entity_init_15870 media_entity_init 2-4 15870 NULL nohasharray
116493 +ubi_io_write_15870 ubi_io_write 0 15870 &media_entity_init_15870
116494 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
116495 +parse_audio_stream_data_15937 parse_audio_stream_data 3 15937 NULL
116496 +power_read_15939 power_read 3 15939 NULL
116497 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
116498 +snd_pcm_lib_read_transfer_15952 snd_pcm_lib_read_transfer 5-2-4 15952 NULL
116499 +memblock_virt_alloc_try_nid_15954 memblock_virt_alloc_try_nid 1 15954 NULL
116500 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
116501 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
116502 +read_file_spectral_period_16057 read_file_spectral_period 3 16057 NULL
116503 +si5351_msynth_params_address_16062 si5351_msynth_params_address 0-1 16062 NULL
116504 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
116505 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 NULL nohasharray
116506 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 &isr_hw_pm_mode_changes_read_16110
116507 +snd_dma_pointer_16126 snd_dma_pointer 0-2 16126 NULL
116508 +fsm_init_16134 fsm_init 2 16134 NULL
116509 +ext4_xattr_block_get_16148 ext4_xattr_block_get 0 16148 NULL
116510 +optimal_reclaimed_pages_16172 optimal_reclaimed_pages 0 16172 NULL
116511 +mapping_level_16188 mapping_level 2-0 16188 NULL
116512 +i40e_allocate_virt_mem_d_16191 i40e_allocate_virt_mem_d 3 16191 NULL
116513 +ath10k_htt_rx_ring_size_16201 ath10k_htt_rx_ring_size 0 16201 NULL
116514 +cipso_v4_map_cat_rng_hton_16203 cipso_v4_map_cat_rng_hton 0 16203 NULL
116515 +SyS_pselect6_16210 SyS_pselect6 1 16210 NULL
116516 +create_table_16213 create_table 2 16213 NULL
116517 +ath9k_hw_ar9287_dump_eeprom_16224 ath9k_hw_ar9287_dump_eeprom 5-4 16224 NULL
116518 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
116519 +BcmGetSectionValStartOffset_16235 BcmGetSectionValStartOffset 0 16235 NULL
116520 +lov_prep_brw_set_16246 lov_prep_brw_set 3 16246 NULL
116521 +i40e_dbg_dump_read_16247 i40e_dbg_dump_read 3 16247 NULL
116522 +il_dbgfs_disable_ht40_write_16249 il_dbgfs_disable_ht40_write 3 16249 NULL
116523 +SyS_fgetxattr_16254 SyS_fgetxattr 4 16254 NULL
116524 +reiserfs_acl_count_16265 reiserfs_acl_count 0-1 16265 NULL
116525 +ocfs2_xattr_bucket_value_truncate_16279 ocfs2_xattr_bucket_value_truncate 4 16279 NULL
116526 +nand_bch_init_16280 nand_bch_init 3-2 16280 NULL nohasharray
116527 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 &nand_bch_init_16280
116528 +account_16283 account 0-4-2 16283 NULL nohasharray
116529 +mirror_status_16283 mirror_status 5 16283 &account_16283
116530 +jumpshot_read_data_16287 jumpshot_read_data 4 16287 NULL
116531 +mo_xattr_get_16288 mo_xattr_get 0 16288 NULL
116532 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
116533 +rbd_segment_offset_16293 rbd_segment_offset 0-2 16293 NULL
116534 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
116535 +kvm_handle_hva_range_16312 kvm_handle_hva_range 3-2 16312 NULL
116536 +sysfs_create_groups_16360 sysfs_create_groups 0 16360 NULL
116537 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
116538 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
116539 +i8042_create_kbd_port_16379 i8042_create_kbd_port 0 16379 NULL
116540 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
116541 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
116542 +__bio_add_page_16435 __bio_add_page 0-4 16435 NULL
116543 +cmdline_store_16442 cmdline_store 4 16442 NULL
116544 +btrfs_truncate_inode_items_16452 btrfs_truncate_inode_items 4 16452 NULL
116545 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
116546 +req_capsule_get_size_16467 req_capsule_get_size 0 16467 NULL
116547 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
116548 +KEY_OFFSET_16504 KEY_OFFSET 0 16504 NULL
116549 +snd_interval_max_16529 snd_interval_max 0 16529 NULL
116550 +raid10_resize_16537 raid10_resize 2 16537 NULL
116551 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
116552 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
116553 +lustre_msg_hdr_size_v2_16589 lustre_msg_hdr_size_v2 0 16589 NULL
116554 +gmux_index_read32_16604 gmux_index_read32 0 16604 NULL
116555 +compat_SyS_migrate_pages_16618 compat_SyS_migrate_pages 2 16618 NULL
116556 +rtw_set_wpa_ie_16633 rtw_set_wpa_ie 3 16633 NULL
116557 +btrfs_get_token_32_16651 btrfs_get_token_32 0 16651 NULL
116558 +__wa_populate_dto_urb_16699 __wa_populate_dto_urb 3-4 16699 NULL
116559 +__proc_lnet_buffers_16717 __proc_lnet_buffers 5 16717 NULL
116560 +__copy_to_user_swizzled_16748 __copy_to_user_swizzled 3-4 16748 NULL
116561 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
116562 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
116563 +i2o_parm_issue_16790 i2o_parm_issue 0 16790 NULL
116564 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
116565 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
116566 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
116567 +hfsplus_min_io_size_16859 hfsplus_min_io_size 0 16859 NULL
116568 +alloc_idx_lebs_16872 alloc_idx_lebs 2 16872 NULL
116569 +carl9170_debugfs_ampdu_state_read_16873 carl9170_debugfs_ampdu_state_read 3 16873 NULL
116570 +st_write_16874 st_write 3 16874 NULL
116571 +__kfifo_peek_n_16877 __kfifo_peek_n 0 16877 NULL
116572 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 NULL nohasharray
116573 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 &psb_unlocked_ioctl_16926
116574 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
116575 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
116576 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
116577 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
116578 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
116579 +C_SYSC_keyctl_17041 C_SYSC_keyctl 4 17041 NULL
116580 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
116581 +__arch_hweight32_17060 __arch_hweight32 0 17060 NULL
116582 +sddr55_read_data_17072 sddr55_read_data 4 17072 NULL
116583 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
116584 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
116585 +carl9170_debugfs_mem_usage_read_17084 carl9170_debugfs_mem_usage_read 3 17084 NULL
116586 +entry_length_17093 entry_length 0 17093 NULL
116587 +write_mem_17114 write_mem 3 17114 NULL
116588 +pvr2_hdw_state_report_17121 pvr2_hdw_state_report 3 17121 NULL
116589 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
116590 +jumpshot_write_data_17151 jumpshot_write_data 4 17151 NULL
116591 +sep_read_17161 sep_read 3 17161 NULL
116592 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
116593 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
116594 +UniStrnlen_17169 UniStrnlen 0 17169 NULL
116595 +access_remote_vm_17189 access_remote_vm 0 17189 NULL nohasharray
116596 +iwl_dbgfs_txfifo_flush_write_17189 iwl_dbgfs_txfifo_flush_write 3 17189 &access_remote_vm_17189
116597 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 NULL nohasharray
116598 +driver_state_read_17194 driver_state_read 3 17194 &iscsit_find_cmd_from_itt_or_dump_17194
116599 +sync_request_17208 sync_request 2 17208 NULL
116600 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
116601 +lprocfs_read_frac_helper_17261 lprocfs_read_frac_helper 0 17261 NULL
116602 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
116603 +alloc_ep_17269 alloc_ep 1 17269 NULL
116604 +pg_read_17276 pg_read 3 17276 NULL
116605 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
116606 +hmac_sha256_17278 hmac_sha256 2 17278 NULL
116607 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
116608 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
116609 +ieee80211_if_fmt_dot11MeshForwarding_17301 ieee80211_if_fmt_dot11MeshForwarding 3 17301 NULL
116610 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
116611 +gnttab_map_frames_v2_17314 gnttab_map_frames_v2 2 17314 NULL
116612 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
116613 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
116614 +mdc_import_seq_write_17409 mdc_import_seq_write 3 17409 NULL
116615 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
116616 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
116617 +libcfs_ipif_enumerate_17445 libcfs_ipif_enumerate 0 17445 NULL
116618 +nla_get_u32_17455 nla_get_u32 0 17455 NULL
116619 +__ref_totlen_17461 __ref_totlen 0 17461 NULL
116620 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
116621 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
116622 +lbs_highrssi_write_17515 lbs_highrssi_write 3 17515 NULL
116623 +qp_free_res_17541 qp_free_res 5 17541 NULL
116624 +__copy_to_user_17551 __copy_to_user 0-3 17551 NULL
116625 +copy_from_user_17559 copy_from_user 3-0 17559 NULL
116626 +snd_pcm_action_lock_irq_17569 snd_pcm_action_lock_irq 0 17569 NULL
116627 +hash_netport4_expire_17573 hash_netport4_expire 4 17573 NULL
116628 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
116629 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
116630 +osst_execute_17607 osst_execute 7-6 17607 NULL
116631 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
116632 +dma_map_page_17628 dma_map_page 0 17628 NULL
116633 +twl4030_set_gpio_direction_17645 twl4030_set_gpio_direction 1 17645 NULL
116634 +SYSC_migrate_pages_17657 SYSC_migrate_pages 2 17657 NULL
116635 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL nohasharray
116636 +ubi_io_read_data_17662 ubi_io_read_data 0 17662 &packet_setsockopt_17662
116637 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
116638 +filemap_fdatawait_17688 filemap_fdatawait 0 17688 NULL
116639 +venus_rename_17707 venus_rename 4-5 17707 NULL
116640 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
116641 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
116642 +ubifs_leb_change_17789 ubifs_leb_change 0 17789 NULL
116643 +shrink_slab_node_17794 shrink_slab_node 3 17794 NULL
116644 +lpuart_copy_rx_to_tty_17801 lpuart_copy_rx_to_tty 3 17801 NULL
116645 +gnet_stats_copy_app_17821 gnet_stats_copy_app 3 17821 NULL
116646 +cipso_v4_gentag_rbm_17836 cipso_v4_gentag_rbm 0 17836 NULL
116647 +em28xx_audio_ep_packet_size_17844 em28xx_audio_ep_packet_size 0 17844 NULL
116648 +dm_stats_message_17863 dm_stats_message 5 17863 NULL
116649 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
116650 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
116651 +virtio_cread32_17873 virtio_cread32 0 17873 NULL
116652 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
116653 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL nohasharray
116654 +i40e_align_l2obj_base_17878 i40e_align_l2obj_base 0-1 17878 &orinoco_set_key_17878
116655 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
116656 +ieee80211_if_fmt_dot11MeshMaxPeerLinks_17883 ieee80211_if_fmt_dot11MeshMaxPeerLinks 3 17883 NULL
116657 +ieee80211_if_fmt_dot11MeshHWMPRootMode_17890 ieee80211_if_fmt_dot11MeshHWMPRootMode 3 17890 NULL
116658 +dev_pm_opp_get_opp_count_17911 dev_pm_opp_get_opp_count 0 17911 NULL
116659 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
116660 +tipc_port_iovec_rcv_17921 tipc_port_iovec_rcv 3 17921 NULL
116661 +scsi_bufflen_17933 scsi_bufflen 0 17933 NULL
116662 +__mutex_lock_check_stamp_17947 __mutex_lock_check_stamp 0 17947 NULL
116663 +beacon_interval_write_17952 beacon_interval_write 3 17952 NULL
116664 +calc_nr_buckets_17976 calc_nr_buckets 0 17976 NULL
116665 +ext4_ext_calc_credits_for_single_extent_17983 ext4_ext_calc_credits_for_single_extent 0-2 17983 NULL
116666 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
116667 +gnttab_max_grant_frames_17993 gnttab_max_grant_frames 0 17993 NULL
116668 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
116669 +cpufreq_add_dev_symlink_18028 cpufreq_add_dev_symlink 0 18028 NULL
116670 +o2hb_highest_node_18034 o2hb_highest_node 0 18034 NULL
116671 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
116672 +__btrfs_drop_extents_18049 __btrfs_drop_extents 5 18049 NULL
116673 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
116674 +lua_sysfs_read_18062 lua_sysfs_read 6 18062 NULL
116675 +fpregs_get_18066 fpregs_get 4 18066 NULL
116676 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
116677 +SYSC_pselect6_18076 SYSC_pselect6 1 18076 NULL
116678 +SYSC_semtimedop_18091 SYSC_semtimedop 3 18091 NULL
116679 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
116680 +hfs_direct_IO_18104 hfs_direct_IO 4 18104 NULL
116681 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
116682 +svc_getnl_18120 svc_getnl 0 18120 NULL
116683 +paging32_gpte_to_gfn_lvl_18131 paging32_gpte_to_gfn_lvl 0-2-1 18131 NULL
116684 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
116685 +is_idx_node_in_use_18165 is_idx_node_in_use 0 18165 NULL
116686 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
116687 +snd_pcm_hw_refine_user_18204 snd_pcm_hw_refine_user 0 18204 NULL
116688 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
116689 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
116690 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
116691 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
116692 +alloc_trace_uprobe_18247 alloc_trace_uprobe 3 18247 NULL
116693 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
116694 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
116695 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
116696 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
116697 +find_dirty_idx_leb_18280 find_dirty_idx_leb 0 18280 NULL
116698 +bio_phys_segments_18281 bio_phys_segments 0 18281 NULL nohasharray
116699 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 &bio_phys_segments_18281
116700 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
116701 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
116702 +um_idi_write_18293 um_idi_write 3 18293 NULL
116703 +nouveau_disp_create__18305 nouveau_disp_create_ 4-7 18305 NULL
116704 +vga_r_18310 vga_r 0 18310 NULL
116705 +class_add_profile_18315 class_add_profile 1-3-5 18315 NULL
116706 +csio_mem_read_18319 csio_mem_read 3 18319 NULL
116707 +alloc_and_copy_string_18321 alloc_and_copy_string 2 18321 NULL
116708 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
116709 +bio_integrity_advance_18324 bio_integrity_advance 2 18324 NULL
116710 +copy_page_to_iter_18345 copy_page_to_iter 3-0 18345 NULL
116711 +lcd_proc_write_18351 lcd_proc_write 3 18351 NULL
116712 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
116713 +SyS_process_vm_readv_18366 SyS_process_vm_readv 3-5 18366 NULL
116714 +ep_io_18367 ep_io 0 18367 NULL
116715 +qib_user_sdma_num_pages_18371 qib_user_sdma_num_pages 0 18371 NULL
116716 +__ceph_getxattr_18386 __ceph_getxattr 0 18386 NULL
116717 +ci_role_write_18388 ci_role_write 3 18388 NULL
116718 +adis16136_show_serial_18402 adis16136_show_serial 3 18402 NULL
116719 +rtl8169_rx_fill_18416 rtl8169_rx_fill 0 18416 NULL
116720 +memblock_virt_alloc_node_nopanic_18431 memblock_virt_alloc_node_nopanic 1 18431 NULL
116721 +iscsi_create_flashnode_sess_18433 iscsi_create_flashnode_sess 4 18433 NULL
116722 +snd_hda_get_connections_18437 snd_hda_get_connections 0 18437 NULL
116723 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
116724 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
116725 +pci_vpd_lrdt_size_18479 pci_vpd_lrdt_size 0 18479 NULL nohasharray
116726 +mite_bytes_in_transit_18479 mite_bytes_in_transit 0 18479 &pci_vpd_lrdt_size_18479
116727 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
116728 +btrfs_fiemap_18501 btrfs_fiemap 3 18501 NULL
116729 +__copy_user_zeroing_intel_18510 __copy_user_zeroing_intel 0-3 18510 NULL
116730 +snd_vx_inb_18514 snd_vx_inb 0 18514 NULL
116731 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
116732 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 9 18530 NULL
116733 +tipc_send2port_18531 tipc_send2port 4 18531 NULL
116734 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
116735 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
116736 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
116737 +debug_output_18575 debug_output 3 18575 NULL
116738 +filemap_fdatawait_range_18600 filemap_fdatawait_range 0 18600 NULL nohasharray
116739 +slabinfo_write_18600 slabinfo_write 3 18600 &filemap_fdatawait_range_18600
116740 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
116741 +from_buffer_18625 from_buffer 3 18625 NULL
116742 +snd_pcm_oss_write3_18657 snd_pcm_oss_write3 0-3 18657 NULL
116743 +ieee80211_if_fmt_rssi_threshold_18664 ieee80211_if_fmt_rssi_threshold 3 18664 NULL
116744 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 NULL
116745 +fnic_stats_debugfs_read_18688 fnic_stats_debugfs_read 3 18688 NULL
116746 +echo_client_prep_commit_18693 echo_client_prep_commit 8 18693 NULL
116747 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
116748 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
116749 +blk_rq_bytes_18715 blk_rq_bytes 0 18715 NULL
116750 +nfs4_init_callback_netid_18717 nfs4_init_callback_netid 3 18717 NULL
116751 +snd_als4k_gcr_read_addr_18741 snd_als4k_gcr_read_addr 0 18741 NULL
116752 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
116753 +__erst_read_to_erange_from_nvram_18748 __erst_read_to_erange_from_nvram 0 18748 NULL
116754 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
116755 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
116756 +SyS_lsetxattr_18776 SyS_lsetxattr 4 18776 NULL
116757 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
116758 +dm_stats_print_18815 dm_stats_print 7 18815 NULL
116759 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
116760 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
116761 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
116762 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
116763 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
116764 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
116765 +ieee80211_rx_mgmt_disassoc_18927 ieee80211_rx_mgmt_disassoc 3 18927 NULL
116766 +snapshot_write_next_18937 snapshot_write_next 0 18937 NULL
116767 +__nla_reserve_18974 __nla_reserve 3 18974 NULL
116768 +__blockdev_direct_IO_18977 __blockdev_direct_IO 0-6 18977 NULL
116769 +find_dirtiest_idx_leb_19001 find_dirtiest_idx_leb 0 19001 NULL
116770 +layout_in_gaps_19006 layout_in_gaps 2 19006 NULL
116771 +huge_page_size_19008 huge_page_size 0 19008 NULL
116772 +hash_netport6_expire_19013 hash_netport6_expire 4 19013 NULL
116773 +sysfs_create_dir_ns_19033 sysfs_create_dir_ns 0 19033 NULL
116774 +revalidate_19043 revalidate 2 19043 NULL
116775 +afs_vnode_store_data_19048 afs_vnode_store_data 2-3-4-5 19048 NULL
116776 +osc_pinger_recov_seq_write_19056 osc_pinger_recov_seq_write 3 19056 NULL nohasharray
116777 +do_vm86_irq_handling_19056 do_vm86_irq_handling 2 19056 &osc_pinger_recov_seq_write_19056
116778 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
116779 +ceph_create_snap_context_19082 ceph_create_snap_context 1 19082 NULL
116780 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
116781 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
116782 +skb_gro_offset_19123 skb_gro_offset 0 19123 NULL
116783 +snd_als4k_iobase_readl_19136 snd_als4k_iobase_readl 0 19136 NULL
116784 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
116785 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
116786 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
116787 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
116788 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 3-0 19214 NULL
116789 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
116790 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
116791 +snd_mask_max_19224 snd_mask_max 0 19224 NULL
116792 +snd_pcm_capture_rewind_19229 snd_pcm_capture_rewind 0-2 19229 NULL
116793 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
116794 +ucma_query_19260 ucma_query 4 19260 NULL
116795 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
116796 +batadv_tt_save_orig_buffer_19288 batadv_tt_save_orig_buffer 4 19288 NULL nohasharray
116797 +cfg80211_rx_unprot_mlme_mgmt_19288 cfg80211_rx_unprot_mlme_mgmt 3 19288 &batadv_tt_save_orig_buffer_19288
116798 +qc_capture_19298 qc_capture 3 19298 NULL
116799 +ocfs2_prepare_inode_for_refcount_19303 ocfs2_prepare_inode_for_refcount 3-4 19303 NULL
116800 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
116801 +debug_read_19322 debug_read 3 19322 NULL
116802 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 NULL nohasharray
116803 +lbs_host_sleep_write_19332 lbs_host_sleep_write 3 19332 &cfg80211_inform_bss_19332
116804 +closure_sub_19359 closure_sub 2 19359 NULL
116805 +firmware_data_write_19360 firmware_data_write 6-5 19360 NULL
116806 +read_zero_19366 read_zero 3 19366 NULL
116807 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
116808 +sync_fill_pt_info_19397 sync_fill_pt_info 0 19397 NULL
116809 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
116810 +hid_hw_raw_request_19408 hid_hw_raw_request 0 19408 NULL
116811 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
116812 +SyS_sched_getaffinity_19444 SyS_sched_getaffinity 2 19444 NULL
116813 +xfrm_alg_auth_len_19454 xfrm_alg_auth_len 0 19454 NULL
116814 +gnet_stats_copy_19458 gnet_stats_copy 4 19458 NULL
116815 +gp2ap020a00f_get_thresh_reg_19468 gp2ap020a00f_get_thresh_reg 0 19468 NULL
116816 +sky2_read16_19475 sky2_read16 0 19475 NULL
116817 +kstrtoll_from_user_19500 kstrtoll_from_user 2 19500 NULL
116818 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
116819 +batadv_tvlv_container_register_19520 batadv_tvlv_container_register 5 19520 NULL
116820 +cfc_write_array_to_buffer_19529 cfc_write_array_to_buffer 3 19529 NULL
116821 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
116822 +gfn_to_index_19558 gfn_to_index 0-1-3-2 19558 NULL
116823 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
116824 +nfsd_read_19568 nfsd_read 5 19568 NULL
116825 +ieee80211_key_alloc_19575 ieee80211_key_alloc 3 19575 NULL
116826 +mnt_want_write_file_19579 mnt_want_write_file 0 19579 NULL
116827 +bm_status_read_19583 bm_status_read 3 19583 NULL
116828 +load_xattr_datum_19594 load_xattr_datum 0 19594 NULL
116829 +__mei_cl_recv_19636 __mei_cl_recv 3 19636 NULL
116830 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
116831 +memblock_virt_alloc_low_nopanic_19714 memblock_virt_alloc_low_nopanic 1 19714 NULL
116832 +ocfs2_control_get_this_node_19721 ocfs2_control_get_this_node 0 19721 NULL
116833 +read_reg_19723 read_reg 0 19723 NULL
116834 +wm8350_block_write_19727 wm8350_block_write 2-3 19727 NULL
116835 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
116836 +snd_es1968_get_dma_ptr_19747 snd_es1968_get_dma_ptr 0 19747 NULL
116837 +p9_client_read_19750 p9_client_read 5-0 19750 NULL
116838 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
116839 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
116840 +jffs2_acl_from_medium_19762 jffs2_acl_from_medium 2 19762 NULL
116841 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
116842 +vfs_getxattr_19832 vfs_getxattr 0 19832 NULL
116843 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
116844 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
116845 +__nla_put_19857 __nla_put 3 19857 NULL
116846 +mrp_request_join_19882 mrp_request_join 4 19882 NULL
116847 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
116848 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
116849 +mangle_name_19923 mangle_name 0 19923 NULL
116850 +cgroup_task_count_19930 cgroup_task_count 0 19930 NULL
116851 +guest_read_tsc_19931 guest_read_tsc 0 19931 NULL
116852 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
116853 +cfg80211_rx_assoc_resp_19944 cfg80211_rx_assoc_resp 4 19944 NULL
116854 +ll_xattr_cache_list_19954 ll_xattr_cache_list 0 19954 NULL
116855 +get_jack_mode_name_19976 get_jack_mode_name 4 19976 NULL
116856 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
116857 +rtw_set_wps_probe_resp_19989 rtw_set_wps_probe_resp 3 19989 NULL nohasharray
116858 +i40e_reserve_msix_vectors_19989 i40e_reserve_msix_vectors 2 19989 &rtw_set_wps_probe_resp_19989
116859 +diva_um_idi_read_20003 diva_um_idi_read 0 20003 NULL
116860 +lov_stripe_md_size_20009 lov_stripe_md_size 0-1 20009 NULL nohasharray
116861 +event_trigger_write_20009 event_trigger_write 3 20009 &lov_stripe_md_size_20009
116862 +tree_mod_log_eb_move_20011 tree_mod_log_eb_move 5 20011 NULL
116863 +SYSC_fgetxattr_20027 SYSC_fgetxattr 4 20027 NULL
116864 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
116865 +iwl_mvm_power_mac_dbgfs_read_20067 iwl_mvm_power_mac_dbgfs_read 0-4 20067 NULL
116866 +target_message_20072 target_message 2 20072 NULL
116867 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
116868 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
116869 +aat2870_reg_write_file_20086 aat2870_reg_write_file 3 20086 NULL
116870 +team_options_register_20091 team_options_register 3 20091 NULL
116871 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
116872 +root_nfs_copy_20111 root_nfs_copy 3 20111 NULL
116873 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
116874 +self_check_vid_hdr_20131 self_check_vid_hdr 0 20131 NULL
116875 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
116876 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
116877 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
116878 +crystalhd_map_dio_20181 crystalhd_map_dio 3 20181 NULL
116879 +pvr2_ctrl_value_to_sym_20229 pvr2_ctrl_value_to_sym 5 20229 NULL
116880 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
116881 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
116882 +btrfs_header_nritems_20296 btrfs_header_nritems 0 20296 NULL
116883 +r10_sync_page_io_20307 r10_sync_page_io 3 20307 NULL
116884 +dm_get_reserved_bio_based_ios_20315 dm_get_reserved_bio_based_ios 0 20315 NULL
116885 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
116886 +vx_send_msg_nolock_20322 vx_send_msg_nolock 0 20322 NULL
116887 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
116888 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
116889 +handle_arr_calc_size_20355 handle_arr_calc_size 0-1 20355 NULL
116890 +snd_pcm_stop_20376 snd_pcm_stop 0 20376 NULL
116891 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
116892 +snd_nm256_readl_20394 snd_nm256_readl 0 20394 NULL
116893 +SyS_get_mempolicy_20399 SyS_get_mempolicy 3 20399 NULL nohasharray
116894 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 &SyS_get_mempolicy_20399
116895 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
116896 +read_buf_20469 read_buf 2 20469 NULL
116897 +bio_trim_20472 bio_trim 2 20472 NULL
116898 +btrfs_get_32_20476 btrfs_get_32 0 20476 NULL
116899 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
116900 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
116901 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
116902 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
116903 +venus_create_20555 venus_create 4 20555 NULL
116904 +btrfs_super_log_root_20565 btrfs_super_log_root 0 20565 NULL
116905 +crypto_ahash_reqsize_20569 crypto_ahash_reqsize 0 20569 NULL
116906 +kvm_test_age_hva_20593 kvm_test_age_hva 2 20593 NULL
116907 +set_secure_conn_20596 set_secure_conn 4 20596 NULL
116908 +sync_timeline_create_20601 sync_timeline_create 2 20601 NULL
116909 +lirc_write_20604 lirc_write 3 20604 NULL
116910 +qib_qsfp_write_20614 qib_qsfp_write 0-2-4 20614 NULL
116911 +snd_pcm_oss_prepare_20641 snd_pcm_oss_prepare 0 20641 NULL
116912 +get_extent_skip_holes_20642 get_extent_skip_holes 2 20642 NULL
116913 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3-4 20646 NULL
116914 +cpulist_scnprintf_20648 cpulist_scnprintf 2-0 20648 NULL
116915 +oz_add_farewell_20652 oz_add_farewell 5 20652 NULL
116916 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
116917 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL nohasharray
116918 +btrfs_qgroup_reserve_20676 btrfs_qgroup_reserve 0 20676 &snd_hdsp_playback_copy_20676
116919 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 0-4 20682 NULL
116920 +cpumask_size_20683 cpumask_size 0 20683 NULL
116921 +btrfs_node_blockptr_20685 btrfs_node_blockptr 0 20685 NULL
116922 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
116923 +__maestro_read_20700 __maestro_read 0 20700 NULL
116924 +cipso_v4_gentag_rng_20703 cipso_v4_gentag_rng 0 20703 NULL
116925 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
116926 +ocfs2_read_xattr_bucket_20722 ocfs2_read_xattr_bucket 0 20722 NULL
116927 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
116928 +fb_prepare_logo_20743 fb_prepare_logo 0 20743 NULL
116929 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
116930 +ocfs2_align_bytes_to_clusters_20754 ocfs2_align_bytes_to_clusters 2 20754 NULL
116931 +brcmf_p2p_escan_20763 brcmf_p2p_escan 2 20763 NULL nohasharray
116932 +mnt_clone_write_20763 mnt_clone_write 0 20763 &brcmf_p2p_escan_20763
116933 +ubi_io_read_20767 ubi_io_read 0 20767 NULL
116934 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
116935 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
116936 +lowpan_write_20800 lowpan_write 3 20800 NULL
116937 +strndup_user_20819 strndup_user 2 20819 NULL
116938 +tipc_msg_build_20825 tipc_msg_build 3 20825 NULL
116939 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
116940 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
116941 +p9_tag_alloc_20845 p9_tag_alloc 3 20845 NULL
116942 +nvme_trans_supported_vpd_pages_20847 nvme_trans_supported_vpd_pages 4 20847 NULL
116943 +get_name_20855 get_name 4 20855 NULL
116944 +iwl_dbgfs_pm_params_read_20866 iwl_dbgfs_pm_params_read 3 20866 NULL
116945 +snd_pcm_capture_avail_20867 snd_pcm_capture_avail 0 20867 NULL
116946 +srq_free_res_20868 srq_free_res 5 20868 NULL
116947 +cfs_cpt_table_create_20884 cfs_cpt_table_create 1 20884 NULL
116948 +rb_simple_write_20890 rb_simple_write 3 20890 NULL
116949 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
116950 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
116951 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
116952 +lbs_rdbbp_write_20918 lbs_rdbbp_write 3 20918 NULL
116953 +htable_bits_20933 htable_bits 0 20933 NULL
116954 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
116955 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
116956 +rsxx_cram_read_20957 rsxx_cram_read 3 20957 NULL
116957 +nfs_map_name_to_uid_20962 nfs_map_name_to_uid 3 20962 NULL
116958 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
116959 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
116960 +qib_verbs_send_20999 qib_verbs_send 5-3 20999 NULL
116961 +btrfs_dirty_pages_21019 btrfs_dirty_pages 0 21019 NULL
116962 +btrfs_inode_ref_name_len_21024 btrfs_inode_ref_name_len 0 21024 NULL
116963 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
116964 +srp_change_queue_depth_21038 srp_change_queue_depth 2 21038 NULL
116965 +fsl_edma_prep_dma_cyclic_21042 fsl_edma_prep_dma_cyclic 4-3 21042 NULL
116966 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
116967 +reiserfs_direct_IO_21051 reiserfs_direct_IO 4 21051 NULL
116968 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
116969 +qdisc_get_default_21072 qdisc_get_default 2 21072 NULL
116970 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
116971 +bl_add_page_to_bio_21094 bl_add_page_to_bio 2 21094 NULL nohasharray
116972 +multipath_status_21094 multipath_status 5 21094 &bl_add_page_to_bio_21094
116973 +rate_control_pid_events_read_21099 rate_control_pid_events_read 3 21099 NULL
116974 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
116975 +_efx_mcdi_rpc_async_21119 _efx_mcdi_rpc_async 4-5 21119 NULL
116976 +i2400m_rx_trace_21127 i2400m_rx_trace 3 21127 NULL
116977 +mei_dbgfs_read_active_21172 mei_dbgfs_read_active 3 21172 NULL
116978 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
116979 +__generic_file_aio_write_21201 __generic_file_aio_write 0 21201 NULL
116980 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
116981 +scsi_execute_req_flags_21215 scsi_execute_req_flags 5 21215 NULL
116982 +get_numpages_21227 get_numpages 0-2-1 21227 NULL
116983 +input_ff_create_21240 input_ff_create 2 21240 NULL
116984 +cfg80211_notify_new_peer_candidate_21242 cfg80211_notify_new_peer_candidate 4 21242 NULL
116985 +fru_length_21257 fru_length 0 21257 NULL
116986 +rtw_set_wps_beacon_21262 rtw_set_wps_beacon 3 21262 NULL
116987 +drm_universal_plane_init_21296 drm_universal_plane_init 6 21296 NULL
116988 +do_msg_fill_21307 do_msg_fill 3 21307 NULL
116989 +add_res_range_21310 add_res_range 4 21310 NULL
116990 +get_zeroed_page_21322 get_zeroed_page 0 21322 NULL
116991 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
116992 +read_file_bool_bmps_21344 read_file_bool_bmps 3 21344 NULL
116993 +gfs2_ea_get_copy_21353 gfs2_ea_get_copy 0 21353 NULL
116994 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
116995 +SYSC_rt_sigpending_21379 SYSC_rt_sigpending 2 21379 NULL
116996 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
116997 +insert_ptr_21386 insert_ptr 6 21386 NULL
116998 +diva_get_driver_dbg_mask_21399 diva_get_driver_dbg_mask 0 21399 NULL
116999 +__clone_and_map_simple_bio_21404 __clone_and_map_simple_bio 4 21404 NULL
117000 +snd_m3_inw_21406 snd_m3_inw 0 21406 NULL
117001 +usnic_ib_dump_vf_hdr_21423 usnic_ib_dump_vf_hdr 3 21423 NULL
117002 +snapshot_read_next_21426 snapshot_read_next 0 21426 NULL
117003 +tcp_bound_to_half_wnd_21429 tcp_bound_to_half_wnd 0-2 21429 NULL
117004 +tracing_saved_cmdlines_read_21434 tracing_saved_cmdlines_read 3 21434 NULL
117005 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
117006 +__ertm_hdr_size_21450 __ertm_hdr_size 0 21450 NULL
117007 +mei_nfc_send_21477 mei_nfc_send 3 21477 NULL
117008 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
117009 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
117010 +btrfs_file_aio_write_21520 btrfs_file_aio_write 4 21520 NULL
117011 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
117012 +cipso_v4_map_cat_enum_hton_21540 cipso_v4_map_cat_enum_hton 0 21540 NULL
117013 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
117014 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
117015 +xfs_buf_read_uncached_21585 xfs_buf_read_uncached 3 21585 NULL
117016 +snd_es18xx_mixer_read_21586 snd_es18xx_mixer_read 0 21586 NULL
117017 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
117018 +filemap_get_page_21606 filemap_get_page 2 21606 NULL
117019 +__jfs_getxattr_21631 __jfs_getxattr 0 21631 NULL
117020 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
117021 +ocfs2_xattr_get_nolock_21678 ocfs2_xattr_get_nolock 0 21678 NULL
117022 +regmap_register_patch_21681 regmap_register_patch 3 21681 NULL
117023 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1 21687 NULL
117024 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
117025 +update_time_21719 update_time 0 21719 NULL
117026 +unix_skb_len_21722 unix_skb_len 0 21722 NULL
117027 +lprocfs_wr_import_21728 lprocfs_wr_import 3 21728 NULL
117028 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
117029 +usbat_flash_read_data_21762 usbat_flash_read_data 4 21762 NULL
117030 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
117031 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
117032 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
117033 +_iwl_dbgfs_sta_drain_write_21837 _iwl_dbgfs_sta_drain_write 3 21837 NULL
117034 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
117035 +lpfc_idiag_extacc_avail_get_21865 lpfc_idiag_extacc_avail_get 0-3 21865 NULL
117036 +brcms_debugfs_hardware_read_21867 brcms_debugfs_hardware_read 3 21867 NULL
117037 +msix_capability_init_21870 msix_capability_init 0 21870 NULL
117038 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
117039 +ldlm_lock_create_21888 ldlm_lock_create 7 21888 NULL
117040 +dbAllocCtl_21911 dbAllocCtl 0 21911 NULL
117041 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
117042 +twl_i2c_write_u16_21953 twl_i2c_write_u16 3 21953 NULL
117043 +__build_xattrs_21979 __build_xattrs 0 21979 NULL
117044 +SYSC_prctl_21980 SYSC_prctl 4 21980 NULL
117045 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 3-0 22001 NULL nohasharray
117046 +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
117047 +regcache_sync_block_raw_flush_22021 regcache_sync_block_raw_flush 3-4 22021 NULL
117048 +btrfs_get_16_22023 btrfs_get_16 0 22023 NULL
117049 +_sp2d_min_pg_22032 _sp2d_min_pg 0 22032 NULL
117050 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
117051 +ieee80211_if_fmt_dropped_frames_ttl_22054 ieee80211_if_fmt_dropped_frames_ttl 3 22054 NULL
117052 +btrfs_reloc_clone_csums_22077 btrfs_reloc_clone_csums 2-3 22077 NULL
117053 +mem_rw_22085 mem_rw 3 22085 NULL
117054 +kstrtos32_from_user_22087 kstrtos32_from_user 2 22087 NULL
117055 +snd_pcm_xrun_22088 snd_pcm_xrun 0 22088 NULL
117056 +rt2x00debug_read_crypto_stats_22109 rt2x00debug_read_crypto_stats 3 22109 NULL
117057 +snd_hda_codec_read_22130 snd_hda_codec_read 0 22130 NULL
117058 +SyS_sched_setaffinity_22148 SyS_sched_setaffinity 2 22148 NULL
117059 +do_tcp_sendpages_22155 do_tcp_sendpages 4 22155 NULL
117060 +pci_request_region_22164 pci_request_region 0 22164 NULL
117061 +__kfifo_alloc_22173 __kfifo_alloc 3 22173 NULL
117062 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
117063 +mem_write_22232 mem_write 3 22232 NULL
117064 +p9_virtio_zc_request_22240 p9_virtio_zc_request 6-5 22240 NULL
117065 +prepare_to_wait_event_22247 prepare_to_wait_event 0 22247 NULL
117066 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
117067 +ping_common_sendmsg_22261 ping_common_sendmsg 5 22261 NULL
117068 +add_res_tree_22263 add_res_tree 7 22263 NULL
117069 +queue_max_sectors_22280 queue_max_sectors 0 22280 NULL
117070 +pci_vpd_srdt_size_22300 pci_vpd_srdt_size 0 22300 NULL nohasharray
117071 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 &pci_vpd_srdt_size_22300
117072 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
117073 +lov_setstripe_22307 lov_setstripe 2 22307 NULL
117074 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
117075 +atomic_read_22342 atomic_read 0 22342 NULL
117076 +ll_lazystatfs_seq_write_22353 ll_lazystatfs_seq_write 3 22353 NULL
117077 +snd_pcm_alsa_frames_22363 snd_pcm_alsa_frames 2 22363 NULL
117078 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
117079 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
117080 +zoran_write_22404 zoran_write 3 22404 NULL
117081 +queue_reply_22416 queue_reply 3 22416 NULL
117082 +__set_enter_print_fmt_22431 __set_enter_print_fmt 0 22431 NULL
117083 +queue_max_segments_22441 queue_max_segments 0 22441 NULL
117084 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
117085 +ecryptfs_write_22488 ecryptfs_write 4-3 22488 NULL
117086 +qib_user_sdma_alloc_header_22490 qib_user_sdma_alloc_header 2 22490 NULL
117087 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
117088 +trim_no_bitmap_22524 trim_no_bitmap 4-3 22524 NULL
117089 +ntb_setup_bwd_msix_22549 ntb_setup_bwd_msix 2-0 22549 NULL
117090 +ocfs2_read_extent_block_22550 ocfs2_read_extent_block 0 22550 NULL
117091 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
117092 +dbFindCtl_22587 dbFindCtl 0 22587 NULL
117093 +snapshot_read_22601 snapshot_read 3 22601 NULL
117094 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
117095 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
117096 +wl1271_rx_filter_get_fields_size_22638 wl1271_rx_filter_get_fields_size 0 22638 NULL
117097 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
117098 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
117099 +ext4_ext_direct_IO_22679 ext4_ext_direct_IO 4 22679 NULL
117100 +fill_gap_22681 fill_gap 0 22681 NULL nohasharray
117101 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 &fill_gap_22681
117102 +bch_dump_read_22685 bch_dump_read 3 22685 NULL
117103 +reg_umr_22686 reg_umr 5 22686 NULL
117104 +SYSC_vmsplice_22697 SYSC_vmsplice 3 22697 NULL
117105 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
117106 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4-0 22735 NULL
117107 +ceph_decode_32_22738 ceph_decode_32 0 22738 NULL nohasharray
117108 +__mei_cl_send_22738 __mei_cl_send 3 22738 &ceph_decode_32_22738
117109 +__writeback_single_inode_22739 __writeback_single_inode 0 22739 NULL
117110 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
117111 +qlcnic_sriov_init_22762 qlcnic_sriov_init 2 22762 NULL
117112 +print_frame_22769 print_frame 0 22769 NULL
117113 +ftrace_arch_read_dyn_info_22773 ftrace_arch_read_dyn_info 0 22773 NULL
117114 +__break_lease_22777 __break_lease 0 22777 NULL
117115 +vnic_dev_get_res_count_22791 vnic_dev_get_res_count 0 22791 NULL
117116 +pla_ocp_write_22802 pla_ocp_write 4 22802 NULL
117117 +__generic_copy_to_user_intel_22806 __generic_copy_to_user_intel 0-3 22806 NULL
117118 +create_attr_set_22861 create_attr_set 1 22861 NULL
117119 +hash_ip6_expire_22867 hash_ip6_expire 4 22867 NULL
117120 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
117121 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
117122 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
117123 +ion_handle_test_kernel_22900 ion_handle_test_kernel 4-3 22900 NULL nohasharray
117124 +policy_emit_config_values_22900 policy_emit_config_values 3 22900 &ion_handle_test_kernel_22900
117125 +__set_xattr_22923 __set_xattr 0 22923 NULL
117126 +xstateregs_set_22932 xstateregs_set 4 22932 NULL
117127 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
117128 +alloc_sglist_22960 alloc_sglist 2-3 22960 NULL
117129 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
117130 +vme_get_size_22964 vme_get_size 0 22964 NULL
117131 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
117132 +cached_dev_cache_miss_22979 cached_dev_cache_miss 4 22979 NULL
117133 +usb_get_langid_22983 usb_get_langid 0 22983 NULL
117134 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
117135 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
117136 +cifs_local_to_utf16_bytes_23025 cifs_local_to_utf16_bytes 0 23025 NULL
117137 +st_status_23032 st_status 5 23032 NULL
117138 +nv50_disp_chan_create__23056 nv50_disp_chan_create_ 5 23056 NULL
117139 +comedi_buf_write_n_available_23057 comedi_buf_write_n_available 0 23057 NULL
117140 +security_inode_killpriv_23060 security_inode_killpriv 0 23060 NULL
117141 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
117142 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
117143 +mei_cl_send_23068 mei_cl_send 3 23068 NULL
117144 +raw_sendmsg_23078 raw_sendmsg 4 23078 NULL
117145 +get_user_hdr_len_23079 get_user_hdr_len 0 23079 NULL
117146 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
117147 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
117148 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
117149 +pipe_iov_copy_from_user_23102 pipe_iov_copy_from_user 3 23102 NULL
117150 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
117151 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
117152 +bset_tree_bytes_23111 bset_tree_bytes 0 23111 NULL nohasharray
117153 +nl80211_send_rx_auth_23111 nl80211_send_rx_auth 4 23111 &bset_tree_bytes_23111
117154 +__clear_user_23118 __clear_user 0-2 23118 NULL
117155 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
117156 +ata_scsi_change_queue_depth_23126 ata_scsi_change_queue_depth 2 23126 NULL
117157 +read_file_ani_23161 read_file_ani 3 23161 NULL
117158 +usblp_write_23178 usblp_write 3 23178 NULL
117159 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
117160 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
117161 +nft_hash_tbl_alloc_23224 nft_hash_tbl_alloc 1 23224 NULL
117162 +tty_buffer_request_room_23228 tty_buffer_request_room 2-0 23228 NULL
117163 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL
117164 +ft1000_read_dpram_mag_32_23232 ft1000_read_dpram_mag_32 0 23232 NULL
117165 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
117166 +__gfn_to_rmap_23240 __gfn_to_rmap 1-2 23240 NULL
117167 +nv50_ram_create__23241 nv50_ram_create_ 4 23241 NULL
117168 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
117169 +uwb_dev_addr_print_23282 uwb_dev_addr_print 2 23282 NULL
117170 +diva_get_trace_filter_23286 diva_get_trace_filter 0 23286 NULL
117171 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
117172 +__aa_kvmalloc_23320 __aa_kvmalloc 1 23320 NULL
117173 +page_readlink_23346 page_readlink 3 23346 NULL
117174 +kmem_zalloc_large_23351 kmem_zalloc_large 1 23351 NULL
117175 +get_dst_timing_23358 get_dst_timing 0 23358 NULL nohasharray
117176 +write_inode_23358 write_inode 0 23358 &get_dst_timing_23358
117177 +fd_setup_write_same_buf_23369 fd_setup_write_same_buf 3 23369 NULL
117178 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
117179 +vga_mm_r_23419 vga_mm_r 0 23419 NULL
117180 +ocfs2_zero_tail_23447 ocfs2_zero_tail 3 23447 NULL
117181 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
117182 +__ata_change_queue_depth_23484 __ata_change_queue_depth 3 23484 NULL
117183 +linear_conf_23485 linear_conf 2 23485 NULL nohasharray
117184 +sync_mapping_buffers_23485 sync_mapping_buffers 0 23485 &linear_conf_23485
117185 +event_filter_read_23494 event_filter_read 3 23494 NULL
117186 +lustre_acl_xattr_merge2ext_23502 lustre_acl_xattr_merge2ext 2 23502 NULL
117187 +devm_iio_device_alloc_23511 devm_iio_device_alloc 2 23511 NULL
117188 +__proc_cpt_table_23516 __proc_cpt_table 5 23516 NULL
117189 +hash_ipmark6_expire_23518 hash_ipmark6_expire 4 23518 NULL
117190 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
117191 +tcp_current_mss_23552 tcp_current_mss 0 23552 NULL
117192 +dbg_leb_change_23555 dbg_leb_change 0 23555 NULL
117193 +btrfs_super_bytenr_23561 btrfs_super_bytenr 0 23561 NULL
117194 +venus_symlink_23570 venus_symlink 6-4 23570 NULL
117195 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
117196 +xfpregs_get_23586 xfpregs_get 4 23586 NULL
117197 +snd_interval_min_23590 snd_interval_min 0 23590 NULL
117198 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
117199 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
117200 +sInW_23663 sInW 0 23663 NULL
117201 +SyS_connect_23669 SyS_connect 3 23669 NULL
117202 +cx18_read_23699 cx18_read 3 23699 NULL
117203 +at_get_23708 at_get 0 23708 NULL
117204 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
117205 +__kfifo_max_r_23768 __kfifo_max_r 0-2-1 23768 NULL
117206 +__build_packet_message_23778 __build_packet_message 4-10 23778 NULL
117207 +security_inode_getxattr_23781 security_inode_getxattr 0 23781 NULL
117208 +cfg80211_inform_bss_width_frame_23782 cfg80211_inform_bss_width_frame 5 23782 NULL
117209 +mpt_free_res_23793 mpt_free_res 5 23793 NULL
117210 +map_write_23795 map_write 3 23795 NULL
117211 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
117212 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
117213 +lustre_msg_buflen_23827 lustre_msg_buflen 0 23827 NULL
117214 +ceph_copy_page_vector_to_user_23829 ceph_copy_page_vector_to_user 0-3-4 23829 NULL
117215 +pgdat_end_pfn_23842 pgdat_end_pfn 0 23842 NULL
117216 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
117217 +p54_init_common_23850 p54_init_common 1 23850 NULL
117218 +bin_to_hex_dup_23853 bin_to_hex_dup 2 23853 NULL
117219 +ocfs2_xattr_get_clusters_23857 ocfs2_xattr_get_clusters 0 23857 NULL
117220 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
117221 +nouveau_clock_create__23881 nouveau_clock_create_ 5 23881 NULL nohasharray
117222 +writeback_single_inode_23881 writeback_single_inode 0 23881 &nouveau_clock_create__23881
117223 +tipc_snprintf_23893 tipc_snprintf 2-0 23893 NULL
117224 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL nohasharray
117225 +ieee80211_if_read_hw_queues_23911 ieee80211_if_read_hw_queues 3 23911 &add_new_gdb_meta_bg_23911
117226 +f2fs_getxattr_23917 f2fs_getxattr 0 23917 NULL
117227 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 NULL nohasharray
117228 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 &ipath_reg_phys_mr_23918
117229 +kvm_read_guest_23928 kvm_read_guest 4-2 23928 NULL
117230 +uvc_endpoint_max_bpi_23944 uvc_endpoint_max_bpi 0 23944 NULL
117231 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
117232 +size_roundup_power2_23958 size_roundup_power2 0-1 23958 NULL
117233 +sddr55_write_data_23983 sddr55_write_data 4 23983 NULL
117234 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
117235 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
117236 +give_pages_24021 give_pages 3 24021 NULL
117237 +adis16400_show_serial_number_24037 adis16400_show_serial_number 3 24037 NULL
117238 +hmac_setkey_24043 hmac_setkey 3 24043 NULL
117239 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
117240 +iwl_dbgfs_low_latency_read_24062 iwl_dbgfs_low_latency_read 3 24062 NULL
117241 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
117242 +C_SYSC_process_vm_writev_24102 C_SYSC_process_vm_writev 3-5 24102 NULL
117243 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
117244 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
117245 +lov_brw_24122 lov_brw 4 24122 NULL
117246 +mpu401_read_24126 mpu401_read 3 24126 NULL
117247 +_picolcd_flash_write_24134 _picolcd_flash_write 4 24134 NULL
117248 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
117249 +SyS_sethostname_24150 SyS_sethostname 2 24150 NULL
117250 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
117251 +adu_read_24177 adu_read 3 24177 NULL
117252 +safe_prepare_write_buffer_24187 safe_prepare_write_buffer 3 24187 NULL
117253 +irq_remapping_setup_msi_irqs_24194 irq_remapping_setup_msi_irqs 2 24194 NULL
117254 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
117255 +efx_vf_size_24213 efx_vf_size 0 24213 NULL
117256 +tcpprobe_sprint_24222 tcpprobe_sprint 0-2 24222 NULL
117257 +mei_amthif_read_24224 mei_amthif_read 4 24224 NULL nohasharray
117258 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 3-2-1 24224 &mei_amthif_read_24224
117259 +pci_num_vf_24235 pci_num_vf 0 24235 NULL
117260 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
117261 +em28xx_alloc_urbs_24260 em28xx_alloc_urbs 4-6 24260 NULL
117262 +calculate_sizes_24273 calculate_sizes 2 24273 NULL
117263 +thin_status_24278 thin_status 5 24278 NULL
117264 +msg_size_24288 msg_size 0 24288 NULL
117265 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
117266 +reserve_metadata_bytes_24313 reserve_metadata_bytes 0 24313 NULL
117267 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
117268 +si476x_radio_read_acf_blob_24336 si476x_radio_read_acf_blob 3 24336 NULL
117269 +C_SYSC_pwritev_24345 C_SYSC_pwritev 3 24345 NULL
117270 +prepare_pages_24349 prepare_pages 0 24349 NULL
117271 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
117272 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
117273 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
117274 +btrfs_item_size_nr_24367 btrfs_item_size_nr 0 24367 NULL
117275 +igetword_24373 igetword 0 24373 NULL nohasharray
117276 +break_deleg_24373 break_deleg 0 24373 &igetword_24373
117277 +max_io_len_24384 max_io_len 0-1 24384 NULL
117278 +mpt_alloc_res_24387 mpt_alloc_res 5 24387 NULL
117279 +osc_cur_grant_bytes_seq_write_24396 osc_cur_grant_bytes_seq_write 3 24396 NULL
117280 +getxattr_24398 getxattr 4 24398 NULL nohasharray
117281 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 &getxattr_24398
117282 +populate_msi_sysfs_24399 populate_msi_sysfs 0 24399 NULL
117283 +blk_update_bidi_request_24415 blk_update_bidi_request 3-4 24415 NULL
117284 +nvme_trans_log_supp_pages_24418 nvme_trans_log_supp_pages 3 24418 NULL
117285 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
117286 +xenbus_file_read_24427 xenbus_file_read 3 24427 NULL
117287 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
117288 +copy_and_ioctl_24434 copy_and_ioctl 4 24434 NULL
117289 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
117290 +rtw_set_wps_assoc_resp_24440 rtw_set_wps_assoc_resp 3 24440 NULL nohasharray
117291 +smk_user_access_24440 smk_user_access 3 24440 &rtw_set_wps_assoc_resp_24440
117292 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
117293 +lbs_highsnr_write_24460 lbs_highsnr_write 3 24460 NULL
117294 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
117295 +dut_mode_read_24489 dut_mode_read 3 24489 NULL
117296 +read_file_spec_scan_ctl_24491 read_file_spec_scan_ctl 3 24491 NULL
117297 +pd_video_read_24510 pd_video_read 3 24510 NULL
117298 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
117299 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
117300 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
117301 +write_cache_pages_24562 write_cache_pages 0 24562 NULL
117302 +SyS_pselect6_24582 SyS_pselect6 1 24582 NULL
117303 +udf_compute_nr_groups_24594 udf_compute_nr_groups 0 24594 NULL
117304 +sensor_hub_get_physical_device_count_24605 sensor_hub_get_physical_device_count 0 24605 NULL nohasharray
117305 +lov_alloc_memmd_24605 lov_alloc_memmd 2 24605 &sensor_hub_get_physical_device_count_24605
117306 +SyS_poll_24620 SyS_poll 2 24620 NULL
117307 +context_alloc_24645 context_alloc 3 24645 NULL
117308 +blk_rq_err_bytes_24650 blk_rq_err_bytes 0 24650 NULL
117309 +btrfs_check_data_free_space_24692 btrfs_check_data_free_space 0 24692 NULL
117310 +datafab_write_data_24696 datafab_write_data 4 24696 NULL
117311 +intelfbhw_get_p1p2_24703 intelfbhw_get_p1p2 2 24703 NULL
117312 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
117313 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
117314 +get_dma_residue_24749 get_dma_residue 0 24749 NULL
117315 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
117316 +ocfs2_read_blocks_24777 ocfs2_read_blocks 0 24777 NULL
117317 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
117318 +cache_read_24790 cache_read 3 24790 NULL
117319 +user_regset_copyout_24796 user_regset_copyout 7 24796 NULL
117320 +kvm_read_guest_virt_helper_24804 kvm_read_guest_virt_helper 3-1 24804 NULL
117321 +ath6kl_fwlog_mask_write_24810 ath6kl_fwlog_mask_write 3 24810 NULL
117322 +snd_als4k_gcr_read_24840 snd_als4k_gcr_read 0 24840 NULL
117323 +snd_pcm_lib_buffer_bytes_24865 snd_pcm_lib_buffer_bytes 0 24865 NULL
117324 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
117325 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
117326 +queues_read_24877 queues_read 3 24877 NULL
117327 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
117328 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL nohasharray
117329 +__btrfs_free_extent_24927 __btrfs_free_extent 7 24927 &v4l2_ctrl_new_24927
117330 +ocfs2_fiemap_24949 ocfs2_fiemap 3-4 24949 NULL
117331 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
117332 +security_inode_rename_24971 security_inode_rename 0 24971 NULL
117333 +twl_i2c_write_u8_24976 twl_i2c_write_u8 3 24976 NULL
117334 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
117335 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
117336 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
117337 +ni_660x_num_counters_25031 ni_660x_num_counters 0 25031 NULL
117338 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
117339 +btrfs_stack_key_blockptr_25058 btrfs_stack_key_blockptr 0 25058 NULL
117340 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
117341 +ll_track_pid_seq_write_25068 ll_track_pid_seq_write 3 25068 NULL
117342 +SYSC_listxattr_25072 SYSC_listxattr 3 25072 NULL
117343 +ima_appraise_measurement_25093 ima_appraise_measurement 6 25093 NULL
117344 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
117345 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
117346 +_iwl_dbgfs_reduced_txp_write_25169 _iwl_dbgfs_reduced_txp_write 3 25169 NULL nohasharray
117347 +kvm_mmu_notifier_change_pte_25169 kvm_mmu_notifier_change_pte 3 25169 &_iwl_dbgfs_reduced_txp_write_25169
117348 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
117349 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
117350 +stripe_status_25259 stripe_status 5 25259 NULL
117351 +snd_pcm_start_25273 snd_pcm_start 0 25273 NULL
117352 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
117353 +vfs_writev_25278 vfs_writev 3 25278 NULL
117354 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
117355 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 NULL
117356 +rng_buffer_size_25348 rng_buffer_size 0 25348 NULL
117357 +SYSC_kexec_load_25361 SYSC_kexec_load 2 25361 NULL
117358 +unix_mkname_25368 unix_mkname 0-2 25368 NULL
117359 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
117360 +vsp1_entity_init_25407 vsp1_entity_init 3 25407 NULL
117361 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
117362 +ipath_decode_err_25468 ipath_decode_err 3 25468 NULL
117363 +crypto_hash_digestsize_25469 crypto_hash_digestsize 0 25469 NULL
117364 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4-0 25502 NULL
117365 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
117366 +sb_permission_25523 sb_permission 0 25523 NULL
117367 +ext3_get_inode_loc_25542 ext3_get_inode_loc 0 25542 NULL
117368 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
117369 +wimax_addr_scnprint_25548 wimax_addr_scnprint 2 25548 NULL
117370 +ht_print_chan_25556 ht_print_chan 0-3-4 25556 NULL
117371 +skb_tailroom_25567 skb_tailroom 0 25567 NULL
117372 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
117373 +copy_user_generic_25611 copy_user_generic 0 25611 NULL
117374 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
117375 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL nohasharray
117376 +__get_user_pages_25628 __get_user_pages 0 25628 &befs_utf2nls_25628
117377 +__direct_map_25647 __direct_map 5-6 25647 NULL
117378 +aircable_prepare_write_buffer_25669 aircable_prepare_write_buffer 3 25669 NULL
117379 +lpfc_idiag_cmd_get_25672 lpfc_idiag_cmd_get 2 25672 NULL
117380 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
117381 +prom_early_alloc_25692 prom_early_alloc 1 25692 NULL
117382 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
117383 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
117384 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 NULL nohasharray
117385 +sel_write_context_25726 sel_write_context 3 25726 &__alloc_bootmem_low_node_25726
117386 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
117387 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
117388 +sg_read_25799 sg_read 3 25799 NULL
117389 +system_enable_read_25815 system_enable_read 3 25815 NULL
117390 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
117391 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
117392 +parport_read_25855 parport_read 0 25855 NULL
117393 +xfs_dir2_sf_hdr_size_25858 xfs_dir2_sf_hdr_size 0 25858 NULL
117394 +key_attr_size_25865 key_attr_size 0 25865 NULL
117395 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
117396 +run_delalloc_nocow_25896 run_delalloc_nocow 3-4 25896 NULL
117397 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
117398 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
117399 +nvme_trans_mode_page_create_25908 nvme_trans_mode_page_create 7-4 25908 NULL
117400 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
117401 +rcname_read_25919 rcname_read 3 25919 NULL
117402 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
117403 +key_flags_read_25931 key_flags_read 3 25931 NULL
117404 +copy_play_buf_25932 copy_play_buf 3 25932 NULL
117405 +flush_25957 flush 2 25957 NULL
117406 +_regmap_multi_reg_write_25967 _regmap_multi_reg_write 3 25967 NULL
117407 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
117408 +lustre_msg_buflen_v2_25997 lustre_msg_buflen_v2 0 25997 NULL
117409 +SyS_process_vm_readv_26019 SyS_process_vm_readv 3-5 26019 NULL
117410 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
117411 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
117412 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
117413 +pri_wm_latency_write_26063 pri_wm_latency_write 3 26063 NULL
117414 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
117415 +i8042_pnp_id_to_string_26108 i8042_pnp_id_to_string 3 26108 NULL
117416 +read_sb_page_26119 read_sb_page 5 26119 NULL
117417 +ath9k_hw_name_26146 ath9k_hw_name 3 26146 NULL
117418 +copy_oldmem_page_26164 copy_oldmem_page 3 26164 NULL
117419 +gfs2_xattr_acl_get_26166 gfs2_xattr_acl_get 0 26166 NULL nohasharray
117420 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 &gfs2_xattr_acl_get_26166
117421 +disk_devt_26180 disk_devt 0 26180 NULL
117422 +ieee80211_if_fmt_dot11MeshTTL_26198 ieee80211_if_fmt_dot11MeshTTL 3 26198 NULL
117423 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
117424 +mce_write_26201 mce_write 3 26201 NULL
117425 +mwifiex_regrdwr_write_26225 mwifiex_regrdwr_write 3 26225 NULL
117426 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
117427 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
117428 +simple_setattr_26234 simple_setattr 0 26234 NULL
117429 +genwqe_ffdc_buff_size_26263 genwqe_ffdc_buff_size 0 26263 NULL
117430 +crypto_ctxsize_26278 crypto_ctxsize 0 26278 NULL
117431 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
117432 +snd_pcm_plug_client_channels_buf_26309 snd_pcm_plug_client_channels_buf 0-3 26309 NULL
117433 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
117434 +check_can_nocow_26336 check_can_nocow 2 26336 NULL
117435 +snd_vx_check_reg_bit_26344 snd_vx_check_reg_bit 0 26344 NULL
117436 +ocfs2_duplicate_clusters_by_page_26357 ocfs2_duplicate_clusters_by_page 6-3 26357 NULL
117437 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
117438 +invalidate_inode_pages2_range_26403 invalidate_inode_pages2_range 0 26403 NULL
117439 +ntty_write_26404 ntty_write 3 26404 NULL
117440 +firmware_store_26408 firmware_store 4 26408 NULL
117441 +pagemap_read_26441 pagemap_read 3 26441 NULL
117442 +enc_pools_add_pages_26461 enc_pools_add_pages 1 26461 NULL nohasharray
117443 +tower_read_26461 tower_read 3 26461 &enc_pools_add_pages_26461
117444 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
117445 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
117446 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
117447 +read_vmcore_26501 read_vmcore 3 26501 NULL
117448 +uhid_char_write_26502 uhid_char_write 3 26502 NULL
117449 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 4-3 26507 NULL
117450 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
117451 +alloc_ep_req_26521 alloc_ep_req 3-2 26521 NULL
117452 +SyS_rt_sigpending_26538 SyS_rt_sigpending 2 26538 NULL
117453 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
117454 +dio_new_bio_26562 dio_new_bio 0 26562 NULL
117455 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL
117456 +kernfs_name_locked_26617 kernfs_name_locked 3 26617 NULL
117457 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
117458 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL nohasharray
117459 +inb_p_26650 inb_p 0 26650 &irq_alloc_generic_chip_26650
117460 +nouveau_volt_create__26654 nouveau_volt_create_ 4 26654 NULL
117461 +cipso_v4_map_cat_rbm_hton_26680 cipso_v4_map_cat_rbm_hton 0 26680 NULL
117462 +flowinfo_read_26683 flowinfo_read 3 26683 NULL
117463 +sysfs_add_file_26716 sysfs_add_file 0 26716 NULL
117464 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
117465 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
117466 +snd_hda_get_raw_connections_26762 snd_hda_get_raw_connections 0 26762 NULL
117467 +dma_map_single_attrs_26779 dma_map_single_attrs 0 26779 NULL
117468 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
117469 +cipso_v4_genopt_26812 cipso_v4_genopt 0 26812 NULL
117470 +iwl_trans_read_mem32_26825 iwl_trans_read_mem32 0 26825 NULL
117471 +smk_write_load_26829 smk_write_load 3 26829 NULL
117472 +scnprint_id_26842 scnprint_id 3-0 26842 NULL
117473 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
117474 +ss_alloc_ep_req_26848 ss_alloc_ep_req 2 26848 NULL
117475 +tipc_conn_sendmsg_26867 tipc_conn_sendmsg 5 26867 NULL
117476 +ath6kl_create_qos_write_26879 ath6kl_create_qos_write 3 26879 NULL
117477 +svc_print_xprts_26881 svc_print_xprts 0 26881 NULL
117478 +skb_zerocopy_headlen_26910 skb_zerocopy_headlen 0 26910 NULL
117479 +hhf_zalloc_26912 hhf_zalloc 1 26912 NULL
117480 +cfg80211_process_auth_26916 cfg80211_process_auth 3 26916 NULL
117481 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
117482 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
117483 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 NULL nohasharray
117484 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 &sctp_setsockopt_adaptation_layer_26935
117485 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
117486 +extract_entropy_user_26952 extract_entropy_user 3 26952 NULL nohasharray
117487 +do_trimming_26952 do_trimming 3 26952 &extract_entropy_user_26952
117488 +do_direct_IO_26979 do_direct_IO 0 26979 NULL
117489 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
117490 +ext4_convert_unwritten_extents_27064 ext4_convert_unwritten_extents 4-3-0 27064 NULL
117491 +snd_pcm_lib_period_bytes_27071 snd_pcm_lib_period_bytes 0 27071 NULL
117492 +paravirt_read_msr_27077 paravirt_read_msr 0 27077 NULL
117493 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
117494 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL nohasharray
117495 +ath9k_hw_4k_dump_eeprom_27089 ath9k_hw_4k_dump_eeprom 5-4 27089 &btmrvl_hscmd_write_27089
117496 +__devcgroup_inode_permission_27108 __devcgroup_inode_permission 0 27108 NULL
117497 +get_kernel_page_27133 get_kernel_page 0 27133 NULL
117498 +drbd_get_capacity_27141 drbd_get_capacity 0 27141 NULL
117499 +pms_capture_27142 pms_capture 4 27142 NULL
117500 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
117501 +snd_compr_calc_avail_27165 snd_compr_calc_avail 0 27165 NULL
117502 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
117503 +write_kmem_27225 write_kmem 3 27225 NULL
117504 +dbAllocAG_27228 dbAllocAG 0 27228 NULL
117505 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
117506 +ll_track_gid_seq_write_27267 ll_track_gid_seq_write 3 27267 NULL
117507 +comedi_alloc_devpriv_27272 comedi_alloc_devpriv 2 27272 NULL
117508 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
117509 +virtqueue_add_inbuf_27312 virtqueue_add_inbuf 3 27312 NULL
117510 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3-0 27332 NULL
117511 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
117512 +iwl_dbgfs_csr_write_27363 iwl_dbgfs_csr_write 3 27363 NULL
117513 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
117514 +seq_read_27411 seq_read 3 27411 NULL
117515 +ib_dma_map_sg_27413 ib_dma_map_sg 0 27413 NULL
117516 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
117517 +cypress_write_27423 cypress_write 4 27423 NULL
117518 +sddr09_read_data_27447 sddr09_read_data 3 27447 NULL
117519 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
117520 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
117521 +ip_set_get_h32_27498 ip_set_get_h32 0 27498 NULL
117522 +btrfs_get_64_27499 btrfs_get_64 0 27499 NULL
117523 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
117524 +oti_alloc_cookies_27510 oti_alloc_cookies 2 27510 NULL
117525 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
117526 +snd_sonicvibes_getdmaa_27552 snd_sonicvibes_getdmaa 0 27552 NULL
117527 +SyS_fgetxattr_27571 SyS_fgetxattr 4 27571 NULL
117528 +sco_sock_recvmsg_27572 sco_sock_recvmsg 4 27572 NULL
117529 +libipw_alloc_txb_27579 libipw_alloc_txb 1 27579 NULL
117530 +C_SYSC_mbind_27636 C_SYSC_mbind 5 27636 NULL
117531 +ocfs2_xattr_ibody_get_27642 ocfs2_xattr_ibody_get 0 27642 NULL nohasharray
117532 +read_flush_procfs_27642 read_flush_procfs 3 27642 &ocfs2_xattr_ibody_get_27642 nohasharray
117533 +nl80211_send_connect_result_27642 nl80211_send_connect_result 5-7 27642 &read_flush_procfs_27642 nohasharray
117534 +ocfs2_direct_IO_27642 ocfs2_direct_IO 4 27642 &nl80211_send_connect_result_27642
117535 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
117536 +btrfs_fallocate_27647 btrfs_fallocate 3-4 27647 NULL
117537 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
117538 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
117539 +ocfs2_extend_dir_27695 ocfs2_extend_dir 4 27695 NULL
117540 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
117541 +evm_write_key_27715 evm_write_key 3 27715 NULL
117542 +ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol_27722 ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol 3 27722 NULL
117543 +xfs_dir2_block_sfsize_27727 xfs_dir2_block_sfsize 0 27727 NULL
117544 +SyS_setsockopt_27759 SyS_setsockopt 5 27759 NULL
117545 +transport_init_session_tags_27776 transport_init_session_tags 1-2 27776 NULL
117546 +__lov_setstripe_27782 __lov_setstripe 2 27782 NULL
117547 +twl4030_set_gpio_dataout_27792 twl4030_set_gpio_dataout 1 27792 NULL
117548 +SyS_readv_27804 SyS_readv 3 27804 NULL
117549 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
117550 +hpt374_read_freq_27828 hpt374_read_freq 0 27828 NULL
117551 +init_header_complete_27833 init_header_complete 0 27833 NULL
117552 +read_profile_27859 read_profile 3 27859 NULL
117553 +sky2_pci_read16_27863 sky2_pci_read16 0 27863 NULL
117554 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
117555 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
117556 +i915_error_object_create_sized_27919 i915_error_object_create_sized 4 27919 NULL
117557 +check_mapped_name_27943 check_mapped_name 3 27943 NULL
117558 +tracing_clock_write_27961 tracing_clock_write 3 27961 NULL nohasharray
117559 +bio_next_split_27961 bio_next_split 2 27961 &tracing_clock_write_27961
117560 +security_path_chown_27966 security_path_chown 0 27966 NULL
117561 +tipc_media_addr_printf_27971 tipc_media_addr_printf 2 27971 NULL
117562 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 NULL nohasharray
117563 +device_register_27972 device_register 0 27972 &mic_rx_pkts_read_27972
117564 +compat_SyS_set_mempolicy_27975 compat_SyS_set_mempolicy 3 27975 NULL
117565 +pci_enable_device_flags_27977 pci_enable_device_flags 0 27977 NULL
117566 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
117567 +seq_get_buf_28006 seq_get_buf 0 28006 NULL
117568 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
117569 +powercap_register_zone_28028 powercap_register_zone 6 28028 NULL
117570 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
117571 +rts51x_xd_rw_28046 rts51x_xd_rw 3-4 28046 NULL
117572 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2-4 28053 NULL
117573 +pool_status_28055 pool_status 5 28055 NULL
117574 +init_rs_non_canonical_28059 init_rs_non_canonical 1 28059 NULL
117575 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
117576 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
117577 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
117578 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
117579 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
117580 +video_read_28148 video_read 3 28148 NULL
117581 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
117582 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
117583 +vread_28173 vread 0-3 28173 NULL
117584 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
117585 +counter_free_res_28187 counter_free_res 5 28187 NULL
117586 +read_disk_sb_28188 read_disk_sb 2 28188 NULL
117587 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
117588 +__qp_memcpy_from_queue_28220 __qp_memcpy_from_queue 3-4 28220 NULL
117589 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL
117590 +amd_nb_num_28228 amd_nb_num 0 28228 NULL
117591 +fuse_direct_IO_28275 fuse_direct_IO 4 28275 NULL
117592 +usemap_size_28281 usemap_size 0 28281 NULL
117593 +inline_xattr_size_28285 inline_xattr_size 0 28285 NULL
117594 +dma_map_sg_attrs_28289 dma_map_sg_attrs 0 28289 NULL
117595 +SyS_ppoll_28290 SyS_ppoll 2 28290 NULL
117596 +kstrtos16_from_user_28300 kstrtos16_from_user 2 28300 NULL
117597 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
117598 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
117599 +security_inode_link_28327 security_inode_link 0 28327 NULL
117600 +generic_write_checks_28329 generic_write_checks 0 28329 NULL
117601 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
117602 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
117603 +snapshot_write_28351 snapshot_write 3 28351 NULL
117604 +xfs_iomap_write_unwritten_28365 xfs_iomap_write_unwritten 3-2 28365 NULL
117605 +batadv_handle_tt_response_28370 batadv_handle_tt_response 4 28370 NULL
117606 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
117607 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
117608 +bypass_pwup_write_28416 bypass_pwup_write 3 28416 NULL
117609 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
117610 +ksocknal_alloc_tx_28426 ksocknal_alloc_tx 2 28426 NULL
117611 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
117612 +snd_emu10k1_efx_read_28452 snd_emu10k1_efx_read 2 28452 NULL
117613 +key_mic_failures_read_28457 key_mic_failures_read 3 28457 NULL
117614 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
117615 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
117616 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 NULL
117617 +early_init_dt_alloc_memory_arch_28528 early_init_dt_alloc_memory_arch 1 28528 NULL
117618 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
117619 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 NULL nohasharray
117620 +aio_read_events_28545 aio_read_events 3 28545 &mptctl_getiocinfo_28545 nohasharray
117621 +run_delalloc_range_28545 run_delalloc_range 3-4 28545 &aio_read_events_28545
117622 +sysfs_create_bin_file_28551 sysfs_create_bin_file 0 28551 NULL
117623 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
117624 +asymmetric_verify_28567 asymmetric_verify 3 28567 NULL
117625 +oxygen_read32_28582 oxygen_read32 0 28582 NULL
117626 +task_cgroup_path_28599 task_cgroup_path 3 28599 NULL
117627 +extract_entropy_28604 extract_entropy 5-3 28604 NULL
117628 +kfifo_unused_28612 kfifo_unused 0 28612 NULL
117629 +snd_nm256_capture_copy_28622 snd_nm256_capture_copy 3-5 28622 NULL
117630 +setup_usemap_28636 setup_usemap 3-4 28636 NULL
117631 +qib_handle_6120_hwerrors_28642 qib_handle_6120_hwerrors 3 28642 NULL
117632 +p9_fcall_alloc_28652 p9_fcall_alloc 1 28652 NULL
117633 +read_nic_io_byte_28654 read_nic_io_byte 0 28654 NULL
117634 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
117635 +SyS_setgroups16_28686 SyS_setgroups16 1 28686 NULL
117636 +kvm_mmu_get_page_28692 kvm_mmu_get_page 2 28692 NULL
117637 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
117638 +spi_execute_28736 spi_execute 5 28736 NULL
117639 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
117640 +read_file_btcoex_28743 read_file_btcoex 3 28743 NULL
117641 +max_hw_blocks_28748 max_hw_blocks 0 28748 NULL
117642 +rpc_pipe_generic_upcall_28766 rpc_pipe_generic_upcall 4 28766 NULL
117643 +ath6kl_get_num_reg_28780 ath6kl_get_num_reg 0 28780 NULL
117644 +sel_write_member_28800 sel_write_member 3 28800 NULL
117645 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
117646 +kernel_tree_alloc_28833 kernel_tree_alloc 1 28833 NULL
117647 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
117648 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
117649 +max_io_len_target_boundary_28879 max_io_len_target_boundary 0-1 28879 NULL
117650 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
117651 +da9055_group_write_28904 da9055_group_write 2-3 28904 NULL
117652 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
117653 +iwl_dbgfs_sleep_level_override_write_28925 iwl_dbgfs_sleep_level_override_write 3 28925 NULL
117654 +push_rx_28939 push_rx 3 28939 NULL
117655 +mxuport_prepare_write_buffer_28943 mxuport_prepare_write_buffer 3 28943 NULL
117656 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3-4 28963 NULL
117657 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
117658 +hash_net6_expire_28979 hash_net6_expire 4 28979 NULL
117659 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
117660 +bin_uuid_28999 bin_uuid 3 28999 NULL
117661 +fd_execute_rw_29004 fd_execute_rw 3 29004 NULL
117662 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
117663 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
117664 +btrfs_root_bytenr_29058 btrfs_root_bytenr 0 29058 NULL
117665 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
117666 +lpfc_idiag_extacc_drivr_get_29067 lpfc_idiag_extacc_drivr_get 0-3 29067 NULL
117667 +sctp_getsockopt_assoc_stats_29074 sctp_getsockopt_assoc_stats 2 29074 NULL
117668 +iwl_dbgfs_log_event_write_29088 iwl_dbgfs_log_event_write 3 29088 NULL
117669 +ccp_init_dm_workarea_29097 ccp_init_dm_workarea 3 29097 NULL
117670 +__compat_sys_preadv64_29103 __compat_sys_preadv64 3 29103 NULL
117671 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
117672 +snprintf_29125 snprintf 0 29125 NULL
117673 +iov_shorten_29130 iov_shorten 0 29130 NULL
117674 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
117675 +kvm_mmu_notifier_clear_flush_young_29154 kvm_mmu_notifier_clear_flush_young 3 29154 NULL
117676 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
117677 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL
117678 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
117679 +nvme_trans_copy_from_user_29227 nvme_trans_copy_from_user 3 29227 NULL
117680 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
117681 +recover_peb_29238 recover_peb 0 29238 NULL
117682 +evdev_handle_get_val_29242 evdev_handle_get_val 5-6 29242 NULL
117683 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
117684 +rbd_osd_req_create_29260 rbd_osd_req_create 3 29260 NULL
117685 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
117686 +ext4_fiemap_29296 ext4_fiemap 4 29296 NULL
117687 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
117688 +__fuse_get_req_29315 __fuse_get_req 2 29315 NULL
117689 +lprocfs_write_helper_29323 lprocfs_write_helper 2 29323 NULL
117690 +kvm_handle_hva_29326 kvm_handle_hva 2 29326 NULL
117691 +tun_put_user_29337 tun_put_user 5 29337 NULL
117692 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
117693 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
117694 +read_file_tx99_power_29405 read_file_tx99_power 3 29405 NULL
117695 +mempool_create_29437 mempool_create 1 29437 NULL
117696 +crypto_ahash_alignmask_29445 crypto_ahash_alignmask 0 29445 NULL
117697 +p9_client_prepare_req_29448 p9_client_prepare_req 3 29448 NULL
117698 +validate_scan_freqs_29462 validate_scan_freqs 0 29462 NULL
117699 +SyS_flistxattr_29474 SyS_flistxattr 3 29474 NULL
117700 +do_register_entry_29478 do_register_entry 4 29478 NULL
117701 +simple_strtoul_29480 simple_strtoul 0 29480 NULL
117702 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
117703 +btrfs_file_extent_disk_bytenr_29505 btrfs_file_extent_disk_bytenr 0 29505 NULL
117704 +i2c_add_adapter_29507 i2c_add_adapter 0 29507 NULL
117705 +usnic_vnic_spec_dump_29508 usnic_vnic_spec_dump 2 29508 NULL
117706 +write_file_regidx_29517 write_file_regidx 3 29517 NULL
117707 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
117708 +pci_enable_msix_29524 pci_enable_msix 0 29524 NULL
117709 +ftrace_write_29551 ftrace_write 3 29551 NULL
117710 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
117711 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
117712 +kvm_read_guest_virt_system_29569 kvm_read_guest_virt_system 4-2 29569 NULL
117713 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
117714 +security_path_chmod_29578 security_path_chmod 0 29578 NULL
117715 +iwl_dbgfs_missed_beacon_write_29586 iwl_dbgfs_missed_beacon_write 3 29586 NULL
117716 +pvr2_hdw_report_unlocked_29589 pvr2_hdw_report_unlocked 4-0 29589 NULL
117717 +dio_set_defer_completion_29599 dio_set_defer_completion 0 29599 NULL
117718 +slots_per_page_29601 slots_per_page 0 29601 NULL
117719 +osc_cached_mb_seq_write_29610 osc_cached_mb_seq_write 3 29610 NULL
117720 +nla_get_u16_29624 nla_get_u16 0 29624 NULL
117721 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
117722 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL nohasharray
117723 +spmi_controller_alloc_29654 spmi_controller_alloc 2 29654 &sctp_make_abort_user_29654
117724 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
117725 +lustre_posix_acl_xattr_2ext_29693 lustre_posix_acl_xattr_2ext 2 29693 NULL
117726 +posix_acl_from_xattr_29708 posix_acl_from_xattr 3 29708 NULL
117727 +probes_write_29711 probes_write 3 29711 NULL
117728 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
117729 +xfs_new_eof_29737 xfs_new_eof 2 29737 NULL
117730 +std_nic_write_29752 std_nic_write 3 29752 NULL
117731 +tg3_irq_count_29786 tg3_irq_count 0 29786 NULL
117732 +dbAlloc_29794 dbAlloc 0 29794 NULL
117733 +tcp_sendpage_29829 tcp_sendpage 4 29829 NULL
117734 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
117735 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
117736 +count_partial_29850 count_partial 0 29850 NULL
117737 +write_file_bool_bmps_29870 write_file_bool_bmps 3 29870 NULL
117738 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
117739 +scsi_end_request_29876 scsi_end_request 3 29876 NULL
117740 +crypto_aead_alignmask_29885 crypto_aead_alignmask 0 29885 NULL
117741 +rtw_cfg80211_indicate_sta_assoc_29897 rtw_cfg80211_indicate_sta_assoc 3 29897 NULL
117742 +lov_ost_pool_extend_29914 lov_ost_pool_extend 2 29914 NULL
117743 +write_file_queue_29922 write_file_queue 3 29922 NULL
117744 +__btrfs_getxattr_29947 __btrfs_getxattr 0 29947 NULL nohasharray
117745 +ipv6_recv_error_29947 ipv6_recv_error 3 29947 &__btrfs_getxattr_29947
117746 +arch_setup_dmar_msi_29992 arch_setup_dmar_msi 0 29992 NULL
117747 +dev_mem_write_30028 dev_mem_write 3 30028 NULL
117748 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
117749 +sysfs_add_file_mode_ns_30038 sysfs_add_file_mode_ns 0 30038 NULL
117750 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 0-4 30040 NULL
117751 +drp_wmove_30043 drp_wmove 4 30043 NULL
117752 +__pci_request_selected_regions_30058 __pci_request_selected_regions 0 30058 NULL
117753 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
117754 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
117755 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
117756 +defragment_dma_buffer_30113 defragment_dma_buffer 0 30113 NULL
117757 +spi_async_locked_30117 spi_async_locked 0 30117 NULL
117758 +u_memcpya_30139 u_memcpya 3-2 30139 NULL
117759 +dbg_port_buf_30145 dbg_port_buf 2 30145 NULL
117760 +elfcorehdr_read_30159 elfcorehdr_read 2 30159 NULL
117761 +alloc_switch_ctx_30165 alloc_switch_ctx 2 30165 NULL
117762 +expand_inode_data_30169 expand_inode_data 3-2 30169 NULL
117763 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
117764 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
117765 +__genwqe_readq_30197 __genwqe_readq 0 30197 NULL
117766 +snd_pcm_playback_forward_30201 snd_pcm_playback_forward 0-2 30201 NULL
117767 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
117768 +read_4k_modal_eeprom_30212 read_4k_modal_eeprom 3 30212 NULL
117769 +SyS_semop_30227 SyS_semop 3 30227 NULL
117770 +bitmap_file_set_bit_30228 bitmap_file_set_bit 2 30228 NULL
117771 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
117772 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL nohasharray
117773 +try_break_deleg_30271 try_break_deleg 0 30271 &isr_pci_pm_read_30271
117774 +compat_readv_30273 compat_readv 3 30273 NULL
117775 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
117776 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
117777 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
117778 +osc_contention_seconds_seq_write_30305 osc_contention_seconds_seq_write 3 30305 NULL
117779 +ext4_acl_from_disk_30320 ext4_acl_from_disk 2 30320 NULL
117780 +i8254_read_30330 i8254_read 0 30330 NULL
117781 +resource_from_user_30341 resource_from_user 3 30341 NULL
117782 +o2nm_this_node_30342 o2nm_this_node 0 30342 NULL
117783 +kstrtou32_from_user_30361 kstrtou32_from_user 2 30361 NULL
117784 +pagecache_write_begin_30364 pagecache_write_begin 0 30364 NULL
117785 +pvscsi_change_queue_depth_30365 pvscsi_change_queue_depth 2 30365 NULL
117786 +C_SYSC_readv_30369 C_SYSC_readv 3 30369 NULL
117787 +blkdev_issue_zeroout_30392 blkdev_issue_zeroout 3 30392 NULL
117788 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
117789 +get_kernel_pages_30397 get_kernel_pages 0 30397 NULL
117790 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
117791 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
117792 +lstcon_session_info_30425 lstcon_session_info 6 30425 NULL
117793 +enable_write_30456 enable_write 3 30456 NULL
117794 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
117795 +urandom_read_30462 urandom_read 3 30462 NULL
117796 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
117797 +i2c_ctrl_read_30467 i2c_ctrl_read 0 30467 NULL
117798 +adu_write_30487 adu_write 3 30487 NULL
117799 +dtim_interval_write_30489 dtim_interval_write 3 30489 NULL
117800 +batadv_send_tt_request_30493 batadv_send_tt_request 5 30493 NULL
117801 +__send_duplicate_bios_30498 __send_duplicate_bios 4 30498 NULL
117802 +memblock_virt_alloc_node_30515 memblock_virt_alloc_node 1 30515 NULL
117803 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
117804 +debug_debug2_read_30526 debug_debug2_read 3 30526 NULL
117805 +ixgbevf_acquire_msix_vectors_30559 ixgbevf_acquire_msix_vectors 2 30559 NULL
117806 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
117807 +set_le_30581 set_le 4 30581 NULL
117808 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
117809 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
117810 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
117811 +ieee80211_if_read_dot11MeshAwakeWindowDuration_30631 ieee80211_if_read_dot11MeshAwakeWindowDuration 3 30631 NULL
117812 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
117813 +mlx5_ib_alloc_fast_reg_page_list_30638 mlx5_ib_alloc_fast_reg_page_list 2 30638 NULL
117814 +SyS_listxattr_30647 SyS_listxattr 3 30647 NULL
117815 +jffs2_flash_read_30667 jffs2_flash_read 0 30667 NULL
117816 +ni_ai_fifo_read_30681 ni_ai_fifo_read 3 30681 NULL
117817 +sst_hsw_get_dsp_position_30691 sst_hsw_get_dsp_position 0 30691 NULL
117818 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
117819 +lbs_wrbbp_write_30712 lbs_wrbbp_write 3 30712 NULL
117820 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
117821 +snd_nm256_playback_silence_30727 snd_nm256_playback_silence 3-4 30727 NULL
117822 +snapshot_status_30744 snapshot_status 5 30744 NULL
117823 +fuse_conn_limit_write_30777 fuse_conn_limit_write 3 30777 NULL
117824 +__bio_alloc_30787 __bio_alloc 3 30787 NULL
117825 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
117826 +get_kobj_path_length_30831 get_kobj_path_length 0 30831 NULL
117827 +ath10k_write_fw_dbglog_30835 ath10k_write_fw_dbglog 3 30835 NULL
117828 +of_gpio_named_count_30841 of_gpio_named_count 0 30841 NULL
117829 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
117830 +wd_autoreset_write_30862 wd_autoreset_write 3 30862 NULL
117831 +ieee80211_if_fmt_dropped_frames_no_route_30884 ieee80211_if_fmt_dropped_frames_no_route 3 30884 NULL
117832 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
117833 +usnic_debugfs_buildinfo_read_30928 usnic_debugfs_buildinfo_read 3 30928 NULL
117834 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
117835 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
117836 +huge_page_mask_30981 huge_page_mask 0 30981 NULL
117837 +read_file_bt_ant_diversity_30983 read_file_bt_ant_diversity 3 30983 NULL
117838 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
117839 +ima_eventsig_init_31022 ima_eventsig_init 5 31022 NULL
117840 +template_fmt_size_31033 template_fmt_size 0 31033 NULL
117841 +do_setup_msi_irqs_31043 do_setup_msi_irqs 2 31043 NULL
117842 +stride_pg_count_31053 stride_pg_count 0-3-2-1-4-5 31053 NULL
117843 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
117844 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
117845 +proc_gid_map_write_31093 proc_gid_map_write 3 31093 NULL
117846 +depth_read_31112 depth_read 3 31112 NULL
117847 +hash_ipportnet6_expire_31118 hash_ipportnet6_expire 4 31118 NULL
117848 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
117849 +size_inside_page_31141 size_inside_page 0 31141 NULL
117850 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
117851 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
117852 +r592_read_fifo_pio_31198 r592_read_fifo_pio 3 31198 NULL
117853 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
117854 +__btrfs_free_reserved_extent_31207 __btrfs_free_reserved_extent 2 31207 NULL
117855 +cpumask_weight_31215 cpumask_weight 0 31215 NULL
117856 +__read_reg_31216 __read_reg 0 31216 NULL
117857 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
117858 +tcp_recvmsg_31238 tcp_recvmsg 4 31238 NULL
117859 +cyy_readb_31240 cyy_readb 0 31240 NULL
117860 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
117861 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
117862 +hash_netportnet4_expire_31290 hash_netportnet4_expire 4 31290 NULL
117863 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
117864 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
117865 +command_file_write_31318 command_file_write 3 31318 NULL
117866 +hwerr_crcbits_31334 hwerr_crcbits 4 31334 NULL
117867 +_regmap_raw_multi_reg_write_31336 _regmap_raw_multi_reg_write 3 31336 NULL
117868 +em28xx_init_usb_xfer_31337 em28xx_init_usb_xfer 4-6 31337 NULL
117869 +outlen_write_31358 outlen_write 3 31358 NULL
117870 +ieee80211_rx_mgmt_auth_31366 ieee80211_rx_mgmt_auth 3 31366 NULL
117871 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
117872 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3-2 31374 NULL
117873 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
117874 +inb_31388 inb 0 31388 NULL
117875 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
117876 +_sp2d_max_pg_31422 _sp2d_max_pg 0 31422 NULL
117877 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
117878 +snd_aw2_saa7146_get_hw_ptr_capture_31431 snd_aw2_saa7146_get_hw_ptr_capture 0 31431 NULL
117879 +transport_alloc_session_tags_31449 transport_alloc_session_tags 2-3 31449 NULL
117880 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
117881 +xfs_btree_get_numrecs_31477 xfs_btree_get_numrecs 0 31477 NULL
117882 +alg_setkey_31485 alg_setkey 3 31485 NULL
117883 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
117884 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
117885 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
117886 +hidraw_write_31536 hidraw_write 3 31536 NULL
117887 +usbvision_read_31555 usbvision_read 3 31555 NULL
117888 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
117889 +get_max_inline_xattr_value_size_31578 get_max_inline_xattr_value_size 0 31578 NULL
117890 +osst_write_31581 osst_write 3 31581 NULL
117891 +snd_compr_get_avail_31584 snd_compr_get_avail 0 31584 NULL
117892 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
117893 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 NULL nohasharray
117894 +memblock_virt_alloc_nopanic_31617 memblock_virt_alloc_nopanic 1 31617 &arvo_sysfs_read_31617
117895 +usnic_ib_dump_vf_31623 usnic_ib_dump_vf 3 31623 NULL
117896 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
117897 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
117898 +xfer_secondary_pool_31661 xfer_secondary_pool 2 31661 NULL
117899 +__lgread_31668 __lgread 4 31668 NULL
117900 +copy_from_user_nmi_31672 copy_from_user_nmi 3-0 31672 NULL
117901 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
117902 +fst_recover_rx_error_31687 fst_recover_rx_error 3 31687 NULL
117903 +rs_pretty_print_rate_31727 rs_pretty_print_rate 0 31727 NULL
117904 +lu_buf_check_and_grow_31735 lu_buf_check_and_grow 2 31735 NULL nohasharray
117905 +utf16s_to_utf8s_31735 utf16s_to_utf8s 0 31735 &lu_buf_check_and_grow_31735
117906 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3-2 31741 NULL
117907 +input_abs_get_max_31742 input_abs_get_max 0 31742 NULL nohasharray
117908 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 &input_abs_get_max_31742
117909 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
117910 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
117911 +SyS_lsetxattr_31766 SyS_lsetxattr 4 31766 NULL
117912 +osync_buffers_list_31789 osync_buffers_list 0 31789 NULL
117913 +usblp_cache_device_id_string_31790 usblp_cache_device_id_string 0 31790 NULL
117914 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
117915 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
117916 +data_write_31805 data_write 3 31805 NULL
117917 +SyS_msgsnd_31814 SyS_msgsnd 3 31814 NULL
117918 +strnlen_user_31815 strnlen_user 0-2 31815 NULL
117919 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
117920 +clone_bio_31854 clone_bio 4-3 31854 NULL
117921 +SyS_ppoll_31855 SyS_ppoll 2 31855 NULL
117922 +iwl_dbgfs_disable_ht40_write_31876 iwl_dbgfs_disable_ht40_write 3 31876 NULL
117923 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
117924 +ddb_output_write_31902 ddb_output_write 3-0 31902 NULL
117925 +xattr_permission_31907 xattr_permission 0 31907 NULL
117926 +lu_buf_realloc_31915 lu_buf_realloc 2 31915 NULL
117927 +new_dir_31919 new_dir 3 31919 NULL
117928 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
117929 +era_status_31934 era_status 5 31934 NULL
117930 +SYSC_sethostname_31940 SYSC_sethostname 2 31940 NULL
117931 +read_mem_31942 read_mem 3 31942 NULL nohasharray
117932 +iov_iter_copy_from_user_31942 iov_iter_copy_from_user 4-0 31942 &read_mem_31942
117933 +ext4_zero_range_31944 ext4_zero_range 3-2 31944 NULL
117934 +vb2_write_31948 vb2_write 3 31948 NULL
117935 +pvr2_ctrl_get_valname_31951 pvr2_ctrl_get_valname 4 31951 NULL
117936 +regcache_rbtree_sync_31964 regcache_rbtree_sync 2 31964 NULL
117937 +iwl_rx_packet_payload_len_31965 iwl_rx_packet_payload_len 0 31965 NULL
117938 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
117939 +iblock_execute_rw_31982 iblock_execute_rw 3 31982 NULL nohasharray
117940 +vx_read_status_31982 vx_read_status 0 31982 &iblock_execute_rw_31982
117941 +find_next_zero_bit_31990 find_next_zero_bit 0 31990 NULL
117942 +lustre_acl_xattr_merge2posix_31992 lustre_acl_xattr_merge2posix 2 31992 NULL
117943 +sysfs_create_file_31996 sysfs_create_file 0 31996 NULL
117944 +calc_hmac_32010 calc_hmac 3 32010 NULL
117945 +aead_len_32021 aead_len 0 32021 NULL nohasharray
117946 +aer_init_32021 aer_init 0 32021 &aead_len_32021
117947 +stk_read_32038 stk_read 3 32038 NULL
117948 +SYSC_llistxattr_32061 SYSC_llistxattr 3 32061 NULL
117949 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
117950 +cow_file_range_inline_32091 cow_file_range_inline 3 32091 NULL
117951 +bio_alloc_32095 bio_alloc 2 32095 NULL
117952 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
117953 +disk_status_32120 disk_status 4 32120 NULL
117954 +kobject_add_internal_32133 kobject_add_internal 0 32133 NULL
117955 +venus_link_32165 venus_link 5 32165 NULL
117956 +do_writepages_32173 do_writepages 0 32173 NULL
117957 +del_ptr_32197 del_ptr 4 32197 NULL
117958 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
117959 +riva_get_cmap_len_32218 riva_get_cmap_len 0 32218 NULL
117960 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
117961 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
117962 +ocfs2_xattr_find_entry_32260 ocfs2_xattr_find_entry 0 32260 NULL
117963 +kvm_set_spte_hva_32312 kvm_set_spte_hva 2 32312 NULL
117964 +cas_calc_tabort_32316 cas_calc_tabort 0 32316 NULL
117965 +SyS_select_32319 SyS_select 1 32319 NULL
117966 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
117967 +nl80211_send_mlme_event_32337 nl80211_send_mlme_event 4 32337 NULL
117968 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
117969 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL nohasharray
117970 +rx_streaming_always_write_32357 rx_streaming_always_write 3 32357 &dispatch_ioctl_32357
117971 +sel_read_initcon_32362 sel_read_initcon 3 32362 NULL
117972 +ll_setxattr_common_32398 ll_setxattr_common 4 32398 NULL
117973 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
117974 +vmci_qp_alloc_32405 vmci_qp_alloc 5-3 32405 NULL
117975 +snd_pcm_sync_ptr_32461 snd_pcm_sync_ptr 0 32461 NULL
117976 +cache_status_32462 cache_status 5 32462 NULL
117977 +fill_readbuf_32464 fill_readbuf 3 32464 NULL
117978 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
117979 +bypass_pwoff_write_32499 bypass_pwoff_write 3 32499 NULL
117980 +mdc_pinger_recov_seq_write_32510 mdc_pinger_recov_seq_write 3 32510 NULL
117981 +ctrl_std_val_to_sym_32516 ctrl_std_val_to_sym 5 32516 NULL
117982 +disconnect_32521 disconnect 4 32521 NULL
117983 +qsfp_read_32522 qsfp_read 0-2-4 32522 NULL
117984 +ilo_read_32531 ilo_read 3 32531 NULL
117985 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
117986 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
117987 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
117988 +osc_iocontrol_32565 osc_iocontrol 3 32565 NULL
117989 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
117990 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
117991 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
117992 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
117993 +__pci_request_region_32618 __pci_request_region 0 32618 NULL
117994 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
117995 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
117996 +kvmalloc_32646 kvmalloc 1 32646 NULL
117997 +ib_sg_dma_len_32649 ib_sg_dma_len 0 32649 NULL
117998 +generic_readlink_32654 generic_readlink 3 32654 NULL
117999 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
118000 +compat_SyS_preadv_32679 compat_SyS_preadv 3 32679 NULL
118001 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
118002 +rt2x00debug_read_queue_dump_32712 rt2x00debug_read_queue_dump 3 32712 NULL
118003 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
118004 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
118005 +vmci_transport_dgram_dequeue_32775 vmci_transport_dgram_dequeue 4 32775 NULL
118006 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
118007 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
118008 +sta_tx_latency_stat_read_32862 sta_tx_latency_stat_read 3 32862 NULL
118009 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
118010 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 NULL nohasharray
118011 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 &ath6kl_usb_submit_ctrl_in_32880
118012 +vp702x_usb_inout_cmd_32884 vp702x_usb_inout_cmd 4-6 32884 NULL
118013 +tipc_link_iovec_xmit_fast_32913 tipc_link_iovec_xmit_fast 3 32913 NULL nohasharray
118014 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 &tipc_link_iovec_xmit_fast_32913
118015 +zlib_inflate_workspacesize_32927 zlib_inflate_workspacesize 0 32927 NULL
118016 +rmap_recycle_32938 rmap_recycle 3 32938 NULL
118017 +compat_filldir_32999 compat_filldir 3 32999 NULL
118018 +SyS_syslog_33007 SyS_syslog 3 33007 NULL
118019 +br_multicast_set_hash_max_33012 br_multicast_set_hash_max 2 33012 NULL
118020 +write_file_bt_ant_diversity_33019 write_file_bt_ant_diversity 3 33019 NULL
118021 +snd_pcm_prepare_33036 snd_pcm_prepare 0 33036 NULL
118022 +mic_virtio_copy_to_user_33048 mic_virtio_copy_to_user 3 33048 NULL
118023 +SYSC_lgetxattr_33049 SYSC_lgetxattr 4 33049 NULL
118024 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
118025 +ebt_compat_match_offset_33053 ebt_compat_match_offset 0-2 33053 NULL
118026 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
118027 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
118028 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
118029 +alloc_tio_33077 alloc_tio 3 33077 NULL
118030 +acl_permission_check_33083 acl_permission_check 0 33083 NULL
118031 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
118032 +notify_change_33143 notify_change 0 33143 NULL
118033 +SyS_poll_33152 SyS_poll 2 33152 NULL
118034 +_pci_add_cap_save_buffer_33153 _pci_add_cap_save_buffer 4 33153 NULL
118035 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
118036 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 3-2 33204 NULL
118037 +pp_read_33210 pp_read 3 33210 NULL
118038 +xfs_file_aio_write_33234 xfs_file_aio_write 4 33234 NULL
118039 +snd_pcm_plug_client_size_33267 snd_pcm_plug_client_size 0-2 33267 NULL
118040 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
118041 +sync_pt_create_33282 sync_pt_create 2 33282 NULL
118042 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
118043 +isku_sysfs_read_keys_easyzone_33318 isku_sysfs_read_keys_easyzone 6 33318 NULL
118044 +vx_send_irq_dsp_33329 vx_send_irq_dsp 0 33329 NULL
118045 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
118046 +lov_stripesize_seq_write_33353 lov_stripesize_seq_write 3 33353 NULL
118047 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
118048 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
118049 +pvscsi_allocate_sg_33357 pvscsi_allocate_sg 0 33357 NULL
118050 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
118051 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
118052 +scsi_varlen_cdb_length_33385 scsi_varlen_cdb_length 0 33385 NULL
118053 +nvc0_ram_create__33391 nvc0_ram_create_ 5 33391 NULL
118054 +ocfs2_allocate_unwritten_extents_33394 ocfs2_allocate_unwritten_extents 2-3 33394 NULL
118055 +cfs_trace_copyin_string_33396 cfs_trace_copyin_string 4 33396 NULL
118056 +snd_pcm_capture_ioctl1_33408 snd_pcm_capture_ioctl1 0 33408 NULL
118057 +hash_netiface6_expire_33421 hash_netiface6_expire 4 33421 NULL
118058 +dis_tap_write_33426 dis_tap_write 3 33426 NULL
118059 +message_stats_list_33440 message_stats_list 5 33440 NULL
118060 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
118061 +create_entry_33479 create_entry 2 33479 NULL
118062 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
118063 +res_counter_read_33499 res_counter_read 4 33499 NULL
118064 +hash_netnet4_expire_33500 hash_netnet4_expire 4 33500 NULL
118065 +fb_read_33506 fb_read 3 33506 NULL
118066 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
118067 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
118068 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
118069 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
118070 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL nohasharray
118071 +osc_max_rpcs_in_flight_seq_write_33539 osc_max_rpcs_in_flight_seq_write 3 33539 &tomoyo_read_self_33539
118072 +count_subheaders_33591 count_subheaders 0 33591 NULL
118073 +scsi_execute_33596 scsi_execute 5 33596 NULL
118074 +comedi_buf_write_n_allocated_33604 comedi_buf_write_n_allocated 0 33604 NULL
118075 +xt_compat_target_offset_33608 xt_compat_target_offset 0 33608 NULL
118076 +usb_gstrings_attach_33615 usb_gstrings_attach 3 33615 NULL nohasharray
118077 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 &usb_gstrings_attach_33615
118078 +stride_page_count_33641 stride_page_count 2 33641 NULL
118079 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
118080 +inw_p_33668 inw_p 0 33668 NULL
118081 +arp_hdr_len_33671 arp_hdr_len 0 33671 NULL
118082 +i2c_hid_alloc_buffers_33673 i2c_hid_alloc_buffers 2 33673 NULL
118083 +submit_one_bio_33683 submit_one_bio 0 33683 NULL
118084 +nv50_disp_dmac_create__33696 nv50_disp_dmac_create_ 6 33696 NULL
118085 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 NULL
118086 +tipc_link_stats_33716 tipc_link_stats 3 33716 NULL
118087 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
118088 +write_file_spectral_count_33723 write_file_spectral_count 3 33723 NULL
118089 +read_file_node_recv_33729 read_file_node_recv 3 33729 NULL
118090 +rtw_cbuf_alloc23a_33740 rtw_cbuf_alloc23a 1 33740 NULL
118091 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
118092 +hashtab_create_33769 hashtab_create 3 33769 NULL
118093 +i8042_create_aux_port_33777 i8042_create_aux_port 0 33777 NULL
118094 +if_sdio_read_rx_len_33800 if_sdio_read_rx_len 0 33800 NULL
118095 +filter_write_33819 filter_write 3 33819 NULL
118096 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
118097 +scrub_setup_recheck_block_33831 scrub_setup_recheck_block 5-4 33831 NULL
118098 +ext4_journal_extend_33835 ext4_journal_extend 2 33835 NULL
118099 +snd_pcm_action_nonatomic_33844 snd_pcm_action_nonatomic 0 33844 NULL
118100 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
118101 +get_user_pages_33908 get_user_pages 0 33908 NULL
118102 +sg_nents_33909 sg_nents 0 33909 NULL
118103 +ath6kl_roam_mode_write_33912 ath6kl_roam_mode_write 3 33912 NULL
118104 +queue_logical_block_size_33918 queue_logical_block_size 0 33918 NULL
118105 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
118106 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
118107 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
118108 +__proc_dump_kernel_33954 __proc_dump_kernel 5 33954 NULL
118109 +btrfs_delalloc_reserve_metadata_33963 btrfs_delalloc_reserve_metadata 0 33963 NULL
118110 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
118111 +lbs_lowrssi_write_34025 lbs_lowrssi_write 3 34025 NULL
118112 +ppp_write_34034 ppp_write 3 34034 NULL
118113 +tty_insert_flip_string_34042 tty_insert_flip_string 3-0 34042 NULL
118114 +calc_linear_pos_34067 calc_linear_pos 0-4 34067 NULL
118115 +memcg_update_all_caches_34068 memcg_update_all_caches 1 34068 NULL
118116 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
118117 +__irq_domain_add_34101 __irq_domain_add 2 34101 NULL
118118 +proc_scsi_host_write_34107 proc_scsi_host_write 3 34107 NULL
118119 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
118120 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2-0 34135 NULL
118121 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
118122 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
118123 +skb_to_sgvec_34171 skb_to_sgvec 0 34171 NULL
118124 +rsi_debug_zone_write_34206 rsi_debug_zone_write 3 34206 NULL
118125 +ext4_da_write_begin_34215 ext4_da_write_begin 3-4 34215 NULL
118126 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
118127 +device_private_init_34279 device_private_init 0 34279 NULL
118128 +ext4_get_groups_count_34324 ext4_get_groups_count 0 34324 NULL
118129 +pcpu_need_to_extend_34326 pcpu_need_to_extend 0 34326 NULL nohasharray
118130 +iov_iter_single_seg_count_34326 iov_iter_single_seg_count 0 34326 &pcpu_need_to_extend_34326
118131 +crypto_ablkcipher_ivsize_34363 crypto_ablkcipher_ivsize 0 34363 NULL nohasharray
118132 +sync_page_io_34363 sync_page_io 3 34363 &crypto_ablkcipher_ivsize_34363
118133 +rngapi_reset_34366 rngapi_reset 3 34366 NULL
118134 +_iwl_dbgfs_low_latency_write_34378 _iwl_dbgfs_low_latency_write 3 34378 NULL nohasharray
118135 +ea_read_34378 ea_read 0 34378 &_iwl_dbgfs_low_latency_write_34378
118136 +fuse_send_read_34379 fuse_send_read 4 34379 NULL
118137 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
118138 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
118139 +read_rbu_image_type_34387 read_rbu_image_type 6 34387 NULL
118140 +iwl_calib_set_34400 iwl_calib_set 3 34400 NULL nohasharray
118141 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 &iwl_calib_set_34400
118142 +wd_exp_mode_write_34407 wd_exp_mode_write 3 34407 NULL
118143 +nl80211_send_disassoc_34424 nl80211_send_disassoc 4 34424 NULL
118144 +__extent_read_full_page_34437 __extent_read_full_page 0 34437 NULL
118145 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
118146 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
118147 +skcipher_sndbuf_34476 skcipher_sndbuf 0 34476 NULL
118148 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
118149 +security_inode_permission_34488 security_inode_permission 0 34488 NULL
118150 +SyS_pwritev_34494 SyS_pwritev 3 34494 NULL
118151 +qp_alloc_res_34496 qp_alloc_res 5 34496 NULL
118152 +lu_buf_check_and_alloc_34505 lu_buf_check_and_alloc 2 34505 NULL
118153 +tracing_stats_read_34537 tracing_stats_read 3 34537 NULL nohasharray
118154 +ext4_fallocate_34537 ext4_fallocate 4-3 34537 &tracing_stats_read_34537
118155 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4-0 34547 NULL
118156 +dbBackSplit_34561 dbBackSplit 0 34561 NULL
118157 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL nohasharray
118158 +self_check_peb_ec_hdr_34564 self_check_peb_ec_hdr 0 34564 &alloc_ieee80211_rsl_34564
118159 +lov_stripecount_seq_write_34582 lov_stripecount_seq_write 3 34582 NULL
118160 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
118161 +inet6_ifla6_size_34591 inet6_ifla6_size 0 34591 NULL
118162 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL nohasharray
118163 +cw1200_queue_init_34599 cw1200_queue_init 4 34599 &ceph_msgpool_init_34599
118164 +bio_integrity_bytes_34602 bio_integrity_bytes 2 34602 NULL
118165 +__jffs2_ref_totlen_34609 __jffs2_ref_totlen 0 34609 NULL nohasharray
118166 +mtd_write_34609 mtd_write 0 34609 &__jffs2_ref_totlen_34609
118167 +__cfg80211_disconnected_34622 __cfg80211_disconnected 3 34622 NULL
118168 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
118169 +kvm_set_spte_hva_34671 kvm_set_spte_hva 2 34671 NULL
118170 +sleep_auth_write_34676 sleep_auth_write 3 34676 NULL
118171 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
118172 +batadv_tvlv_realloc_packet_buff_34688 batadv_tvlv_realloc_packet_buff 3-4 34688 NULL
118173 +port_print_34704 port_print 3 34704 NULL
118174 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
118175 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
118176 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
118177 +lsm_alloc_plain_34755 lsm_alloc_plain 1 34755 NULL
118178 +bootmode_store_34762 bootmode_store 4 34762 NULL
118179 +device_add_34766 device_add 0 34766 NULL
118180 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
118181 +SYSC_keyctl_34800 SYSC_keyctl 4 34800 NULL
118182 +can_nocow_extent_34801 can_nocow_extent 2 34801 NULL
118183 +drbd_get_max_capacity_34804 drbd_get_max_capacity 0 34804 NULL
118184 +ll_setxattr_34806 ll_setxattr 4 34806 NULL
118185 +file_page_index_34820 file_page_index 0-2 34820 NULL
118186 +bio_segments_34832 bio_segments 0 34832 NULL
118187 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
118188 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
118189 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
118190 +usb_serial_generic_prepare_write_buffer_34857 usb_serial_generic_prepare_write_buffer 3 34857 NULL
118191 +ieee80211_if_read_txpower_34871 ieee80211_if_read_txpower 3 34871 NULL
118192 +msg_print_text_34889 msg_print_text 0 34889 NULL
118193 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
118194 +si476x_radio_read_rsq_primary_blob_34916 si476x_radio_read_rsq_primary_blob 3 34916 NULL
118195 +__inode_permission_34925 __inode_permission 0 34925 NULL nohasharray
118196 +btrfs_super_chunk_root_34925 btrfs_super_chunk_root 0 34925 &__inode_permission_34925
118197 +ceph_aio_write_34930 ceph_aio_write 4 34930 NULL
118198 +sec_flags2str_34933 sec_flags2str 3 34933 NULL
118199 +snd_info_entry_read_34938 snd_info_entry_read 3 34938 NULL
118200 +do_add_page_to_bio_34974 do_add_page_to_bio 2-10 34974 NULL
118201 +schedule_erase_34996 schedule_erase 0 34996 NULL
118202 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
118203 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
118204 +rtw_cfg80211_rx_p2p_action_public_35010 rtw_cfg80211_rx_p2p_action_public 3 35010 NULL
118205 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
118206 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
118207 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
118208 +__kfifo_uint_must_check_helper_35097 __kfifo_uint_must_check_helper 0-1 35097 NULL
118209 +capi_write_35104 capi_write 3 35104 NULL nohasharray
118210 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
118211 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
118212 +message_stats_print_35158 message_stats_print 6 35158 NULL
118213 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
118214 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
118215 +compat_SyS_pselect6_35203 compat_SyS_pselect6 1 35203 NULL
118216 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
118217 +security_key_getsecurity_35218 security_key_getsecurity 0 35218 NULL nohasharray
118218 +striped_read_35218 striped_read 0-2 35218 &security_key_getsecurity_35218
118219 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
118220 +set_fd_set_35249 set_fd_set 1 35249 NULL
118221 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
118222 +dis_disc_write_35265 dis_disc_write 3 35265 NULL
118223 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
118224 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
118225 +i2o_block_end_request_35282 i2o_block_end_request 3 35282 NULL
118226 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
118227 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3-0 35311 NULL nohasharray
118228 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 &__btrfs_buffered_write_35311
118229 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
118230 +sta_tx_latency_stat_write_35323 sta_tx_latency_stat_write 3 35323 NULL
118231 +ieee80211_if_fmt_ap_power_level_35347 ieee80211_if_fmt_ap_power_level 3 35347 NULL
118232 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
118233 +ieee80211_rx_mgmt_deauth_35351 ieee80211_rx_mgmt_deauth 3 35351 NULL
118234 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
118235 +read_kmem_35372 read_kmem 3 35372 NULL
118236 +SyS_getxattr_35408 SyS_getxattr 4 35408 NULL
118237 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
118238 +iwl_dbgfs_drv_rx_stats_read_35430 iwl_dbgfs_drv_rx_stats_read 3 35430 NULL
118239 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
118240 +efx_mcdi_rpc_async_quiet_35460 efx_mcdi_rpc_async_quiet 4-5 35460 NULL
118241 +macvtap_do_read_35475 macvtap_do_read 3 35475 NULL
118242 +fiemap_prepare_and_copy_exts_35494 fiemap_prepare_and_copy_exts 5 35494 NULL
118243 +btrfs_prealloc_file_range_trans_35500 btrfs_prealloc_file_range_trans 4 35500 NULL
118244 +async_setkey_35521 async_setkey 3 35521 NULL
118245 +__filemap_fdatawrite_range_35528 __filemap_fdatawrite_range 0 35528 NULL
118246 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
118247 +pstore_mkfile_35536 pstore_mkfile 7 35536 NULL
118248 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
118249 +ocfs2_write_zero_page_35539 ocfs2_write_zero_page 3 35539 NULL
118250 +ibnl_put_attr_35541 ibnl_put_attr 3 35541 NULL
118251 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
118252 +ext4_blocks_for_truncate_35579 ext4_blocks_for_truncate 0 35579 NULL
118253 +ext2_acl_from_disk_35580 ext2_acl_from_disk 2 35580 NULL
118254 +spk_msg_set_35586 spk_msg_set 3 35586 NULL
118255 +kernel_readv_35617 kernel_readv 3 35617 NULL
118256 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
118257 +pci_request_regions_35635 pci_request_regions 0 35635 NULL
118258 +ptlrpcd_steal_rqset_35637 ptlrpcd_steal_rqset 0 35637 NULL
118259 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
118260 +rdmaltWithLock_35669 rdmaltWithLock 0 35669 NULL
118261 +SYSC_pwritev_35690 SYSC_pwritev 3 35690 NULL
118262 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
118263 +md_super_write_35703 md_super_write 4 35703 NULL
118264 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
118265 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
118266 +pvr2_hdw_cpufw_get_35824 pvr2_hdw_cpufw_get 0-4-2 35824 NULL
118267 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
118268 +vx_query_hbuffer_size_35859 vx_query_hbuffer_size 0 35859 NULL
118269 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
118270 +fls64_35862 fls64 0 35862 NULL
118271 +kvm_dirty_bitmap_bytes_35886 kvm_dirty_bitmap_bytes 0 35886 NULL
118272 +ieee80211_if_fmt_dot11MeshRetryTimeout_35890 ieee80211_if_fmt_dot11MeshRetryTimeout 3 35890 NULL
118273 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
118274 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
118275 +rbio_nr_pages_35916 rbio_nr_pages 0-1-2 35916 NULL
118276 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
118277 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
118278 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
118279 +ext_rts51x_sd_execute_write_data_35971 ext_rts51x_sd_execute_write_data 9 35971 NULL
118280 +generic_ocp_read_35974 generic_ocp_read 3 35974 NULL nohasharray
118281 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 &generic_ocp_read_35974
118282 +acl_alloc_35979 acl_alloc 1 35979 NULL
118283 +device_add_class_symlinks_35985 device_add_class_symlinks 0 35985 NULL
118284 +kuc_alloc_35998 kuc_alloc 1 35998 NULL nohasharray
118285 +write_file_antenna_35998 write_file_antenna 3 35998 &kuc_alloc_35998
118286 +scsi_transfer_length_36011 scsi_transfer_length 0 36011 NULL
118287 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
118288 +ubi_eba_write_leb_36029 ubi_eba_write_leb 0 36029 NULL
118289 +__videobuf_alloc_36031 __videobuf_alloc 1 36031 NULL
118290 +account_shadowed_36048 account_shadowed 2 36048 NULL
118291 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
118292 +snd_pcm_playback_hw_avail_36061 snd_pcm_playback_hw_avail 0 36061 NULL
118293 +write_emulate_36065 write_emulate 2-4 36065 NULL
118294 +stack_max_size_write_36068 stack_max_size_write 3 36068 NULL
118295 +radeon_vm_num_pdes_36070 radeon_vm_num_pdes 0 36070 NULL
118296 +ieee80211_if_fmt_peer_36071 ieee80211_if_fmt_peer 3 36071 NULL
118297 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
118298 +snd_pcm_plug_read_transfer_36080 snd_pcm_plug_read_transfer 0-3 36080 NULL
118299 +mtip_hw_read_device_status_36082 mtip_hw_read_device_status 3 36082 NULL
118300 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
118301 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
118302 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
118303 +twl_set_36154 twl_set 2 36154 NULL
118304 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
118305 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
118306 +SyS_kexec_load_36176 SyS_kexec_load 2 36176 NULL
118307 +ramoops_init_przs_36199 ramoops_init_przs 4 36199 NULL
118308 +SYSC_sched_getaffinity_36208 SYSC_sched_getaffinity 2 36208 NULL
118309 +SYSC_process_vm_readv_36216 SYSC_process_vm_readv 3-5 36216 NULL
118310 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
118311 +rtw_cfg80211_set_wpa_ie_36236 rtw_cfg80211_set_wpa_ie 3 36236 NULL
118312 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
118313 +SYSC_getxattr_36242 SYSC_getxattr 4 36242 NULL
118314 +vmsplice_to_user_36245 vmsplice_to_user 3 36245 NULL nohasharray
118315 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 &vmsplice_to_user_36245
118316 +cfs_hash_buckets_realloc_36276 cfs_hash_buckets_realloc 4 36276 NULL nohasharray
118317 +usb_buffer_alloc_36276 usb_buffer_alloc 2 36276 &cfs_hash_buckets_realloc_36276
118318 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
118319 +crypto_shash_digestsize_36284 crypto_shash_digestsize 0 36284 NULL
118320 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
118321 +cfg80211_rx_mlme_mgmt_36306 cfg80211_rx_mlme_mgmt 3 36306 NULL
118322 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
118323 +__compat_sys_pwritev64_36328 __compat_sys_pwritev64 3 36328 NULL nohasharray
118324 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 &__compat_sys_pwritev64_36328
118325 +lc_create_36332 lc_create 4 36332 NULL
118326 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
118327 +isku_sysfs_read_key_mask_36343 isku_sysfs_read_key_mask 6 36343 NULL
118328 +ath6kl_regwrite_write_36351 ath6kl_regwrite_write 3 36351 NULL
118329 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL
118330 +to_sector_36361 to_sector 0-1 36361 NULL
118331 +tunables_read_36385 tunables_read 3 36385 NULL
118332 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
118333 +sierra_write_36402 sierra_write 4 36402 NULL
118334 +SyS_sethostname_36417 SyS_sethostname 2 36417 NULL
118335 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
118336 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
118337 +SyS_process_vm_writev_36476 SyS_process_vm_writev 3-5 36476 NULL
118338 +lock_and_cleanup_extent_if_need_36480 lock_and_cleanup_extent_if_need 0 36480 NULL
118339 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
118340 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 NULL nohasharray
118341 +ip6_append_data_36490 ip6_append_data 4 36490 &tx_tx_checksum_result_read_36490
118342 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
118343 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
118344 +_iwl_dbgfs_fw_nmi_write_36515 _iwl_dbgfs_fw_nmi_write 3 36515 NULL
118345 +get_param_l_36518 get_param_l 0 36518 NULL
118346 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
118347 +crypto_aead_authsize_36537 crypto_aead_authsize 0 36537 NULL
118348 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
118349 +__kfifo_to_user_36555 __kfifo_to_user 3-0 36555 NULL
118350 +btrfs_get_token_64_36572 btrfs_get_token_64 0 36572 NULL
118351 +__erst_read_36579 __erst_read 0 36579 NULL
118352 +put_cmsg_36589 put_cmsg 4 36589 NULL
118353 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
118354 +vxge_config_vpaths_36636 vxge_config_vpaths 0 36636 NULL
118355 +convert_extent_item_v0_36645 convert_extent_item_v0 4 36645 NULL
118356 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
118357 +lpfc_idiag_extacc_alloc_get_36648 lpfc_idiag_extacc_alloc_get 0-3 36648 NULL
118358 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
118359 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
118360 +xillybus_read_36678 xillybus_read 3 36678 NULL
118361 +gsmtty_write_36702 gsmtty_write 3 36702 NULL
118362 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4-0 36740 NULL
118363 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
118364 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
118365 +i40e_init_lan_hmc_36796 i40e_init_lan_hmc 5-4-3-2 36796 NULL
118366 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
118367 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
118368 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
118369 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
118370 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
118371 +cm_write_36858 cm_write 3 36858 NULL
118372 +tipc_link_iovec_long_xmit_36871 tipc_link_iovec_long_xmit 3 36871 NULL nohasharray
118373 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 &tipc_link_iovec_long_xmit_36871
118374 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
118375 +raid56_parity_write_36877 raid56_parity_write 5 36877 NULL
118376 +__btrfs_map_block_36883 __btrfs_map_block 3 36883 NULL
118377 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
118378 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
118379 +OS_kmalloc_36909 OS_kmalloc 1 36909 NULL
118380 +il4965_rs_sta_dbgfs_scale_table_write_36979 il4965_rs_sta_dbgfs_scale_table_write 3 36979 NULL
118381 +drbd_new_dev_size_36998 drbd_new_dev_size 0-3 36998 NULL
118382 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
118383 +setxattr_37006 setxattr 4 37006 NULL
118384 +command_file_read_37038 command_file_read 3 37038 NULL
118385 +figure_loop_size_37051 figure_loop_size 2-3 37051 NULL
118386 +qp_broker_create_37053 qp_broker_create 6-5 37053 NULL nohasharray
118387 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 &qp_broker_create_37053
118388 +_iwl_dbgfs_bcast_filters_macs_write_37069 _iwl_dbgfs_bcast_filters_macs_write 3 37069 NULL
118389 +SYSC_setxattr_37078 SYSC_setxattr 4 37078 NULL
118390 +parse_command_37079 parse_command 2 37079 NULL
118391 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
118392 +tun_get_user_37094 tun_get_user 5 37094 NULL
118393 +has_wrprotected_page_37123 has_wrprotected_page 2-3 37123 NULL
118394 +snd_hda_get_conn_list_37132 snd_hda_get_conn_list 0 37132 NULL
118395 +mtt_free_res_37144 mtt_free_res 5 37144 NULL
118396 +msg_word_37164 msg_word 0 37164 NULL
118397 +f2fs_direct_IO_37167 f2fs_direct_IO 4 37167 NULL
118398 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
118399 +forced_ps_write_37209 forced_ps_write 3 37209 NULL
118400 +crypto_shash_descsize_37212 crypto_shash_descsize 0 37212 NULL nohasharray
118401 +ext4_ind_direct_IO_37212 ext4_ind_direct_IO 4-0 37212 &crypto_shash_descsize_37212
118402 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
118403 +__do_replace_37227 __do_replace 5 37227 NULL
118404 +iwl_dbgfs_d3_sram_read_37237 iwl_dbgfs_d3_sram_read 3 37237 NULL
118405 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL
118406 +prot_queue_del_37258 prot_queue_del 0 37258 NULL
118407 +exofs_max_io_pages_37263 exofs_max_io_pages 0-2 37263 NULL
118408 +_iwl_dbgfs_fw_restart_write_37270 _iwl_dbgfs_fw_restart_write 3 37270 NULL
118409 +request_threaded_irq_37303 request_threaded_irq 0 37303 NULL
118410 +ieee80211_if_read_power_mode_37305 ieee80211_if_read_power_mode 3 37305 NULL
118411 +ext3_direct_IO_37308 ext3_direct_IO 4 37308 NULL
118412 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
118413 +tipc_send_37315 tipc_send 3 37315 NULL
118414 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL nohasharray
118415 +bnx2x_vf_fill_fw_str_37327 bnx2x_vf_fill_fw_str 3 37327 &l2cap_create_connless_pdu_37327
118416 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
118417 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
118418 +security_inode_getsecurity_37354 security_inode_getsecurity 0 37354 NULL
118419 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
118420 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
118421 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4-0 37428 NULL
118422 +iwl_print_last_event_logs_37433 iwl_print_last_event_logs 0-7-9 37433 NULL
118423 +fru_alloc_37442 fru_alloc 1 37442 NULL
118424 +tcp_established_options_37450 tcp_established_options 0 37450 NULL
118425 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
118426 +get_est_timing_37484 get_est_timing 0 37484 NULL
118427 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
118428 +bitmap_dirty_bits_37503 bitmap_dirty_bits 2 37503 NULL
118429 +osc_active_seq_write_37514 osc_active_seq_write 3 37514 NULL
118430 +bdev_writeseg_37519 bdev_writeseg 2-3 37519 NULL
118431 +xz_dec_test_write_37527 xz_dec_test_write 3 37527 NULL
118432 +fault_inject_read_37534 fault_inject_read 3 37534 NULL
118433 +hdr_size_37536 hdr_size 0 37536 NULL
118434 +extent_map_end_37550 extent_map_end 0 37550 NULL
118435 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL
118436 +fat_cont_expand_37552 fat_cont_expand 0 37552 NULL
118437 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
118438 +qla2x00_debounce_register_37597 qla2x00_debounce_register 0 37597 NULL
118439 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
118440 +SYSC_mbind_37622 SYSC_mbind 5 37622 NULL
118441 +SyS_mbind_37638 SyS_mbind 5 37638 NULL
118442 +may_delete_37656 may_delete 0 37656 NULL
118443 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
118444 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 NULL nohasharray
118445 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 &vmw_framebuffer_dmabuf_dirty_37661
118446 +SYSC_get_mempolicy_37664 SYSC_get_mempolicy 3 37664 NULL
118447 +__wa_seg_calculate_isoc_frame_count_37672 __wa_seg_calculate_isoc_frame_count 0 37672 NULL
118448 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
118449 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
118450 +nametbl_header_37698 nametbl_header 2-0 37698 NULL
118451 +__le32_to_cpup_37702 __le32_to_cpup 0 37702 NULL
118452 +dynamic_ps_timeout_write_37713 dynamic_ps_timeout_write 3 37713 NULL
118453 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
118454 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
118455 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
118456 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
118457 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
118458 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
118459 +ocrdma_alloc_frmr_page_list_37815 ocrdma_alloc_frmr_page_list 2 37815 NULL
118460 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
118461 +android_get_p2p_addr_37832 android_get_p2p_addr 0 37832 NULL
118462 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
118463 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
118464 +set_registers_37883 set_registers 4 37883 NULL
118465 +btrfs_stack_file_extent_disk_bytenr_37888 btrfs_stack_file_extent_disk_bytenr 0 37888 NULL
118466 +_rtw_malloc_37928 _rtw_malloc 1 37928 NULL nohasharray
118467 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 &_rtw_malloc_37928
118468 +read_rbu_packet_size_37939 read_rbu_packet_size 6 37939 NULL
118469 +write_file_bool_37957 write_file_bool 3 37957 NULL
118470 +fifo_alloc_37961 fifo_alloc 1 37961 NULL
118471 +rds_rdma_extra_size_37990 rds_rdma_extra_size 0 37990 NULL
118472 +persistent_ram_old_size_37997 persistent_ram_old_size 0 37997 NULL
118473 +vfs_readv_38011 vfs_readv 3 38011 NULL
118474 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
118475 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL nohasharray
118476 +klsi_105_prepare_write_buffer_38044 klsi_105_prepare_write_buffer 3 38044 &il_dbgfs_chain_noise_read_38044
118477 +SyS_llistxattr_38048 SyS_llistxattr 3 38048 NULL
118478 +sysfs_do_create_link_38051 sysfs_do_create_link 0 38051 NULL
118479 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
118480 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
118481 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
118482 +wcn36xx_smd_rsp_process_38081 wcn36xx_smd_rsp_process 3 38081 NULL nohasharray
118483 +xfs_buf_readahead_map_38081 xfs_buf_readahead_map 3 38081 &wcn36xx_smd_rsp_process_38081
118484 +uwb_mac_addr_print_38085 uwb_mac_addr_print 2 38085 NULL
118485 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
118486 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
118487 +ep0_read_38095 ep0_read 3 38095 NULL
118488 +osc_checksum_seq_write_38096 osc_checksum_seq_write 3 38096 NULL nohasharray
118489 +sk_wmem_schedule_38096 sk_wmem_schedule 2 38096 &osc_checksum_seq_write_38096
118490 +o2hb_read_slots_38105 o2hb_read_slots 2 38105 NULL
118491 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
118492 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
118493 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 4-3-0 38153 NULL
118494 +btrfs_extent_same_38163 btrfs_extent_same 3-2 38163 NULL
118495 +kvm_clear_guest_38164 kvm_clear_guest 3-2 38164 NULL
118496 +cdev_add_38176 cdev_add 2-3 38176 NULL
118497 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
118498 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
118499 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
118500 +ceph_decode_16_38239 ceph_decode_16 0 38239 NULL
118501 +_ipw_read_reg32_38245 _ipw_read_reg32 0 38245 NULL
118502 +snd_pcm_playback_rewind_38249 snd_pcm_playback_rewind 0-2 38249 NULL
118503 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 NULL nohasharray
118504 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 &mthca_alloc_icm_table_38268
118505 +xfs_bmbt_to_bmdr_38275 xfs_bmbt_to_bmdr 3 38275 NULL nohasharray
118506 +xfs_bmdr_to_bmbt_38275 xfs_bmdr_to_bmbt 5 38275 &xfs_bmbt_to_bmdr_38275
118507 +ftdi_process_packet_38281 ftdi_process_packet 4 38281 NULL
118508 +C_SYSC_pselect6_38296 C_SYSC_pselect6 1 38296 NULL
118509 +ucma_query_path_38305 ucma_query_path 3 38305 NULL
118510 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
118511 +ida_simple_get_38326 ida_simple_get 0 38326 NULL
118512 +__snd_gf1_look8_38333 __snd_gf1_look8 0 38333 NULL
118513 +btrfs_file_extent_disk_num_bytes_38363 btrfs_file_extent_disk_num_bytes 0 38363 NULL
118514 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
118515 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
118516 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
118517 +kvm_write_guest_38454 kvm_write_guest 4-2 38454 NULL
118518 +_iwl_dbgfs_scan_ant_rxchain_write_38479 _iwl_dbgfs_scan_ant_rxchain_write 3 38479 NULL
118519 +blk_end_bidi_request_38482 blk_end_bidi_request 3-4 38482 NULL
118520 +dev_names_read_38509 dev_names_read 3 38509 NULL
118521 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
118522 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
118523 +set_queue_count_38519 set_queue_count 0 38519 NULL
118524 +ubifs_idx_node_sz_38546 ubifs_idx_node_sz 0-2 38546 NULL
118525 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
118526 +kuc_len_38557 kuc_len 0-1 38557 NULL
118527 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
118528 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
118529 +_ipw_read32_38565 _ipw_read32 0 38565 NULL
118530 +snd_nm256_playback_copy_38567 snd_nm256_playback_copy 3-5 38567 NULL
118531 +copy_ctl_value_to_user_38587 copy_ctl_value_to_user 4 38587 NULL
118532 +rd_allocate_sgl_table_38607 rd_allocate_sgl_table 3 38607 NULL
118533 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
118534 +write_enabled_file_bool_38630 write_enabled_file_bool 3 38630 NULL
118535 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
118536 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
118537 +qp_broker_alloc_38646 qp_broker_alloc 6-5 38646 NULL
118538 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
118539 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
118540 +snd_es1371_wait_src_ready_38673 snd_es1371_wait_src_ready 0 38673 NULL
118541 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
118542 +validate_vid_hdr_38699 validate_vid_hdr 0 38699 NULL
118543 +rbio_add_io_page_38700 rbio_add_io_page 6 38700 NULL
118544 +udf_readpages_38761 udf_readpages 4 38761 NULL
118545 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
118546 +bcache_device_init_38781 bcache_device_init 3 38781 NULL
118547 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
118548 +do_pci_enable_device_38802 do_pci_enable_device 0 38802 NULL
118549 +err_decode_38804 err_decode 2 38804 NULL
118550 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
118551 +direct_entry_38836 direct_entry 3 38836 NULL
118552 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
118553 +read_nic_io_word_38853 read_nic_io_word 0 38853 NULL
118554 +interfaces_38859 interfaces 2 38859 NULL
118555 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
118556 +il_dbgfs_sram_write_38942 il_dbgfs_sram_write 3 38942 NULL
118557 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
118558 +usb_maxpacket_38977 usb_maxpacket 0 38977 NULL nohasharray
118559 +C_SYSC_preadv64_38977 C_SYSC_preadv64 3 38977 &usb_maxpacket_38977
118560 +OSDSetBlock_38986 OSDSetBlock 2-4 38986 NULL
118561 +bio_clone_range_38997 bio_clone_range 2 38997 NULL
118562 +lpfc_idiag_extacc_write_38998 lpfc_idiag_extacc_write 3 38998 NULL
118563 +get_nodes_39012 get_nodes 3 39012 NULL
118564 +twl6030_interrupt_unmask_39013 twl6030_interrupt_unmask 2 39013 NULL
118565 +force_sc_support_read_39014 force_sc_support_read 3 39014 NULL
118566 +__blkdev_issue_zeroout_39020 __blkdev_issue_zeroout 3 39020 NULL
118567 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
118568 +do_write_kmem_39051 do_write_kmem 0-1-3 39051 NULL
118569 +tomoyo_truncate_39105 tomoyo_truncate 0 39105 NULL
118570 +leb_write_lock_39111 leb_write_lock 0 39111 NULL
118571 +__kfifo_to_user_r_39123 __kfifo_to_user_r 5-3 39123 NULL
118572 +ea_foreach_39133 ea_foreach 0 39133 NULL
118573 +generic_permission_39150 generic_permission 0 39150 NULL
118574 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
118575 +ath9k_hw_ar9003_dump_eeprom_39156 ath9k_hw_ar9003_dump_eeprom 5-4 39156 NULL
118576 +echo_client_kbrw_39170 echo_client_kbrw 6 39170 NULL
118577 +ext3_xattr_check_names_39174 ext3_xattr_check_names 0 39174 NULL
118578 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
118579 +qcam_read_bytes_39205 qcam_read_bytes 0 39205 NULL
118580 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
118581 +posix_acl_to_xattr_39237 posix_acl_to_xattr 0 39237 NULL
118582 +snd_pcm_capture_forward_39248 snd_pcm_capture_forward 0-2 39248 NULL
118583 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
118584 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
118585 +i915_error_state_read_39254 i915_error_state_read 3 39254 NULL
118586 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
118587 +_iwl_dbgfs_pm_params_write_39325 _iwl_dbgfs_pm_params_write 3 39325 NULL
118588 +__cfg80211_connect_result_39326 __cfg80211_connect_result 4-6 39326 NULL
118589 +insert_reserved_file_extent_39327 insert_reserved_file_extent 3 39327 NULL
118590 +wimax_msg_alloc_39343 wimax_msg_alloc 4 39343 NULL
118591 +ide_complete_rq_39354 ide_complete_rq 3 39354 NULL
118592 +do_write_log_from_user_39362 do_write_log_from_user 3-0 39362 NULL
118593 +vortex_wtdma_getlinearpos_39371 vortex_wtdma_getlinearpos 0 39371 NULL
118594 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
118595 +fnic_trace_debugfs_read_39380 fnic_trace_debugfs_read 3 39380 NULL
118596 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
118597 +__send_to_port_39386 __send_to_port 3 39386 NULL
118598 +user_power_read_39414 user_power_read 3 39414 NULL
118599 +hash_ipmark4_expire_39419 hash_ipmark4_expire 4 39419 NULL
118600 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
118601 +mic_desc_size_39464 mic_desc_size 0 39464 NULL
118602 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
118603 +ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries_39499 ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries 3 39499 NULL
118604 +cl_req_alloc_39523 cl_req_alloc 4 39523 NULL
118605 +int_proc_write_39542 int_proc_write 3 39542 NULL
118606 +ext4_alloc_file_blocks_39551 ext4_alloc_file_blocks 3 39551 NULL
118607 +pp_write_39554 pp_write 3 39554 NULL
118608 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
118609 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
118610 +memblock_virt_alloc_internal_39600 memblock_virt_alloc_internal 1 39600 NULL
118611 +ext_depth_39607 ext_depth 0 39607 NULL
118612 +batadv_tt_tvlv_generate_39615 batadv_tt_tvlv_generate 4 39615 NULL
118613 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
118614 +sdio_readb_39618 sdio_readb 0 39618 NULL
118615 +prepare_uptodate_page_39622 prepare_uptodate_page 0 39622 NULL
118616 +set_dev_class_39645 set_dev_class 4 39645 NULL
118617 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
118618 +tcp_try_rmem_schedule_39657 tcp_try_rmem_schedule 3 39657 NULL
118619 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
118620 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
118621 +hsc_msg_len_get_39673 hsc_msg_len_get 0 39673 NULL
118622 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
118623 +sd_completed_bytes_39705 sd_completed_bytes 0 39705 NULL
118624 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
118625 +adt7316_spi_multi_read_39765 adt7316_spi_multi_read 3 39765 NULL
118626 +security_inode_listsecurity_39812 security_inode_listsecurity 0 39812 NULL
118627 +snd_pcm_oss_writev3_39818 snd_pcm_oss_writev3 3 39818 NULL
118628 +get_priv_size_39828 get_priv_size 0-1 39828 NULL
118629 +pkt_add_39897 pkt_add 3 39897 NULL
118630 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
118631 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
118632 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
118633 +__mnt_want_write_file_39917 __mnt_want_write_file 0 39917 NULL
118634 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
118635 +exofs_read_kern_39921 exofs_read_kern 6 39921 NULL nohasharray
118636 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 &exofs_read_kern_39921
118637 +__spi_async_39932 __spi_async 0 39932 NULL
118638 +__get_order_39935 __get_order 0 39935 NULL
118639 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL
118640 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3-0 39955 NULL
118641 +lstcon_group_list_39958 lstcon_group_list 2 39958 NULL
118642 +bio_chain_clone_range_39967 bio_chain_clone_range 3 39967 NULL
118643 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
118644 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
118645 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
118646 +fw_device_op_read_39990 fw_device_op_read 3 39990 NULL
118647 +server_name2svname_39998 server_name2svname 4 39998 NULL
118648 +xen_hvm_config_40018 xen_hvm_config 2 40018 NULL
118649 +ivtvfb_write_40023 ivtvfb_write 3 40023 NULL
118650 +disc_pwup_write_40027 disc_pwup_write 3 40027 NULL
118651 +ea_foreach_i_40028 ea_foreach_i 0 40028 NULL
118652 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
118653 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 NULL nohasharray
118654 +add_tty_40055 add_tty 1 40055 &l2cap_create_iframe_pdu_40055
118655 +atomic_xchg_40070 atomic_xchg 0 40070 NULL
118656 +snd_pcm_sw_params_user_40095 snd_pcm_sw_params_user 0 40095 NULL
118657 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
118658 +dwc2_max_desc_num_40132 dwc2_max_desc_num 0 40132 NULL
118659 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
118660 +ath10k_write_simulate_fw_crash_40143 ath10k_write_simulate_fw_crash 3 40143 NULL
118661 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
118662 +pt_write_40159 pt_write 3 40159 NULL
118663 +scsi_sg_count_40182 scsi_sg_count 0 40182 NULL
118664 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
118665 +allocate_probes_40204 allocate_probes 1 40204 NULL
118666 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
118667 +compress_file_range_40225 compress_file_range 3-4 40225 NULL
118668 +ocrdma_dbgfs_ops_read_40232 ocrdma_dbgfs_ops_read 3 40232 NULL
118669 +osst_read_40237 osst_read 3 40237 NULL
118670 +lpage_info_slot_40243 lpage_info_slot 1-3 40243 NULL
118671 +ocfs2_zero_extend_get_range_40248 ocfs2_zero_extend_get_range 4 40248 NULL
118672 +of_get_child_count_40254 of_get_child_count 0 40254 NULL
118673 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
118674 +ext2_fiemap_40271 ext2_fiemap 4 40271 NULL
118675 +usbnet_read_cmd_40275 usbnet_read_cmd 7 40275 NULL
118676 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
118677 +SyS_bind_40303 SyS_bind 3 40303 NULL
118678 +ubi_io_write_data_40305 ubi_io_write_data 0 40305 NULL
118679 +ib_get_mad_data_offset_40336 ib_get_mad_data_offset 0 40336 NULL
118680 +mmio_read_40348 mmio_read 4 40348 NULL
118681 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
118682 +ocfs2_check_range_for_refcount_40365 ocfs2_check_range_for_refcount 2-3 40365 NULL
118683 +get_chars_40373 get_chars 3 40373 NULL
118684 +fb_prepare_extra_logos_40429 fb_prepare_extra_logos 0-2 40429 NULL
118685 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
118686 +zd_usb_scnprint_id_40459 zd_usb_scnprint_id 0-3 40459 NULL
118687 +gp2ap020a00f_write_event_threshold_40461 gp2ap020a00f_write_event_threshold 2 40461 NULL
118688 +SyS_writev_40467 SyS_writev 3 40467 NULL
118689 +SyS_select_40473 SyS_select 1 40473 NULL
118690 +afs_fs_store_data_40484 afs_fs_store_data 3-4-5-6 40484 NULL
118691 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
118692 +devcgroup_inode_permission_40492 devcgroup_inode_permission 0 40492 NULL
118693 +__ethtool_get_sset_count_40511 __ethtool_get_sset_count 0 40511 NULL
118694 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
118695 +ixgbe_dbg_reg_ops_read_40540 ixgbe_dbg_reg_ops_read 3 40540 NULL
118696 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
118697 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
118698 +get_priv_descr_and_size_40612 get_priv_descr_and_size 0 40612 NULL
118699 +i2c_register_adapter_40660 i2c_register_adapter 0 40660 NULL
118700 +twl4030_kpwrite_u8_40665 twl4030_kpwrite_u8 3 40665 NULL
118701 +__cfg80211_roamed_40668 __cfg80211_roamed 4-6 40668 NULL
118702 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
118703 +fops_read_40672 fops_read 3 40672 NULL
118704 +idr_get_empty_slot_40674 idr_get_empty_slot 0 40674 NULL
118705 +alloc_rbio_40676 alloc_rbio 4 40676 NULL
118706 +videobuf_dma_init_user_locked_40678 videobuf_dma_init_user_locked 4-3 40678 NULL
118707 +pci_enable_resources_40680 pci_enable_resources 0 40680 NULL
118708 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
118709 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
118710 +set_extent_bit_40719 set_extent_bit 0 40719 NULL
118711 +of_pdt_build_one_prop_40735 of_pdt_build_one_prop 5 40735 NULL
118712 +fuse_readpages_40737 fuse_readpages 4 40737 NULL
118713 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
118714 +security_inode_listxattr_40752 security_inode_listxattr 0 40752 NULL
118715 +card_send_command_40757 card_send_command 3 40757 NULL
118716 +ad1889_readl_40765 ad1889_readl 0 40765 NULL
118717 +pg_write_40766 pg_write 3 40766 NULL
118718 +kernfs_fop_read_40770 kernfs_fop_read 3 40770 NULL
118719 +show_list_40775 show_list 3-0 40775 NULL
118720 +kfifo_out_copy_r_40784 kfifo_out_copy_r 0-3 40784 NULL
118721 +bitmap_weight_40791 bitmap_weight 0 40791 NULL
118722 +pyra_sysfs_read_40795 pyra_sysfs_read 6 40795 NULL
118723 +rtw_add_beacon_40801 rtw_add_beacon 3-5 40801 NULL
118724 +add_action_40811 add_action 4 40811 NULL
118725 +nl80211_send_roamed_40825 nl80211_send_roamed 5-7 40825 NULL
118726 +nilfs_mdt_init_40849 nilfs_mdt_init 3 40849 NULL
118727 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
118728 +read_file_queue_40895 read_file_queue 3 40895 NULL
118729 +waiters_read_40902 waiters_read 3 40902 NULL
118730 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
118731 +gfs2_ea_find_40913 gfs2_ea_find 0 40913 NULL
118732 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
118733 +snd_vx_create_40948 snd_vx_create 4 40948 NULL
118734 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
118735 +insert_old_idx_40987 insert_old_idx 0 40987 NULL
118736 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
118737 +iwl_dbgfs_scan_ant_rxchain_read_40999 iwl_dbgfs_scan_ant_rxchain_read 3 40999 NULL
118738 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
118739 +mtd_block_isbad_41015 mtd_block_isbad 0 41015 NULL
118740 +__proc_dobitmasks_41029 __proc_dobitmasks 5 41029 NULL
118741 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
118742 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
118743 +ocfs2_xattr_index_block_find_41040 ocfs2_xattr_index_block_find 0 41040 NULL
118744 +lprocfs_write_frac_helper_41050 lprocfs_write_frac_helper 2 41050 NULL
118745 +vfs_listxattr_41062 vfs_listxattr 0 41062 NULL nohasharray
118746 +beacon_filtering_write_41062 beacon_filtering_write 3 41062 &vfs_listxattr_41062
118747 +sc_only_mode_read_41076 sc_only_mode_read 3 41076 NULL
118748 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
118749 +nvme_map_user_pages_41093 nvme_map_user_pages 4-3 41093 NULL nohasharray
118750 +roccat_read_41093 roccat_read 3 41093 &nvme_map_user_pages_41093
118751 +dma_attach_41094 dma_attach 5-6 41094 NULL
118752 +provide_user_output_41105 provide_user_output 3 41105 NULL
118753 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
118754 +ath10k_read_wmi_services_41112 ath10k_read_wmi_services 3 41112 NULL
118755 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
118756 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
118757 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
118758 +netif_get_num_default_rss_queues_41187 netif_get_num_default_rss_queues 0 41187 NULL
118759 +request_irq_41192 request_irq 0 41192 NULL
118760 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
118761 +nfs_page_array_len_41219 nfs_page_array_len 0-2-1 41219 NULL
118762 +cfg80211_process_disassoc_41231 cfg80211_process_disassoc 3 41231 NULL
118763 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
118764 +erst_read_41260 erst_read 0 41260 NULL
118765 +alloc_context_41283 alloc_context 1 41283 NULL
118766 +of_count_phandle_with_args_41291 of_count_phandle_with_args 0 41291 NULL
118767 +o2hb_setup_one_bio_41341 o2hb_setup_one_bio 4 41341 NULL
118768 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
118769 +rtw_android_set_block_41347 rtw_android_set_block 0 41347 NULL
118770 +ceph_do_getattr_41349 ceph_do_getattr 0 41349 NULL
118771 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
118772 +kmp_init_41373 kmp_init 2 41373 NULL
118773 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
118774 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
118775 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
118776 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
118777 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
118778 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
118779 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 6-4 41442 NULL
118780 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
118781 +se_io_cb_41461 se_io_cb 3 41461 NULL
118782 +layout_leb_in_gaps_41470 layout_leb_in_gaps 0 41470 NULL
118783 +snd_pcm_status_41472 snd_pcm_status 0 41472 NULL
118784 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
118785 +bl_alloc_init_bio_41478 bl_alloc_init_bio 1 41478 NULL
118786 +kvm_unmap_hva_range_41484 kvm_unmap_hva_range 3-2 41484 NULL
118787 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
118788 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
118789 +xfrm_hash_new_size_41505 xfrm_hash_new_size 0-1 41505 NULL
118790 +SyS_preadv_41523 SyS_preadv 3 41523 NULL
118791 +dm_get_reserved_rq_based_ios_41529 dm_get_reserved_rq_based_ios 0 41529 NULL
118792 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
118793 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
118794 +nr_status_frames_41559 nr_status_frames 0-1 41559 NULL nohasharray
118795 +si476x_radio_fops_read_41559 si476x_radio_fops_read 3 41559 &nr_status_frames_41559
118796 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
118797 +batadv_tvlv_container_ogm_append_41588 batadv_tvlv_container_ogm_append 4 41588 NULL
118798 +vga_io_r_41609 vga_io_r 0 41609 NULL
118799 +tcp_hdrlen_41610 tcp_hdrlen 0 41610 NULL
118800 +usb_endpoint_maxp_41613 usb_endpoint_maxp 0 41613 NULL nohasharray
118801 +lbs_bcnmiss_write_41613 lbs_bcnmiss_write 3 41613 &usb_endpoint_maxp_41613
118802 +a2mp_send_41615 a2mp_send 4 41615 NULL
118803 +lstcon_batch_list_41627 lstcon_batch_list 2 41627 NULL
118804 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
118805 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
118806 +get_std_timing_41654 get_std_timing 0 41654 NULL
118807 +ieee80211_if_fmt_bssid_41677 ieee80211_if_fmt_bssid 3 41677 NULL
118808 +fill_pcm_stream_name_41685 fill_pcm_stream_name 2 41685 NULL
118809 +lov_unpackmd_41701 lov_unpackmd 4 41701 NULL
118810 +fillonedir_41746 fillonedir 3 41746 NULL
118811 +iwl_dbgfs_bt_notif_read_41794 iwl_dbgfs_bt_notif_read 3 41794 NULL
118812 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
118813 +rtw_android_get_macaddr_41812 rtw_android_get_macaddr 0 41812 NULL
118814 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
118815 +ixgbe_dbg_netdev_ops_read_41839 ixgbe_dbg_netdev_ops_read 3 41839 NULL
118816 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
118817 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
118818 +pci_map_single_41869 pci_map_single 0 41869 NULL
118819 +v_APCI3120_InterruptDmaMoveBlock16bit_41914 v_APCI3120_InterruptDmaMoveBlock16bit 4 41914 NULL
118820 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
118821 +ext4_da_write_inline_data_begin_41935 ext4_da_write_inline_data_begin 3-4 41935 NULL
118822 +sci_rxfill_41945 sci_rxfill 0 41945 NULL
118823 +read_gssp_41947 read_gssp 3 41947 NULL
118824 +ocfs2_xattr_bucket_get_name_value_41949 ocfs2_xattr_bucket_get_name_value 0 41949 NULL
118825 +portnames_read_41958 portnames_read 3 41958 NULL
118826 +ubi_self_check_all_ff_41959 ubi_self_check_all_ff 0 41959 NULL
118827 +dst_mtu_41969 dst_mtu 0 41969 NULL
118828 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
118829 +ubi_io_is_bad_41983 ubi_io_is_bad 0 41983 NULL
118830 +pool_allocate_42012 pool_allocate 3 42012 NULL
118831 +spidev_sync_read_42014 spidev_sync_read 0 42014 NULL
118832 +rs_sta_dbgfs_scale_table_write_42017 rs_sta_dbgfs_scale_table_write 3 42017 NULL
118833 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
118834 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
118835 +alloc_trace_kprobe_42041 alloc_trace_kprobe 6 42041 NULL
118836 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
118837 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
118838 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
118839 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
118840 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
118841 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
118842 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
118843 +dw_dma_cyclic_prep_42113 dw_dma_cyclic_prep 3-4 42113 NULL
118844 +blk_ioctl_zeroout_42160 blk_ioctl_zeroout 3 42160 NULL
118845 +mmc_align_data_size_42161 mmc_align_data_size 0-2 42161 NULL
118846 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
118847 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
118848 +write_file_beacon_42185 write_file_beacon 3 42185 NULL
118849 +get_znodes_to_commit_42201 get_znodes_to_commit 0 42201 NULL
118850 +pla_ocp_read_42235 pla_ocp_read 3 42235 NULL
118851 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
118852 +find_last_bit_42260 find_last_bit 0 42260 NULL
118853 +__pcpu_size_to_slot_42271 __pcpu_size_to_slot 0 42271 NULL
118854 +__tty_buffer_request_room_42276 __tty_buffer_request_room 2-0 42276 NULL
118855 +snd_pcm_hw_param_value_max_42280 snd_pcm_hw_param_value_max 0 42280 NULL
118856 +__cpus_weight_42299 __cpus_weight 0 42299 NULL
118857 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
118858 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
118859 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
118860 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
118861 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
118862 +tcp_sync_mss_42330 tcp_sync_mss 2-0 42330 NULL
118863 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
118864 +drbd_md_last_sector_42378 drbd_md_last_sector 0 42378 NULL
118865 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
118866 +msnd_fifo_read_42406 msnd_fifo_read 0-3 42406 NULL
118867 +krng_get_random_42420 krng_get_random 3 42420 NULL
118868 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
118869 +spr_wm_latency_write_42441 spr_wm_latency_write 3 42441 NULL
118870 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
118871 +snd_pcm_action_group_42452 snd_pcm_action_group 0 42452 NULL
118872 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
118873 +kuc_free_42455 kuc_free 2 42455 NULL
118874 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
118875 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
118876 +bypass_write_42498 bypass_write 3 42498 NULL
118877 +SyS_mincore_42511 SyS_mincore 2-1 42511 NULL
118878 +kvm_write_wall_clock_42520 kvm_write_wall_clock 2 42520 NULL
118879 +dio_bio_complete_42524 dio_bio_complete 0 42524 NULL
118880 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
118881 +self_check_ec_hdr_42528 self_check_ec_hdr 0 42528 NULL
118882 +dbAllocNear_42546 dbAllocNear 0 42546 NULL
118883 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 NULL
118884 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
118885 +iwl_print_event_log_42566 iwl_print_event_log 7-5-0 42566 NULL
118886 +xfrm_new_hash_mask_42579 xfrm_new_hash_mask 0-1 42579 NULL
118887 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
118888 +ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout_42635 ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout 3 42635 NULL
118889 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
118890 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
118891 +_regmap_raw_write_42652 _regmap_raw_write 4-2 42652 NULL
118892 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
118893 +vb2_read_42703 vb2_read 3 42703 NULL
118894 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
118895 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
118896 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
118897 +dpm_sysfs_add_42756 dpm_sysfs_add 0 42756 NULL
118898 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
118899 +snd_midi_event_decode_42780 snd_midi_event_decode 0 42780 NULL
118900 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL nohasharray
118901 +isku_sysfs_read_info_42781 isku_sysfs_read_info 6 42781 &cryptd_hash_setkey_42781
118902 +elfcorehdr_read_notes_42786 elfcorehdr_read_notes 2 42786 NULL
118903 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
118904 +ntfs_attr_extend_allocation_42796 ntfs_attr_extend_allocation 0 42796 NULL
118905 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
118906 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
118907 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
118908 +set_arg_42824 set_arg 3 42824 NULL
118909 +si476x_radio_read_rsq_blob_42827 si476x_radio_read_rsq_blob 3 42827 NULL
118910 +ocfs2_clusters_for_bytes_42872 ocfs2_clusters_for_bytes 0-2 42872 NULL
118911 +nvme_trans_unit_serial_page_42879 nvme_trans_unit_serial_page 4 42879 NULL
118912 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
118913 +hd_end_request_42904 hd_end_request 2 42904 NULL
118914 +sta_last_rx_rate_read_42909 sta_last_rx_rate_read 3 42909 NULL
118915 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
118916 +vx_reset_chk_42946 vx_reset_chk 0 42946 NULL
118917 +blkdev_direct_IO_42962 blkdev_direct_IO 4 42962 NULL
118918 +ntb_setup_snb_msix_42971 ntb_setup_snb_msix 2-0 42971 NULL
118919 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
118920 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL nohasharray
118921 +rtw_os_xmit_resource_alloc_42990 rtw_os_xmit_resource_alloc 3 42990 &nfs_idmap_get_desc_42990
118922 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
118923 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
118924 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
118925 +nfs_map_group_to_gid_43082 nfs_map_group_to_gid 3 43082 NULL
118926 +_xfer_secondary_pool_43089 _xfer_secondary_pool 2 43089 NULL
118927 +sysfs_create_file_ns_43103 sysfs_create_file_ns 0 43103 NULL
118928 +ieee80211_if_fmt_drop_unencrypted_43107 ieee80211_if_fmt_drop_unencrypted 3 43107 NULL
118929 +calculate_node_totalpages_43118 calculate_node_totalpages 2-3 43118 NULL
118930 +e1000_request_msix_43134 e1000_request_msix 0 43134 NULL
118931 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
118932 +cfs_cpt_table_alloc_43159 cfs_cpt_table_alloc 1 43159 NULL
118933 +usb_string_sub_43164 usb_string_sub 0 43164 NULL
118934 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
118935 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
118936 +ext4_xattr_ibody_get_43200 ext4_xattr_ibody_get 0 43200 NULL
118937 +uio_write_43202 uio_write 3 43202 NULL
118938 +iso_callback_43208 iso_callback 3 43208 NULL
118939 +ath10k_p2p_calc_noa_ie_len_43209 ath10k_p2p_calc_noa_ie_len 0 43209 NULL
118940 +f2fs_acl_from_disk_43210 f2fs_acl_from_disk 2 43210 NULL
118941 +atomic_long_add_return_43217 atomic_long_add_return 1-0 43217 NULL
118942 +batadv_tt_tvlv_unicast_handler_v1_43239 batadv_tt_tvlv_unicast_handler_v1 5 43239 NULL
118943 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
118944 +ide_end_rq_43269 ide_end_rq 4 43269 NULL
118945 +nilfs_direct_IO_43271 nilfs_direct_IO 4 43271 NULL
118946 +evtchn_write_43278 evtchn_write 3 43278 NULL
118947 +filemap_write_and_wait_range_43279 filemap_write_and_wait_range 0 43279 NULL
118948 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
118949 +mmu_set_spte_43327 mmu_set_spte 6-7 43327 NULL
118950 +__ext4_get_inode_loc_43332 __ext4_get_inode_loc 0 43332 NULL
118951 +xenfb_write_43412 xenfb_write 3 43412 NULL
118952 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL nohasharray
118953 +msi_capability_init_43423 msi_capability_init 0 43423 &__alloc_bootmem_low_43423
118954 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
118955 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
118956 +usb_string_43443 usb_string 0 43443 NULL nohasharray
118957 +usemap_size_43443 usemap_size 0-1-2 43443 &usb_string_43443
118958 +get_vm_area_size_43444 get_vm_area_size 0 43444 NULL
118959 +fs_path_prepare_for_add_43453 fs_path_prepare_for_add 2 43453 NULL
118960 +nvme_trans_device_id_page_43466 nvme_trans_device_id_page 4 43466 NULL
118961 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
118962 +ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime_43505 ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime 3 43505 NULL
118963 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
118964 +read_events_43534 read_events 3 43534 NULL
118965 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
118966 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
118967 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
118968 +handle_frequent_errors_43599 handle_frequent_errors 4 43599 NULL
118969 +lpfc_idiag_drbacc_read_reg_43606 lpfc_idiag_drbacc_read_reg 0-3 43606 NULL
118970 +proc_read_43614 proc_read 3 43614 NULL
118971 +disable_dma_on_even_43618 disable_dma_on_even 0 43618 NULL
118972 +alloc_thread_groups_43625 alloc_thread_groups 2 43625 NULL
118973 +random_write_43656 random_write 3 43656 NULL
118974 +bio_integrity_tag_43658 bio_integrity_tag 3 43658 NULL
118975 +ext4_acl_count_43659 ext4_acl_count 0-1 43659 NULL
118976 +write_file_tx99_power_43670 write_file_tx99_power 3 43670 NULL
118977 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4 43679 NULL
118978 +max77693_bulk_write_43698 max77693_bulk_write 2-3 43698 NULL
118979 +drbd_md_first_sector_43729 drbd_md_first_sector 0 43729 NULL
118980 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
118981 +fuse_conn_congestion_threshold_write_43736 fuse_conn_congestion_threshold_write 3 43736 NULL
118982 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
118983 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
118984 +generic_file_direct_write_43770 generic_file_direct_write 0 43770 NULL
118985 +ocfs2_xattr_get_value_outside_43787 ocfs2_xattr_get_value_outside 0 43787 NULL nohasharray
118986 +byte_pos_43787 byte_pos 0 43787 &ocfs2_xattr_get_value_outside_43787
118987 +btrfs_copy_from_user_43806 btrfs_copy_from_user 3-1-0 43806 NULL
118988 +ieee80211_if_fmt_element_ttl_43825 ieee80211_if_fmt_element_ttl 3 43825 NULL
118989 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
118990 +read_flush_43851 read_flush 3 43851 NULL
118991 +pm860x_bulk_write_43875 pm860x_bulk_write 2-3 43875 NULL
118992 +ec_dbgfs_cmd_write_43895 ec_dbgfs_cmd_write 3 43895 NULL
118993 +SendString_43928 SendString 3 43928 NULL
118994 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
118995 +__get_required_blob_size_43980 __get_required_blob_size 0-3-2 43980 NULL
118996 +nla_reserve_43984 nla_reserve 3 43984 NULL
118997 +__clkdev_alloc_43990 __clkdev_alloc 1 43990 NULL
118998 +scsi_command_size_43992 scsi_command_size 0 43992 NULL nohasharray
118999 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 &scsi_command_size_43992 nohasharray
119000 +kvm_read_guest_virt_43992 kvm_read_guest_virt 4-2 43992 &bcm_recvmsg_43992
119001 +ulist_add_43994 ulist_add 0 43994 NULL
119002 +emit_flags_44006 emit_flags 4-3 44006 NULL
119003 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
119004 +fru_strlen_44046 fru_strlen 0 44046 NULL
119005 +ath9k_def_dump_modal_eeprom_44078 ath9k_def_dump_modal_eeprom 3-2-0 44078 NULL
119006 +SYSC_add_key_44079 SYSC_add_key 4 44079 NULL
119007 +pci_msix_vec_count_44093 pci_msix_vec_count 0 44093 NULL
119008 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
119009 +skb_frag_dma_map_44112 skb_frag_dma_map 0 44112 NULL
119010 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL nohasharray
119011 +file_remove_suid_44122 file_remove_suid 0 44122 &tracing_set_trace_read_44122
119012 +SyS_process_vm_writev_44129 SyS_process_vm_writev 3-5 44129 NULL
119013 +ttm_get_pages_44142 ttm_get_pages 2 44142 NULL
119014 +scsi_get_resid_44147 scsi_get_resid 0 44147 NULL
119015 +ubifs_find_dirty_idx_leb_44169 ubifs_find_dirty_idx_leb 0 44169 NULL
119016 +ocfs2_xattr_bucket_find_44174 ocfs2_xattr_bucket_find 0 44174 NULL
119017 +SYSC_set_mempolicy_44176 SYSC_set_mempolicy 3 44176 NULL
119018 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
119019 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
119020 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
119021 +sigma_action_write_regmap_44240 sigma_action_write_regmap 3 44240 NULL
119022 +device_create_file_44285 device_create_file 0 44285 NULL
119023 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
119024 +bitmap_scnprintf_44318 bitmap_scnprintf 0-2 44318 NULL
119025 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
119026 +ccp_init_data_44324 ccp_init_data 5 44324 NULL
119027 +rs_init_44327 rs_init 1 44327 NULL
119028 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 NULL nohasharray
119029 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 &blk_queue_init_tags_44355
119030 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
119031 +mtip_hw_read_flags_44396 mtip_hw_read_flags 3 44396 NULL
119032 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
119033 +strlcpy_44400 strlcpy 3 44400 NULL
119034 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
119035 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
119036 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
119037 +write_file_debug_44476 write_file_debug 3 44476 NULL
119038 +btrfs_chunk_item_size_44478 btrfs_chunk_item_size 0-1 44478 NULL
119039 +sdio_align_size_44489 sdio_align_size 0-2 44489 NULL
119040 +bio_advance_44496 bio_advance 2 44496 NULL
119041 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
119042 +ac_register_board_44504 ac_register_board 3 44504 NULL
119043 +security_getprocattr_44505 security_getprocattr 0 44505 NULL nohasharray
119044 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 &security_getprocattr_44505
119045 +spidev_write_44510 spidev_write 3 44510 NULL
119046 +SyS_io_getevents_44519 SyS_io_getevents 3 44519 NULL
119047 +ieee80211_rx_mgmt_assoc_resp_44525 ieee80211_rx_mgmt_assoc_resp 3 44525 NULL
119048 +comm_write_44537 comm_write 3 44537 NULL
119049 +snd_pcm_drop_44542 snd_pcm_drop 0 44542 NULL
119050 +dgrp_config_proc_write_44571 dgrp_config_proc_write 3 44571 NULL
119051 +btrfs_set_extent_delalloc_44587 btrfs_set_extent_delalloc 0 44587 NULL
119052 +nouveau_perfmon_create__44602 nouveau_perfmon_create_ 4 44602 NULL
119053 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
119054 +mpi_resize_44674 mpi_resize 2 44674 NULL
119055 +sysfs_create_link_44685 sysfs_create_link 0 44685 NULL
119056 +ts_read_44687 ts_read 3 44687 NULL
119057 +lov_emerg_alloc_44698 lov_emerg_alloc 1 44698 NULL
119058 +C_SYSC_select_44701 C_SYSC_select 1 44701 NULL
119059 +__generic_block_fiemap_44713 __generic_block_fiemap 4 44713 NULL nohasharray
119060 +xfer_to_user_44713 xfer_to_user 3 44713 &__generic_block_fiemap_44713
119061 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
119062 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
119063 +fib_count_nexthops_44730 fib_count_nexthops 0 44730 NULL
119064 +efx_wanted_parallelism_44732 efx_wanted_parallelism 0 44732 NULL
119065 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
119066 +bch_bio_max_sectors_44755 bch_bio_max_sectors 0 44755 NULL
119067 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
119068 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
119069 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4-0 44769 NULL
119070 +handsfree_ramp_44777 handsfree_ramp 2 44777 NULL
119071 +irq_domain_add_legacy_44781 irq_domain_add_legacy 4-2 44781 NULL
119072 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
119073 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
119074 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
119075 +force_static_address_write_44819 force_static_address_write 3 44819 NULL
119076 +mei_cl_read_start_44824 mei_cl_read_start 2 44824 NULL
119077 +rmap_write_protect_44833 rmap_write_protect 2 44833 NULL
119078 +sisusb_write_44834 sisusb_write 3 44834 NULL
119079 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
119080 +qib_verbs_send_dma_44850 qib_verbs_send_dma 6 44850 NULL
119081 +copydesc_user_44855 copydesc_user 3 44855 NULL
119082 +set_advertising_44870 set_advertising 4 44870 NULL
119083 +init_rs_44873 init_rs 1 44873 NULL
119084 +skb_availroom_44883 skb_availroom 0 44883 NULL
119085 +do_tty_write_44896 do_tty_write 5 44896 NULL
119086 +regmap_spi_read_44921 regmap_spi_read 3-5 44921 NULL
119087 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
119088 +bytepos_delta_45017 bytepos_delta 0 45017 NULL
119089 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
119090 +dm_kvzalloc_45025 dm_kvzalloc 1 45025 NULL
119091 +sysfs_do_create_link_sd_45057 sysfs_do_create_link_sd 0 45057 NULL
119092 +sel_write_user_45060 sel_write_user 3 45060 NULL
119093 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
119094 +snd_card_new_45104 snd_card_new 5 45104 NULL
119095 +kvm_mmu_page_get_gfn_45110 kvm_mmu_page_get_gfn 0-2 45110 NULL
119096 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
119097 +usbdev_read_45114 usbdev_read 3 45114 NULL
119098 +send_to_tty_45141 send_to_tty 3 45141 NULL
119099 +cfs_trace_daemon_command_usrstr_45147 cfs_trace_daemon_command_usrstr 2 45147 NULL
119100 +gen_bitmask_string_45149 gen_bitmask_string 6 45149 NULL
119101 +device_write_45156 device_write 3 45156 NULL nohasharray
119102 +ocfs2_remove_inode_range_45156 ocfs2_remove_inode_range 3 45156 &device_write_45156
119103 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
119104 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
119105 +sctp_pack_cookie_45190 sctp_pack_cookie 6 45190 NULL nohasharray
119106 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 &sctp_pack_cookie_45190
119107 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
119108 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
119109 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
119110 +event_enable_write_45238 event_enable_write 3 45238 NULL
119111 +prism2_pda_proc_read_45246 prism2_pda_proc_read 3 45246 NULL
119112 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
119113 +gfs2_fiemap_45282 gfs2_fiemap 4 45282 NULL
119114 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
119115 +e1000_tx_map_45309 e1000_tx_map 5 45309 NULL
119116 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
119117 +brcmf_sdio_died_dump_45359 brcmf_sdio_died_dump 3 45359 NULL
119118 +null_alloc_repbuf_45375 null_alloc_repbuf 3 45375 NULL
119119 +count_skb_frag_slots_45395 count_skb_frag_slots 0 45395 NULL
119120 +sock_recv_errqueue_45412 sock_recv_errqueue 3 45412 NULL
119121 +ieee80211_if_fmt_dot11MeshHWMProotInterval_45421 ieee80211_if_fmt_dot11MeshHWMProotInterval 3 45421 NULL
119122 +ll_iocontrol_register_45430 ll_iocontrol_register 2 45430 NULL
119123 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
119124 +rds_ib_set_wr_signal_state_45463 rds_ib_set_wr_signal_state 0 45463 NULL
119125 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
119126 +snd_pcm_hwsync_45479 snd_pcm_hwsync 0 45479 NULL
119127 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
119128 +copy_macs_45534 copy_macs 4 45534 NULL
119129 +nla_attr_size_45545 nla_attr_size 0-1 45545 NULL
119130 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
119131 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
119132 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
119133 +_regmap_bus_raw_write_45559 _regmap_bus_raw_write 2 45559 NULL
119134 +posix_acl_xattr_size_45561 posix_acl_xattr_size 0-1 45561 NULL
119135 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
119136 +ath6kl_keepalive_write_45600 ath6kl_keepalive_write 3 45600 NULL
119137 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
119138 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
119139 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
119140 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
119141 +bscnl_emit_45699 bscnl_emit 2-5-0 45699 NULL nohasharray
119142 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 &bscnl_emit_45699
119143 +sg_proc_write_adio_45704 sg_proc_write_adio 3 45704 NULL
119144 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
119145 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3-0 45748 NULL nohasharray
119146 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
119147 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
119148 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
119149 +osc_checksum_type_seq_write_45785 osc_checksum_type_seq_write 3 45785 NULL
119150 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
119151 +rds_tcp_inc_copy_to_user_45804 rds_tcp_inc_copy_to_user 3 45804 NULL
119152 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
119153 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
119154 +ll_max_readahead_mb_seq_write_45815 ll_max_readahead_mb_seq_write 3 45815 NULL
119155 +memcg_update_cache_size_45828 memcg_update_cache_size 2 45828 NULL
119156 +ipv6_recv_rxpmtu_45830 ipv6_recv_rxpmtu 3 45830 NULL
119157 +insert_state_45848 insert_state 0 45848 NULL
119158 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
119159 +efx_tx_queue_insert_45859 efx_tx_queue_insert 2 45859 NULL
119160 +isdn_write_45863 isdn_write 3 45863 NULL
119161 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
119162 +ocfs2_xattr_block_find_45891 ocfs2_xattr_block_find 0 45891 NULL
119163 +cfs_cpt_weight_45903 cfs_cpt_weight 0 45903 NULL
119164 +wm_adsp_region_to_reg_45915 wm_adsp_region_to_reg 0-2 45915 NULL
119165 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
119166 +btree_keys_cachelines_45928 btree_keys_cachelines 0 45928 NULL
119167 +alloc_mr_45935 alloc_mr 1 45935 NULL
119168 +copy_to_45969 copy_to 3 45969 NULL
119169 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
119170 +ioat2_dca_count_dca_slots_45984 ioat2_dca_count_dca_slots 0 45984 NULL
119171 +kobject_init_and_add_46003 kobject_init_and_add 0 46003 NULL
119172 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
119173 +get_free_entries_46030 get_free_entries 1 46030 NULL nohasharray
119174 +fnic_reset_stats_read_46030 fnic_reset_stats_read 3 46030 &get_free_entries_46030
119175 +__access_remote_vm_46031 __access_remote_vm 0 46031 NULL
119176 +snd_emu10k1x_ptr_read_46049 snd_emu10k1x_ptr_read 0 46049 NULL
119177 +__ocfs2_move_extent_46060 __ocfs2_move_extent 3-4 46060 NULL nohasharray
119178 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 &__ocfs2_move_extent_46060
119179 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
119180 +memcg_update_array_size_46111 memcg_update_array_size 1 46111 NULL nohasharray
119181 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 &memcg_update_array_size_46111
119182 +C_SYSC_writev_46113 C_SYSC_writev 3 46113 NULL
119183 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
119184 +rtw_buf_update_46138 rtw_buf_update 4 46138 NULL
119185 +vb2_dma_sg_get_userptr_46146 vb2_dma_sg_get_userptr 3-2 46146 NULL
119186 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
119187 +twl_direction_out_46182 twl_direction_out 2 46182 NULL
119188 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
119189 +fq_resize_46195 fq_resize 2 46195 NULL
119190 +add_conn_list_46197 add_conn_list 3-0 46197 NULL
119191 +i2400m_op_msg_from_user_46213 i2400m_op_msg_from_user 4 46213 NULL
119192 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
119193 +dsp_write_46218 dsp_write 2 46218 NULL
119194 +hash_netiface4_expire_46226 hash_netiface4_expire 4 46226 NULL
119195 +xen_setup_msi_irqs_46245 xen_setup_msi_irqs 2 46245 NULL
119196 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
119197 +sg_proc_write_dressz_46316 sg_proc_write_dressz 3 46316 NULL
119198 +C_SYSC_ppoll_46319 C_SYSC_ppoll 2 46319 NULL
119199 +compat_SyS_readv_46328 compat_SyS_readv 3 46328 NULL nohasharray
119200 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 &compat_SyS_readv_46328
119201 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
119202 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
119203 +fuse_file_aio_write_46399 fuse_file_aio_write 4 46399 NULL
119204 +crypto_ablkcipher_reqsize_46411 crypto_ablkcipher_reqsize 0 46411 NULL
119205 +ttm_page_pool_get_pages_46431 ttm_page_pool_get_pages 0-5 46431 NULL
119206 +cfs_power2_roundup_46433 cfs_power2_roundup 0-1 46433 NULL
119207 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
119208 +il_dbgfs_clear_traffic_stats_write_46458 il_dbgfs_clear_traffic_stats_write 3 46458 NULL
119209 +filldir64_46469 filldir64 3 46469 NULL
119210 +fill_in_write_vector_46498 fill_in_write_vector 0 46498 NULL
119211 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
119212 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
119213 +nouveau_drm_ioctl_46514 nouveau_drm_ioctl 2 46514 NULL nohasharray
119214 +kmsg_read_46514 kmsg_read 3 46514 &nouveau_drm_ioctl_46514
119215 +nl80211_send_rx_assoc_46538 nl80211_send_rx_assoc 4 46538 NULL
119216 +dn_current_mss_46574 dn_current_mss 0 46574 NULL
119217 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
119218 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
119219 +il3945_stats_flag_46606 il3945_stats_flag 0-3 46606 NULL
119220 +vscnprintf_46617 vscnprintf 0-2 46617 NULL
119221 +__kfifo_out_r_46623 __kfifo_out_r 0-3 46623 NULL
119222 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
119223 +pci_enable_device_46642 pci_enable_device 0 46642 NULL
119224 +vfs_getxattr_alloc_46649 vfs_getxattr_alloc 0 46649 NULL
119225 +e1000_tx_map_46672 e1000_tx_map 4 46672 NULL
119226 +l2cap_create_le_flowctl_pdu_46682 l2cap_create_le_flowctl_pdu 3 46682 NULL
119227 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
119228 +__ilog2_u32_46706 __ilog2_u32 0 46706 NULL
119229 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
119230 +wl1271_rx_filter_alloc_field_46721 wl1271_rx_filter_alloc_field 5 46721 NULL
119231 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
119232 +read_file_tx99_46741 read_file_tx99 3 46741 NULL
119233 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
119234 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
119235 +_xfs_buf_get_pages_46811 _xfs_buf_get_pages 2 46811 NULL
119236 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
119237 +shmem_pwrite_fast_46842 shmem_pwrite_fast 3 46842 NULL
119238 +spi_async_46857 spi_async 0 46857 NULL
119239 +vsnprintf_46863 vsnprintf 0 46863 NULL
119240 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
119241 +qp_memcpy_from_queue_iov_46874 qp_memcpy_from_queue_iov 5-4 46874 NULL
119242 +lov_iocontrol_46876 lov_iocontrol 3 46876 NULL
119243 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
119244 +sk_mem_pages_46896 sk_mem_pages 0-1 46896 NULL
119245 +ieee80211_if_fmt_power_mode_46906 ieee80211_if_fmt_power_mode 3 46906 NULL
119246 +wlcore_alloc_hw_46917 wlcore_alloc_hw 3-1 46917 NULL
119247 +fb_write_46924 fb_write 3 46924 NULL
119248 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
119249 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
119250 +SYSC_poll_46965 SYSC_poll 2 46965 NULL
119251 +crypto_tfm_alg_alignmask_46971 crypto_tfm_alg_alignmask 0 46971 NULL
119252 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
119253 +strlcat_46985 strlcat 3 46985 NULL
119254 +bitmap_file_clear_bit_46990 bitmap_file_clear_bit 2 46990 NULL
119255 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
119256 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
119257 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2-4 47024 NULL
119258 +fs_path_len_47060 fs_path_len 0 47060 NULL
119259 +event_trigger_regex_write_47067 event_trigger_regex_write 3 47067 NULL
119260 +ext4_xattr_list_entries_47070 ext4_xattr_list_entries 0 47070 NULL
119261 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
119262 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
119263 +iwl_dump_nic_event_log_47089 iwl_dump_nic_event_log 0 47089 NULL
119264 +ptlrpc_lprocfs_threads_max_seq_write_47104 ptlrpc_lprocfs_threads_max_seq_write 3 47104 NULL
119265 +mousedev_read_47123 mousedev_read 3 47123 NULL
119266 +upcall_msg_size_47141 upcall_msg_size 2 47141 NULL
119267 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 NULL nohasharray
119268 +ses_recv_diag_47143 ses_recv_diag 4 47143 &acpi_ut_initialize_buffer_47143
119269 +mxms_headerlen_47161 mxms_headerlen 0 47161 NULL
119270 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
119271 +rts51x_ms_rw_47171 rts51x_ms_rw 3-4 47171 NULL
119272 +options_write_47243 options_write 3 47243 NULL
119273 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
119274 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
119275 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
119276 +vsnprintf_47291 vsnprintf 0 47291 NULL
119277 +SYSC_semop_47292 SYSC_semop 3 47292 NULL
119278 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
119279 +nouveau_fb_create__47316 nouveau_fb_create_ 4 47316 NULL
119280 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
119281 +avc_get_hash_stats_47359 avc_get_hash_stats 0 47359 NULL
119282 +kvm_arch_create_memslot_47364 kvm_arch_create_memslot 3 47364 NULL nohasharray
119283 +__output_copy_user_47364 __output_copy_user 3 47364 &kvm_arch_create_memslot_47364
119284 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
119285 +nv_rd32_47390 nv_rd32 0 47390 NULL nohasharray
119286 +trace_options_core_read_47390 trace_options_core_read 3 47390 &nv_rd32_47390
119287 +nametbl_list_47391 nametbl_list 2 47391 NULL
119288 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
119289 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
119290 +lbs_wrmac_write_47400 lbs_wrmac_write 3 47400 NULL
119291 +sta_vht_capa_read_47409 sta_vht_capa_read 3 47409 NULL
119292 +crypto_ablkcipher_alignmask_47410 crypto_ablkcipher_alignmask 0 47410 NULL
119293 +lbs_wrrf_write_47418 lbs_wrrf_write 3 47418 NULL
119294 +C_SYSC_set_mempolicy_47466 C_SYSC_set_mempolicy 3 47466 NULL
119295 +nvme_trans_send_fw_cmd_47479 nvme_trans_send_fw_cmd 4 47479 NULL
119296 +newpart_47485 newpart 6-4 47485 NULL
119297 +mcp23s17_read_regs_47491 mcp23s17_read_regs 4 47491 NULL
119298 +core_sys_select_47494 core_sys_select 1 47494 NULL
119299 +as3722_block_write_47503 as3722_block_write 2-3 47503 NULL
119300 +alloc_arraycache_47505 alloc_arraycache 2 47505 NULL
119301 +unlink_simple_47506 unlink_simple 3 47506 NULL
119302 +pstore_decompress_47510 pstore_decompress 0 47510 NULL
119303 +__proc_lnet_portal_rotor_47529 __proc_lnet_portal_rotor 5 47529 NULL
119304 +snd_pcm_resume_47530 snd_pcm_resume 0 47530 NULL
119305 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL nohasharray
119306 +vscnprintf_47533 vscnprintf 0-2 47533 &process_vm_rw_47533
119307 +ieee80211_if_fmt_min_discovery_timeout_47539 ieee80211_if_fmt_min_discovery_timeout 3 47539 NULL
119308 +rtw_cfg80211_set_assoc_resp_wpsp2pie_47558 rtw_cfg80211_set_assoc_resp_wpsp2pie 3 47558 NULL
119309 +read_ldt_47570 read_ldt 2 47570 NULL
119310 +isku_sysfs_read_last_set_47572 isku_sysfs_read_last_set 6 47572 NULL
119311 +btrfs_stack_header_bytenr_47589 btrfs_stack_header_bytenr 0 47589 NULL
119312 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
119313 +sctp_ssnmap_new_47608 sctp_ssnmap_new 2-1 47608 NULL
119314 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
119315 +twl4030_clear_set_47624 twl4030_clear_set 4 47624 NULL
119316 +ccp_sha_setkey_47633 ccp_sha_setkey 3 47633 NULL
119317 +get_size_47644 get_size 1-2 47644 NULL
119318 +snd_pcm_info_47699 snd_pcm_info 0 47699 NULL
119319 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL nohasharray
119320 +ipath_format_hwmsg_47700 ipath_format_hwmsg 2 47700 &packet_recvmsg_47700
119321 +save_microcode_47717 save_microcode 3 47717 NULL
119322 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
119323 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
119324 +ir_prepare_write_buffer_47747 ir_prepare_write_buffer 3 47747 NULL
119325 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
119326 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
119327 +uwb_ie_dump_hex_47774 uwb_ie_dump_hex 4 47774 NULL
119328 +SyS_setgroups16_47780 SyS_setgroups16 1 47780 NULL
119329 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
119330 +posix_acl_fix_xattr_from_user_47793 posix_acl_fix_xattr_from_user 2 47793 NULL
119331 +lov_packmd_47810 lov_packmd 0 47810 NULL
119332 +tree_mod_log_insert_move_47823 tree_mod_log_insert_move 5 47823 NULL
119333 +pinconf_dbg_config_write_47835 pinconf_dbg_config_write 3 47835 NULL
119334 +KEY_SIZE_47855 KEY_SIZE 0 47855 NULL
119335 +vhci_read_47878 vhci_read 3 47878 NULL
119336 +ubi_wl_put_peb_47886 ubi_wl_put_peb 0 47886 NULL
119337 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
119338 +cfs_percpt_alloc_47918 cfs_percpt_alloc 2 47918 NULL
119339 +comedi_write_47926 comedi_write 3 47926 NULL
119340 +nvme_trans_get_blk_desc_len_47946 nvme_trans_get_blk_desc_len 0-2 47946 NULL
119341 +arch_setup_msi_irq_47959 arch_setup_msi_irq 0 47959 NULL
119342 +gether_get_ifname_47972 gether_get_ifname 3 47972 NULL
119343 +mempool_resize_47983 mempool_resize 2 47983 NULL nohasharray
119344 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 &mempool_resize_47983
119345 +dbg_port_buf_47990 dbg_port_buf 2 47990 NULL
119346 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
119347 +lustre_cfg_len_48002 lustre_cfg_len 0 48002 NULL
119348 +gdm_tty_recv_complete_48011 gdm_tty_recv_complete 2 48011 NULL
119349 +bio_integrity_set_tag_48035 bio_integrity_set_tag 3 48035 NULL
119350 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
119351 +SYSC_writev_48040 SYSC_writev 3 48040 NULL
119352 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
119353 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
119354 +palmas_bulk_write_48068 palmas_bulk_write 2-3-5 48068 NULL
119355 +disc_write_48070 disc_write 3 48070 NULL
119356 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
119357 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
119358 +wm_latency_write_48125 wm_latency_write 3 48125 NULL
119359 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
119360 +set_discoverable_48141 set_discoverable 4 48141 NULL
119361 +dn_fib_count_nhs_48145 dn_fib_count_nhs 0 48145 NULL
119362 +SyS_vmsplice_48150 SyS_vmsplice 3 48150 NULL
119363 +_add_to_r4w_48152 _add_to_r4w 4 48152 NULL
119364 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
119365 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
119366 +rbd_obj_method_sync_48170 rbd_obj_method_sync 8 48170 NULL
119367 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
119368 +cfg80211_process_deauth_48200 cfg80211_process_deauth 3 48200 NULL
119369 +ext4_index_trans_blocks_48205 ext4_index_trans_blocks 0-2 48205 NULL
119370 +snd_seq_dump_var_event_48209 snd_seq_dump_var_event 0 48209 NULL
119371 +ll_direct_IO_26_48216 ll_direct_IO_26 4 48216 NULL
119372 +uv_blade_nr_possible_cpus_48226 uv_blade_nr_possible_cpus 0 48226 NULL
119373 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
119374 +read_file_recv_48232 read_file_recv 3 48232 NULL
119375 +unaccount_shadowed_48233 unaccount_shadowed 2 48233 NULL
119376 +nouveau_i2c_port_create__48240 nouveau_i2c_port_create_ 7 48240 NULL
119377 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
119378 +batadv_socket_read_48257 batadv_socket_read 3 48257 NULL
119379 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
119380 +trace_options_write_48275 trace_options_write 3 48275 NULL
119381 +send_set_info_48288 send_set_info 7 48288 NULL
119382 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
119383 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
119384 +hash_setkey_48310 hash_setkey 3 48310 NULL
119385 +skb_add_data_48363 skb_add_data 3 48363 NULL
119386 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
119387 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
119388 +uhid_event_from_user_48417 uhid_event_from_user 2 48417 NULL
119389 +div64_u64_rem_48418 div64_u64_rem 0-1-2 48418 NULL
119390 +snd_power_wait_48422 snd_power_wait 0 48422 NULL
119391 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
119392 +print_filtered_48442 print_filtered 2-0 48442 NULL
119393 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
119394 +compat_SyS_preadv64_48469 compat_SyS_preadv64 3 48469 NULL
119395 +_iwl_dbgfs_bt_tx_prio_write_48473 _iwl_dbgfs_bt_tx_prio_write 3 48473 NULL
119396 +ipath_format_hwerrors_48487 ipath_format_hwerrors 5 48487 NULL
119397 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
119398 +send_control_msg_48498 send_control_msg 6 48498 NULL
119399 +count_masked_bytes_48507 count_masked_bytes 0-1 48507 NULL
119400 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
119401 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
119402 +phantom_get_free_48514 phantom_get_free 0 48514 NULL
119403 +drbd_bm_capacity_48530 drbd_bm_capacity 0 48530 NULL
119404 +raid10_size_48571 raid10_size 0-2-3 48571 NULL
119405 +llog_data_len_48607 llog_data_len 1 48607 NULL
119406 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
119407 +ll_rw_extents_stats_pp_seq_write_48651 ll_rw_extents_stats_pp_seq_write 3 48651 NULL
119408 +mtd_read_48655 mtd_read 0 48655 NULL
119409 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
119410 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL
119411 +ubi_eba_unmap_leb_48671 ubi_eba_unmap_leb 0 48671 NULL
119412 +security_inode_setattr_48689 security_inode_setattr 0 48689 NULL
119413 +hysdn_log_write_48694 hysdn_log_write 3 48694 NULL
119414 +altera_drscan_48698 altera_drscan 2 48698 NULL
119415 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
119416 +lpfc_idiag_drbacc_write_48712 lpfc_idiag_drbacc_write 3 48712 NULL
119417 +SyS_lgetxattr_48719 SyS_lgetxattr 4 48719 NULL
119418 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
119419 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
119420 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
119421 +gfs2_direct_IO_48774 gfs2_direct_IO 4 48774 NULL
119422 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
119423 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
119424 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
119425 +azx_get_position_48841 azx_get_position 0 48841 NULL
119426 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
119427 +comedi_buf_write_alloc_48846 comedi_buf_write_alloc 0-2 48846 NULL
119428 +suspend_dtim_interval_write_48854 suspend_dtim_interval_write 3 48854 NULL
119429 +C_SYSC_pwritev64_48864 C_SYSC_pwritev64 3 48864 NULL nohasharray
119430 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 &C_SYSC_pwritev64_48864
119431 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
119432 +crypto_cipher_ctxsize_48890 crypto_cipher_ctxsize 0 48890 NULL
119433 +joydev_handle_JSIOCSAXMAP_48898 joydev_handle_JSIOCSAXMAP 3 48898 NULL
119434 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
119435 +msg_hdr_sz_48908 msg_hdr_sz 0 48908 NULL
119436 +snd_pcm_update_hw_ptr_48925 snd_pcm_update_hw_ptr 0 48925 NULL
119437 +sep_crypto_dma_48937 sep_crypto_dma 0 48937 NULL
119438 +si5351_write_parameters_48940 si5351_write_parameters 2 48940 NULL
119439 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
119440 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
119441 +vmci_handle_arr_create_48971 vmci_handle_arr_create 1 48971 NULL
119442 +rds_rm_size_48996 rds_rm_size 0-2 48996 NULL
119443 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
119444 +null_alloc_rs_49019 null_alloc_rs 2 49019 NULL
119445 +filemap_check_errors_49022 filemap_check_errors 0 49022 NULL
119446 +transient_status_49027 transient_status 4 49027 NULL
119447 +ll_xattr_cache_add_49032 ll_xattr_cache_add 4-0 49032 NULL
119448 +scsi_register_49094 scsi_register 2 49094 NULL
119449 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
119450 +xfrm_replay_state_esn_len_49119 xfrm_replay_state_esn_len 0 49119 NULL
119451 +ll_max_cached_mb_seq_write_49122 ll_max_cached_mb_seq_write 3 49122 NULL
119452 +pt_read_49136 pt_read 3 49136 NULL nohasharray
119453 +netxen_setup_msi_interrupts_49136 netxen_setup_msi_interrupts 2 49136 &pt_read_49136
119454 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
119455 +f2fs_acl_count_49155 f2fs_acl_count 0-1 49155 NULL
119456 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
119457 +__jfs_setxattr_49175 __jfs_setxattr 5 49175 NULL
119458 +ath6kl_bgscan_int_write_49178 ath6kl_bgscan_int_write 3 49178 NULL
119459 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
119460 +print_queue_49191 print_queue 0-4 49191 NULL
119461 +root_nfs_cat_49192 root_nfs_cat 3 49192 NULL
119462 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
119463 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
119464 +do_jffs2_getxattr_49210 do_jffs2_getxattr 0 49210 NULL
119465 +nouveau_therm_create__49228 nouveau_therm_create_ 4 49228 NULL
119466 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
119467 +isku_sysfs_read_keys_media_49268 isku_sysfs_read_keys_media 6 49268 NULL
119468 +ptlrpc_check_set_49277 ptlrpc_check_set 0 49277 NULL
119469 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
119470 +viafb_dfph_proc_write_49288 viafb_dfph_proc_write 3 49288 NULL
119471 +uio_read_49300 uio_read 3 49300 NULL
119472 +isku_sysfs_read_keys_macro_49312 isku_sysfs_read_keys_macro 6 49312 NULL
119473 +SYSC_mincore_49319 SYSC_mincore 2-1 49319 NULL
119474 +fwtty_port_handler_49327 fwtty_port_handler 9 49327 NULL
119475 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-4-3 49330 NULL
119476 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
119477 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
119478 +ext4_ext_index_trans_blocks_49396 ext4_ext_index_trans_blocks 0 49396 NULL
119479 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
119480 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
119481 +samples_to_bytes_49426 samples_to_bytes 0-2 49426 NULL
119482 +compat_do_msg_fill_49440 compat_do_msg_fill 3 49440 NULL
119483 +__hfsplus_getxattr_49460 __hfsplus_getxattr 0 49460 NULL
119484 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
119485 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
119486 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
119487 +iwl_dbgfs_disable_power_off_read_49517 iwl_dbgfs_disable_power_off_read 3 49517 NULL
119488 +SyS_listxattr_49519 SyS_listxattr 3 49519 NULL
119489 +emulator_write_phys_49520 emulator_write_phys 2-4 49520 NULL
119490 +smk_write_access_49561 smk_write_access 3 49561 NULL
119491 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
119492 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
119493 +evm_inode_setattr_49594 evm_inode_setattr 0 49594 NULL
119494 +tap_write_49595 tap_write 3 49595 NULL
119495 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
119496 +btrfs_mksubvol_49616 btrfs_mksubvol 3 49616 NULL
119497 +heap_init_49617 heap_init 2 49617 NULL
119498 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
119499 +port_fops_read_49626 port_fops_read 3 49626 NULL
119500 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
119501 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 3-4 49683 NULL
119502 +SyS_pwritev_49688 SyS_pwritev 3 49688 NULL
119503 +__setup_irq_49696 __setup_irq 0 49696 NULL
119504 +__copy_from_user_nocheck_49699 __copy_from_user_nocheck 0-3 49699 NULL
119505 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
119506 +write_pool_49718 write_pool 3 49718 NULL
119507 +kvm_mmu_notifier_invalidate_page_49723 kvm_mmu_notifier_invalidate_page 3 49723 NULL
119508 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
119509 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
119510 +btrfs_chunk_num_stripes_49751 btrfs_chunk_num_stripes 0 49751 NULL
119511 +fuse_wr_pages_49753 fuse_wr_pages 0-2-1 49753 NULL
119512 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
119513 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
119514 +ceph_osdc_readpages_49789 ceph_osdc_readpages 0 49789 NULL
119515 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
119516 +__of_parse_phandle_with_args_49807 __of_parse_phandle_with_args 0 49807 NULL
119517 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 6-3-0 49829 NULL
119518 +add_uuid_49831 add_uuid 4 49831 NULL
119519 +twl4030_write_49846 twl4030_write 2 49846 NULL
119520 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
119521 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
119522 +fiemap_count_to_size_49869 fiemap_count_to_size 0-1 49869 NULL
119523 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
119524 +osc_brw_49896 osc_brw 4 49896 NULL
119525 +ieee80211_if_fmt_dtim_count_49987 ieee80211_if_fmt_dtim_count 3 49987 NULL
119526 +drm_buffer_copy_from_user_49990 drm_buffer_copy_from_user 3 49990 NULL
119527 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
119528 +dn_mss_from_pmtu_50011 dn_mss_from_pmtu 0-2 50011 NULL
119529 +security_context_to_sid_50019 security_context_to_sid 2 50019 NULL
119530 +isdn_read_50021 isdn_read 3 50021 NULL
119531 +mdc_rename_pack_50023 mdc_rename_pack 4-6 50023 NULL
119532 +brcmf_debugfs_chipinfo_read_50033 brcmf_debugfs_chipinfo_read 3 50033 NULL
119533 +ioread8_50049 ioread8 0 50049 NULL
119534 +fuse_conn_max_background_write_50061 fuse_conn_max_background_write 3 50061 NULL
119535 +__kfifo_dma_in_prepare_50081 __kfifo_dma_in_prepare 4 50081 NULL
119536 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
119537 +libcfs_ioctl_popdata_50087 libcfs_ioctl_popdata 3 50087 NULL
119538 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
119539 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
119540 +android_set_cntry_50100 android_set_cntry 0 50100 NULL
119541 +read_file_slot_50111 read_file_slot 3 50111 NULL
119542 +rx_streaming_interval_write_50120 rx_streaming_interval_write 3 50120 NULL
119543 +jfs_direct_IO_50125 jfs_direct_IO 4 50125 NULL
119544 +SYSC_preadv_50134 SYSC_preadv 3 50134 NULL
119545 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
119546 +kmalloc_node_50163 kmalloc_node 1 50163 NULL
119547 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
119548 +ahd_probe_stack_size_50168 ahd_probe_stack_size 0 50168 NULL
119549 +odev_update_50169 odev_update 2 50169 NULL
119550 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL nohasharray
119551 +ieee80211_if_fmt_dot11MeshHWMPRannInterval_50172 ieee80211_if_fmt_dot11MeshHWMPRannInterval 3 50172 &ubi_resize_volume_50172
119552 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
119553 +cyttsp4_probe_50201 cyttsp4_probe 4 50201 NULL
119554 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
119555 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
119556 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
119557 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
119558 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
119559 +soc_codec_reg_show_50302 soc_codec_reg_show 0-3 50302 NULL
119560 +SYSC_flistxattr_50307 SYSC_flistxattr 3 50307 NULL
119561 +SYSC_sched_setaffinity_50310 SYSC_sched_setaffinity 2 50310 NULL
119562 +soc_camera_read_50319 soc_camera_read 3 50319 NULL
119563 +do_launder_page_50329 do_launder_page 0 50329 NULL
119564 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
119565 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
119566 +snd_pcm_lib_writev_50337 snd_pcm_lib_writev 0-3 50337 NULL
119567 +tpm_read_50344 tpm_read 3 50344 NULL
119568 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
119569 +iwl_dbgfs_echo_test_write_50362 iwl_dbgfs_echo_test_write 3 50362 NULL
119570 +xfrm_send_migrate_50365 xfrm_send_migrate 5 50365 NULL
119571 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
119572 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
119573 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
119574 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
119575 +validate_acl_mac_addrs_50429 validate_acl_mac_addrs 0 50429 NULL
119576 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
119577 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
119578 +device_create_sys_dev_entry_50458 device_create_sys_dev_entry 0 50458 NULL
119579 +cfs_size_round_50472 cfs_size_round 0-1 50472 NULL
119580 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
119581 +mei_io_cb_alloc_req_buf_50493 mei_io_cb_alloc_req_buf 2 50493 NULL
119582 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
119583 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
119584 +usbat_flash_write_data_50553 usbat_flash_write_data 4 50553 NULL
119585 +self_check_peb_vid_hdr_50563 self_check_peb_vid_hdr 0 50563 NULL
119586 +fat_readpages_50582 fat_readpages 4 50582 NULL
119587 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
119588 +xillybus_write_50605 xillybus_write 3 50605 NULL
119589 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
119590 +sparse_early_usemaps_alloc_node_50623 sparse_early_usemaps_alloc_node 4 50623 NULL
119591 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
119592 +ath6kl_tm_rx_event_50664 ath6kl_tm_rx_event 3 50664 NULL
119593 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
119594 +prism2_read_fid_reg_50689 prism2_read_fid_reg 0 50689 NULL
119595 +xfs_growfs_get_hdr_buf_50697 xfs_growfs_get_hdr_buf 3 50697 NULL
119596 +dev_mem_read_50706 dev_mem_read 3 50706 NULL
119597 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
119598 +__ext3_get_inode_loc_50744 __ext3_get_inode_loc 0 50744 NULL
119599 +ocfs2_xattr_block_get_50773 ocfs2_xattr_block_get 0 50773 NULL
119600 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL
119601 +bio_alloc_map_data_50782 bio_alloc_map_data 2 50782 NULL
119602 +ixgbe_acquire_msix_vectors_50789 ixgbe_acquire_msix_vectors 2 50789 NULL
119603 +tpm_write_50798 tpm_write 3 50798 NULL
119604 +tun_do_read_50800 tun_do_read 4 50800 NULL
119605 +write_flush_50803 write_flush 3 50803 NULL
119606 +dvb_play_50814 dvb_play 3 50814 NULL
119607 +btrfs_stack_file_extent_disk_num_bytes_50825 btrfs_stack_file_extent_disk_num_bytes 0 50825 NULL
119608 +dpcm_show_state_50827 dpcm_show_state 0 50827 NULL
119609 +SetArea_50835 SetArea 4 50835 NULL
119610 +videobuf_dma_init_user_50839 videobuf_dma_init_user 4-3 50839 NULL
119611 +self_check_write_50856 self_check_write 0 50856 NULL
119612 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
119613 +SyS_lgetxattr_50889 SyS_lgetxattr 4 50889 NULL
119614 +netlbl_secattr_catmap_walk_rng_50894 netlbl_secattr_catmap_walk_rng 0-2 50894 NULL
119615 +__bdev_writeseg_50903 __bdev_writeseg 4 50903 NULL
119616 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
119617 +blk_rq_cur_sectors_50910 blk_rq_cur_sectors 0 50910 NULL
119618 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
119619 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
119620 +show_device_status_50947 show_device_status 0 50947 NULL
119621 +irq_timeout_write_50950 irq_timeout_write 3 50950 NULL
119622 +virtio_cread16_50951 virtio_cread16 0 50951 NULL
119623 +sdio_uart_write_50954 sdio_uart_write 3 50954 NULL
119624 +SyS_setxattr_50957 SyS_setxattr 4 50957 NULL
119625 +of_modalias_node_50975 of_modalias_node 3 50975 NULL
119626 +iwl_statistics_flag_50981 iwl_statistics_flag 0-3 50981 NULL
119627 +timeout_write_50991 timeout_write 3 50991 NULL
119628 +proc_write_51003 proc_write 3 51003 NULL
119629 +jbd2_journal_extend_51012 jbd2_journal_extend 2 51012 NULL
119630 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
119631 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
119632 +BcmGetSectionValEndOffset_51039 BcmGetSectionValEndOffset 0 51039 NULL
119633 +dump_midi_51040 dump_midi 3 51040 NULL
119634 +usb_get_descriptor_51041 usb_get_descriptor 0 51041 NULL
119635 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
119636 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
119637 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
119638 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
119639 +__ocfs2_find_path_51096 __ocfs2_find_path 0 51096 NULL
119640 +ti_recv_51110 ti_recv 3 51110 NULL
119641 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
119642 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
119643 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
119644 +snd_pcm_unlink_51210 snd_pcm_unlink 0 51210 NULL
119645 +iwl_dbgfs_bcast_filters_macs_read_51231 iwl_dbgfs_bcast_filters_macs_read 3 51231 NULL
119646 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
119647 +snd_pcm_write_51235 snd_pcm_write 3 51235 NULL
119648 +drm_property_create_51239 drm_property_create 4 51239 NULL
119649 +st_read_51251 st_read 3 51251 NULL
119650 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
119651 +target_alloc_sgl_51264 target_alloc_sgl 3 51264 NULL
119652 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
119653 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
119654 +pvr2_std_id_to_str_51288 pvr2_std_id_to_str 2 51288 NULL
119655 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
119656 +init_map_ipmac_51317 init_map_ipmac 5 51317 NULL
119657 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
119658 +ext2_xattr_get_51327 ext2_xattr_get 0 51327 NULL
119659 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
119660 +ipw_get_event_log_len_51341 ipw_get_event_log_len 0 51341 NULL
119661 +ieee80211_if_fmt_estab_plinks_51370 ieee80211_if_fmt_estab_plinks 3 51370 NULL
119662 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
119663 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
119664 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
119665 +hfsplus_brec_read_51436 hfsplus_brec_read 0 51436 NULL
119666 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
119667 +print_devstats_dot11ACKFailureCount_51443 print_devstats_dot11ACKFailureCount 3 51443 NULL
119668 +vmxnet3_acquire_msix_vectors_51462 vmxnet3_acquire_msix_vectors 2 51462 NULL
119669 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
119670 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
119671 +kvm_fetch_guest_virt_51493 kvm_fetch_guest_virt 4-2 51493 NULL
119672 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
119673 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
119674 +batadv_tt_prepare_tvlv_local_data_51568 batadv_tt_prepare_tvlv_local_data 0 51568 NULL
119675 +ixgb_get_eeprom_len_51586 ixgb_get_eeprom_len 0 51586 NULL
119676 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
119677 +table_size_to_number_of_entries_51613 table_size_to_number_of_entries 0-1 51613 NULL
119678 +extent_fiemap_51621 extent_fiemap 3 51621 NULL
119679 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
119680 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
119681 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
119682 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
119683 +rtw_os_xmit_resource_alloc23a_51693 rtw_os_xmit_resource_alloc23a 3 51693 NULL
119684 +host_mapping_level_51696 host_mapping_level 0 51696 NULL
119685 +sel_write_access_51704 sel_write_access 3 51704 NULL
119686 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
119687 +v9fs_alloc_rdir_buf_51716 v9fs_alloc_rdir_buf 2 51716 NULL
119688 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
119689 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
119690 +cm4040_read_51732 cm4040_read 3 51732 NULL
119691 +get_user_pages_fast_51751 get_user_pages_fast 0 51751 NULL
119692 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
119693 +if_write_51756 if_write 3 51756 NULL
119694 +ssd1307fb_alloc_array_51788 ssd1307fb_alloc_array 1 51788 NULL
119695 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
119696 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
119697 +ioread32_51847 ioread32 0 51847 NULL nohasharray
119698 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 &ioread32_51847
119699 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
119700 +SYSC_sendto_51852 SYSC_sendto 6 51852 NULL
119701 +bm_page_io_async_51858 bm_page_io_async 2 51858 NULL
119702 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
119703 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
119704 +user_read_51881 user_read 3 51881 NULL
119705 +dbAdjCtl_51888 dbAdjCtl 0 51888 NULL
119706 +SyS_mq_timedsend_51896 SyS_mq_timedsend 3 51896 NULL
119707 +wmi_set_ie_51919 wmi_set_ie 3 51919 NULL
119708 +dbg_status_buf_51930 dbg_status_buf 2 51930 NULL
119709 +__tcp_mtu_to_mss_51938 __tcp_mtu_to_mss 0-2 51938 NULL
119710 +xfrm_alg_len_51940 xfrm_alg_len 0 51940 NULL
119711 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
119712 +snd_mask_min_51969 snd_mask_min 0 51969 NULL
119713 +__blkdev_get_51972 __blkdev_get 0 51972 NULL
119714 +get_zone_51981 get_zone 0-1 51981 NULL
119715 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
119716 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
119717 +scsi_sysfs_add_host_52010 scsi_sysfs_add_host 0 52010 NULL
119718 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
119719 +rdmalt_52022 rdmalt 0 52022 NULL
119720 +override_release_52032 override_release 2 52032 NULL
119721 +end_port_52042 end_port 0 52042 NULL
119722 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
119723 +msnd_fifo_write_52052 msnd_fifo_write 0-3 52052 NULL
119724 +dvb_ringbuffer_avail_52057 dvb_ringbuffer_avail 0 52057 NULL
119725 +__fuse_request_alloc_52060 __fuse_request_alloc 1 52060 NULL
119726 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
119727 +mxuport_process_read_urb_data_52072 mxuport_process_read_urb_data 3 52072 NULL
119728 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
119729 +ulist_add_merge_52096 ulist_add_merge 0 52096 NULL
119730 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
119731 +split_scan_timeout_write_52128 split_scan_timeout_write 3 52128 NULL
119732 +retry_count_read_52129 retry_count_read 3 52129 NULL
119733 +snd_pcm_channel_info_user_52135 snd_pcm_channel_info_user 0 52135 NULL
119734 +gdm_usb_hci_send_52138 gdm_usb_hci_send 3 52138 NULL
119735 +sub_alloc_52140 sub_alloc 0 52140 NULL
119736 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
119737 +htable_size_52148 htable_size 0-1 52148 NULL
119738 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
119739 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
119740 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
119741 +print_prefix_52176 print_prefix 0 52176 NULL
119742 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
119743 +reiserfs_posix_acl_from_disk_52191 reiserfs_posix_acl_from_disk 2 52191 NULL
119744 +vmci_qp_broker_alloc_52216 vmci_qp_broker_alloc 6-5 52216 NULL
119745 +fuse_request_alloc_52243 fuse_request_alloc 1 52243 NULL
119746 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
119747 +shrink_slab_52261 shrink_slab 2 52261 NULL
119748 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
119749 +handle_supp_msgs_52284 handle_supp_msgs 4 52284 NULL
119750 +kobject_set_name_vargs_52309 kobject_set_name_vargs 0 52309 NULL
119751 +read_file_reset_52310 read_file_reset 3 52310 NULL
119752 +ssd1307fb_write_52315 ssd1307fb_write 3 52315 NULL
119753 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
119754 +hwflags_read_52318 hwflags_read 3 52318 NULL
119755 +snd_pcm_hw_free_52327 snd_pcm_hw_free 0 52327 NULL
119756 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
119757 +hur_len_52339 hur_len 0 52339 NULL
119758 +bytes_to_frames_52362 bytes_to_frames 0-2 52362 NULL nohasharray
119759 +cap_inode_killpriv_52362 cap_inode_killpriv 0 52362 &bytes_to_frames_52362
119760 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
119761 +iwl_dump_fh_52371 iwl_dump_fh 0 52371 NULL
119762 +hfsplus_find_attr_52374 hfsplus_find_attr 0 52374 NULL
119763 +mq_emit_config_values_52378 mq_emit_config_values 3 52378 NULL
119764 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
119765 +jfs_setxattr_52389 jfs_setxattr 4 52389 NULL
119766 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
119767 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
119768 +hso_serial_common_create_52428 hso_serial_common_create 4 52428 NULL
119769 +delay_status_52431 delay_status 5 52431 NULL
119770 +ath6kl_delete_qos_write_52435 ath6kl_delete_qos_write 3 52435 NULL
119771 +ieee80211_if_fmt_num_sta_ps_52438 ieee80211_if_fmt_num_sta_ps 3 52438 NULL
119772 +alauda_read_data_52452 alauda_read_data 3 52452 NULL
119773 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1 52477 NULL
119774 +usb_tranzport_write_52479 usb_tranzport_write 3 52479 NULL
119775 +ocfs2_extend_no_holes_52483 ocfs2_extend_no_holes 3-4 52483 NULL
119776 +fd_do_rw_52495 fd_do_rw 3 52495 NULL
119777 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
119778 +lmv_get_easize_52504 lmv_get_easize 0 52504 NULL
119779 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
119780 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
119781 +dup_variable_bug_52525 dup_variable_bug 3 52525 NULL
119782 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
119783 +SyS_vmsplice_52540 SyS_vmsplice 3 52540 NULL
119784 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
119785 +debug_level_proc_write_52572 debug_level_proc_write 3 52572 NULL
119786 +isku_sysfs_read_macro_52587 isku_sysfs_read_macro 6 52587 NULL
119787 +snd_pcm_sw_params_52594 snd_pcm_sw_params 0 52594 NULL
119788 +SyS_setsockopt_52610 SyS_setsockopt 5 52610 NULL
119789 +ll_sa_entry_alloc_52611 ll_sa_entry_alloc 4 52611 NULL
119790 +tps80031_writes_52638 tps80031_writes 3-4 52638 NULL
119791 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
119792 +nvme_queue_extra_52661 nvme_queue_extra 0-1 52661 NULL
119793 +SYSC_gethostname_52677 SYSC_gethostname 2 52677 NULL
119794 +nvd0_disp_pioc_create__52693 nvd0_disp_pioc_create_ 5 52693 NULL
119795 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
119796 +__dm_stat_bio_52722 __dm_stat_bio 3 52722 NULL
119797 +cx25840_ir_rx_read_52724 cx25840_ir_rx_read 3 52724 NULL
119798 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
119799 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
119800 +carl9170_debugfs_vif_dump_read_52755 carl9170_debugfs_vif_dump_read 3 52755 NULL
119801 +ieee80211_if_read_beacon_timeout_52756 ieee80211_if_read_beacon_timeout 3 52756 NULL
119802 +nvme_trans_ext_inq_page_52776 nvme_trans_ext_inq_page 3 52776 NULL
119803 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
119804 +lb_alloc_ep_req_52837 lb_alloc_ep_req 2 52837 NULL
119805 +mon_bin_get_event_52863 mon_bin_get_event 4-6 52863 NULL
119806 +twl6030_gpadc_write_52867 twl6030_gpadc_write 1 52867 NULL
119807 +qib_decode_6120_err_52876 qib_decode_6120_err 3 52876 NULL
119808 +twlreg_write_52880 twlreg_write 3 52880 NULL
119809 +pvr2_ctrl_value_to_sym_internal_52881 pvr2_ctrl_value_to_sym_internal 5 52881 NULL
119810 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
119811 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
119812 +dio_bio_reap_52913 dio_bio_reap 0 52913 NULL
119813 +__kfifo_out_peek_r_52919 __kfifo_out_peek_r 3 52919 NULL
119814 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
119815 +ieee80211_if_fmt_fwded_mcast_52961 ieee80211_if_fmt_fwded_mcast 3 52961 NULL
119816 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
119817 +num_node_state_52989 num_node_state 0 52989 NULL
119818 +efivarfs_file_write_53000 efivarfs_file_write 3 53000 NULL
119819 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
119820 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
119821 +bio_cur_bytes_53037 bio_cur_bytes 0 53037 NULL
119822 +regcache_lzo_block_count_53056 regcache_lzo_block_count 0 53056 NULL
119823 +cfi_read_query_53066 cfi_read_query 0 53066 NULL
119824 +iwl_dbgfs_interrupt_write_53069 iwl_dbgfs_interrupt_write 3 53069 NULL
119825 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
119826 +vmci_check_host_caps_53087 vmci_check_host_caps 0 53087 NULL
119827 +mic_virtio_copy_from_user_53107 mic_virtio_copy_from_user 3 53107 NULL
119828 +verity_status_53120 verity_status 5 53120 NULL
119829 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
119830 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL nohasharray
119831 +inode_newsize_ok_53140 inode_newsize_ok 0 53140 &ps_poll_ps_poll_max_ap_turn_read_53140
119832 +ieee80211_bss_info_update_53170 ieee80211_bss_info_update 4 53170 NULL
119833 +btrfs_io_bio_alloc_53179 btrfs_io_bio_alloc 2 53179 NULL
119834 +clear_capture_buf_53192 clear_capture_buf 2 53192 NULL
119835 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
119836 +ptlrpc_lprocfs_req_history_max_seq_write_53243 ptlrpc_lprocfs_req_history_max_seq_write 3 53243 NULL
119837 +xfs_trans_read_buf_map_53258 xfs_trans_read_buf_map 5 53258 NULL
119838 +wil_write_file_ssid_53266 wil_write_file_ssid 3 53266 NULL
119839 +btrfs_file_extent_num_bytes_53269 btrfs_file_extent_num_bytes 0 53269 NULL
119840 +ftrace_profile_write_53327 ftrace_profile_write 3 53327 NULL
119841 +find_nr_power_limit_53330 find_nr_power_limit 0 53330 NULL
119842 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
119843 +btree_keys_bytes_53348 btree_keys_bytes 0 53348 NULL
119844 +sock_setbindtodevice_53369 sock_setbindtodevice 3 53369 NULL
119845 +get_random_bytes_arch_53370 get_random_bytes_arch 2 53370 NULL
119846 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
119847 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
119848 +apei_exec_run_optional_53452 apei_exec_run_optional 0 53452 NULL
119849 +paging64_prefetch_gpte_53468 paging64_prefetch_gpte 4 53468 NULL
119850 +ima_write_template_field_data_53475 ima_write_template_field_data 2 53475 NULL nohasharray
119851 +create_trace_kprobe_53475 create_trace_kprobe 1 53475 &ima_write_template_field_data_53475
119852 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
119853 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
119854 +do_verify_xattr_datum_53499 do_verify_xattr_datum 0 53499 NULL
119855 +snd_pcm_format_physical_width_53505 snd_pcm_format_physical_width 0 53505 NULL
119856 +dbAllocNext_53506 dbAllocNext 0 53506 NULL
119857 +force_sc_support_write_53512 force_sc_support_write 3 53512 NULL nohasharray
119858 +check_acl_53512 check_acl 0 53512 &force_sc_support_write_53512
119859 +nft_data_dump_53549 nft_data_dump 5 53549 NULL
119860 +SYSC_bind_53582 SYSC_bind 3 53582 NULL
119861 +cifs_utf16_bytes_53593 cifs_utf16_bytes 0 53593 NULL
119862 +proc_uid_map_write_53596 proc_uid_map_write 3 53596 NULL
119863 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
119864 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL
119865 +xd_write_multiple_pages_53633 xd_write_multiple_pages 6-5 53633 NULL
119866 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
119867 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
119868 +fuse_fill_write_pages_53682 fuse_fill_write_pages 4-0 53682 NULL
119869 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
119870 +bdev_logical_block_size_53690 bdev_logical_block_size 0 53690 NULL nohasharray
119871 +igb_alloc_q_vector_53690 igb_alloc_q_vector 4-6 53690 &bdev_logical_block_size_53690
119872 +find_overflow_devnum_53711 find_overflow_devnum 0 53711 NULL
119873 +__proc_debug_mb_53732 __proc_debug_mb 5 53732 NULL
119874 +wdm_write_53735 wdm_write 3 53735 NULL
119875 +lpfc_idiag_queacc_read_qe_53755 lpfc_idiag_queacc_read_qe 0-2 53755 NULL nohasharray
119876 +amdtp_out_stream_get_max_payload_53755 amdtp_out_stream_get_max_payload 0 53755 &lpfc_idiag_queacc_read_qe_53755
119877 +wa_populate_buf_in_urb_53758 wa_populate_buf_in_urb 3-4 53758 NULL
119878 +ext2_acl_count_53773 ext2_acl_count 0-1 53773 NULL
119879 +__kfifo_dma_in_prepare_r_53792 __kfifo_dma_in_prepare_r 4-5 53792 NULL
119880 +qp_alloc_host_work_53798 qp_alloc_host_work 5-3 53798 NULL
119881 +regmap_raw_write_53803 regmap_raw_write 2-4 53803 NULL
119882 +lpfc_idiag_ctlacc_read_reg_53809 lpfc_idiag_ctlacc_read_reg 0-3 53809 NULL
119883 +nls_nullsize_53815 nls_nullsize 0 53815 NULL
119884 +setup_data_read_53822 setup_data_read 3 53822 NULL
119885 +pms_read_53873 pms_read 3 53873 NULL
119886 +ieee80211_if_fmt_dropped_frames_congestion_53883 ieee80211_if_fmt_dropped_frames_congestion 3 53883 NULL
119887 +SyS_setgroups_53900 SyS_setgroups 1 53900 NULL
119888 +batadv_tt_tvlv_ogm_handler_v1_53909 batadv_tt_tvlv_ogm_handler_v1 5 53909 NULL
119889 +azx_via_get_position_53916 azx_via_get_position 0 53916 NULL
119890 +usb_serial_generic_write_53927 usb_serial_generic_write 4 53927 NULL
119891 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
119892 +__ocfs2_xattr_set_value_outside_53981 __ocfs2_xattr_set_value_outside 5 53981 NULL
119893 +ieee80211_if_fmt_dot11MeshHWMPperrMinInterval_53998 ieee80211_if_fmt_dot11MeshHWMPperrMinInterval 3 53998 NULL
119894 +hfsplus_attr_build_key_54013 hfsplus_attr_build_key 0 54013 NULL
119895 +snd_pcm_lib_write_transfer_54018 snd_pcm_lib_write_transfer 5-2-4 54018 NULL
119896 +mdc_kuc_write_54019 mdc_kuc_write 3 54019 NULL
119897 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
119898 +batadv_tt_update_orig_54049 batadv_tt_update_orig 6-4 54049 NULL
119899 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
119900 +nl80211_send_disconnected_54056 nl80211_send_disconnected 5 54056 NULL
119901 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
119902 +_malloc_54077 _malloc 1 54077 NULL
119903 +lustre_posix_acl_xattr_filter_54103 lustre_posix_acl_xattr_filter 2 54103 NULL nohasharray
119904 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 &lustre_posix_acl_xattr_filter_54103
119905 +__comedi_buf_write_alloc_54112 __comedi_buf_write_alloc 0-2 54112 NULL
119906 +strn_len_54122 strn_len 0 54122 NULL
119907 +isku_receive_54130 isku_receive 4 54130 NULL
119908 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
119909 +irq_blk_threshold_write_54138 irq_blk_threshold_write 3 54138 NULL
119910 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 NULL
119911 +nouveau_falcon_create__54169 nouveau_falcon_create_ 8 54169 NULL
119912 +p9_client_prepare_req_54175 p9_client_prepare_req 3 54175 NULL
119913 +do_sys_poll_54221 do_sys_poll 2 54221 NULL
119914 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
119915 +pi_read_regr_54231 pi_read_regr 0 54231 NULL
119916 +mcp23s08_read_regs_54246 mcp23s08_read_regs 4 54246 NULL
119917 +reada_add_block_54247 reada_add_block 2 54247 NULL
119918 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
119919 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
119920 +audio_write_54261 audio_write 4 54261 NULL nohasharray
119921 +wusb_prf_54261 wusb_prf 7 54261 &audio_write_54261
119922 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
119923 +kstrtou16_from_user_54274 kstrtou16_from_user 2 54274 NULL
119924 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
119925 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
119926 +reclaim_pages_54301 reclaim_pages 3 54301 NULL
119927 +sprintf_54306 sprintf 0 54306 NULL
119928 +bio_add_pc_page_54319 bio_add_pc_page 4 54319 NULL
119929 +br_fdb_fillbuf_54339 br_fdb_fillbuf 0 54339 NULL
119930 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
119931 +__get_free_pages_54352 __get_free_pages 0 54352 NULL
119932 +readlink_copy_54366 readlink_copy 2 54366 NULL
119933 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
119934 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 NULL nohasharray
119935 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 &do_dccp_setsockopt_54377
119936 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
119937 +snd_pcm_oss_read2_54387 snd_pcm_oss_read2 0-3 54387 NULL
119938 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
119939 +ll_ra_count_get_54410 ll_ra_count_get 3 54410 NULL
119940 +copy_gadget_strings_54417 copy_gadget_strings 2-3 54417 NULL
119941 +sparse_early_mem_maps_alloc_node_54485 sparse_early_mem_maps_alloc_node 4 54485 NULL
119942 +simple_strtoull_54493 simple_strtoull 0 54493 NULL
119943 +btrfs_ordered_sum_size_54509 btrfs_ordered_sum_size 0-2 54509 NULL
119944 +sst_byt_get_dsp_position_54513 sst_byt_get_dsp_position 0-3 54513 NULL
119945 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
119946 +vmci_transport_dgram_enqueue_54525 vmci_transport_dgram_enqueue 4 54525 NULL
119947 +viacam_read_54526 viacam_read 3 54526 NULL
119948 +unix_dgram_connect_54535 unix_dgram_connect 3 54535 NULL
119949 +setsockopt_54539 setsockopt 5 54539 NULL
119950 +lbs_lowsnr_write_54549 lbs_lowsnr_write 3 54549 NULL
119951 +SYSC_setsockopt_54561 SYSC_setsockopt 5 54561 NULL
119952 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
119953 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
119954 +nvme_npages_54601 nvme_npages 0-1 54601 NULL
119955 +irq_pkt_threshold_write_54605 irq_pkt_threshold_write 3 54605 NULL
119956 +port_fops_write_54627 port_fops_write 3 54627 NULL
119957 +tipc_send_stream_54648 tipc_send_stream 4 54648 NULL
119958 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
119959 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
119960 +twl6030_interrupt_mask_54659 twl6030_interrupt_mask 2 54659 NULL
119961 +tdp_page_fault_54663 tdp_page_fault 2 54663 NULL
119962 +bus_add_device_54665 bus_add_device 0 54665 NULL
119963 +cw1200_queue_stats_init_54670 cw1200_queue_stats_init 2 54670 NULL
119964 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
119965 +evm_read_key_54674 evm_read_key 3 54674 NULL
119966 +__btrfs_inc_extent_ref_54706 __btrfs_inc_extent_ref 7 54706 NULL
119967 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
119968 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
119969 +kzalloc_54740 kzalloc 1 54740 NULL
119970 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
119971 +lpfc_idiag_pcicfg_write_54749 lpfc_idiag_pcicfg_write 3 54749 NULL
119972 +crystalhd_user_data_54754 crystalhd_user_data 3 54754 NULL
119973 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
119974 +adis16480_show_firmware_date_54762 adis16480_show_firmware_date 3 54762 NULL
119975 +ldsem_atomic_update_54774 ldsem_atomic_update 1 54774 NULL
119976 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
119977 +nfsd_write_54809 nfsd_write 6 54809 NULL
119978 +ar9287_dump_modal_eeprom_54814 ar9287_dump_modal_eeprom 3-2 54814 NULL
119979 +crypto_tfm_ctx_alignment_54815 crypto_tfm_ctx_alignment 0 54815 NULL nohasharray
119980 +kvzalloc_54815 kvzalloc 1 54815 &crypto_tfm_ctx_alignment_54815 nohasharray
119981 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 &kvzalloc_54815
119982 +generic_perform_write_54832 generic_perform_write 3-0 54832 NULL
119983 +write_rio_54837 write_rio 3 54837 NULL
119984 +ext3_acl_from_disk_54839 ext3_acl_from_disk 2 54839 NULL nohasharray
119985 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 &ext3_acl_from_disk_54839
119986 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
119987 +printer_read_54851 printer_read 3 54851 NULL
119988 +assign_irq_vector_54852 assign_irq_vector 0 54852 NULL
119989 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
119990 +prism_build_supp_rates_54865 prism_build_supp_rates 0 54865 NULL
119991 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL nohasharray
119992 +kobject_set_name_vargs_54913 kobject_set_name_vargs 0 54913 &iscsi_pool_init_54913
119993 +btrfs_stack_chunk_num_stripes_54923 btrfs_stack_chunk_num_stripes 0 54923 NULL
119994 +bio_add_page_54933 bio_add_page 0-3 54933 NULL
119995 +mxms_structlen_54939 mxms_structlen 0 54939 NULL
119996 +add_port_54941 add_port 2 54941 NULL
119997 +tipc_send2name_54946 tipc_send2name 5 54946 NULL
119998 +ath9k_dump_btcoex_54949 ath9k_dump_btcoex 0-3 54949 NULL
119999 +alauda_write_data_54967 alauda_write_data 3 54967 NULL
120000 +c4_add_card_54968 c4_add_card 3 54968 NULL
120001 +ext3_xattr_get_54989 ext3_xattr_get 0 54989 NULL
120002 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
120003 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
120004 +apei_exec_run_55075 apei_exec_run 0 55075 NULL
120005 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
120006 +snd_pcm_capture_hw_avail_55086 snd_pcm_capture_hw_avail 0 55086 NULL
120007 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
120008 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
120009 +filldir_55137 filldir 3 55137 NULL
120010 +ocfs2_truncate_file_55148 ocfs2_truncate_file 3 55148 NULL
120011 +npages_to_npools_55149 npages_to_npools 0-1 55149 NULL
120012 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
120013 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
120014 +compat_SyS_ppoll_55196 compat_SyS_ppoll 2 55196 NULL
120015 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
120016 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL
120017 +__kfifo_dma_out_prepare_r_55211 __kfifo_dma_out_prepare_r 4-5 55211 NULL
120018 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
120019 +qxl_alloc_client_monitors_config_55216 qxl_alloc_client_monitors_config 2 55216 NULL
120020 +nouveau_mc_create__55217 nouveau_mc_create_ 4 55217 NULL
120021 +dbAllocDmap_55227 dbAllocDmap 0 55227 NULL
120022 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
120023 +lbs_failcount_write_55276 lbs_failcount_write 3 55276 NULL
120024 +persistent_ram_new_55286 persistent_ram_new 1-2 55286 NULL
120025 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
120026 +lov_get_stripecnt_55297 lov_get_stripecnt 0-3 55297 NULL
120027 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
120028 +qp_alloc_guest_work_55305 qp_alloc_guest_work 5-3 55305 NULL nohasharray
120029 +compat_SyS_process_vm_readv_55305 compat_SyS_process_vm_readv 3-5 55305 &qp_alloc_guest_work_55305
120030 +compat_SyS_mbind_55329 compat_SyS_mbind 5 55329 NULL
120031 +vme_user_read_55338 vme_user_read 3 55338 NULL
120032 +__wa_xfer_setup_sizes_55342 __wa_xfer_setup_sizes 0 55342 NULL nohasharray
120033 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 &__wa_xfer_setup_sizes_55342
120034 +cw1200_sdio_align_size_55391 cw1200_sdio_align_size 2 55391 NULL
120035 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
120036 +nouveau_cli_create_55425 nouveau_cli_create 3 55425 NULL
120037 +si476x_radio_read_rds_blckcnt_blob_55427 si476x_radio_read_rds_blckcnt_blob 3 55427 NULL
120038 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
120039 +cx23888_ir_rx_read_55473 cx23888_ir_rx_read 3 55473 NULL
120040 +snd_pcm_lib_write_55483 snd_pcm_lib_write 0-3 55483 NULL
120041 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
120042 +batadv_tt_entries_55487 batadv_tt_entries 0-1 55487 NULL
120043 +ras_stride_increase_window_55501 ras_stride_increase_window 3 55501 NULL
120044 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 NULL
120045 +ea_get_55522 ea_get 3-0 55522 NULL
120046 +buffer_size_55534 buffer_size 0 55534 NULL
120047 +set_msr_interception_55538 set_msr_interception 2 55538 NULL
120048 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
120049 +hash_ipport6_expire_55549 hash_ipport6_expire 4 55549 NULL
120050 +dm_stats_list_55551 dm_stats_list 4 55551 NULL
120051 +compat_SyS_setsockopt_55581 compat_SyS_setsockopt 5 55581 NULL
120052 +add_partition_55588 add_partition 2 55588 NULL
120053 +kstrtou8_from_user_55599 kstrtou8_from_user 2 55599 NULL
120054 +SyS_keyctl_55602 SyS_keyctl 4 55602 NULL
120055 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
120056 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
120057 +edge_tty_recv_55622 edge_tty_recv 3 55622 NULL
120058 +reiserfs_xattr_get_55628 reiserfs_xattr_get 0 55628 NULL nohasharray
120059 +pktgen_if_write_55628 pktgen_if_write 3 55628 &reiserfs_xattr_get_55628
120060 +osc_obd_max_pages_per_rpc_seq_write_55636 osc_obd_max_pages_per_rpc_seq_write 3 55636 NULL
120061 +xfs_bmbt_maxrecs_55649 xfs_bmbt_maxrecs 0-2 55649 NULL
120062 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
120063 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
120064 +get_info_55681 get_info 3 55681 NULL
120065 +iwl_dbgfs_plcp_delta_write_55682 iwl_dbgfs_plcp_delta_write 3 55682 NULL
120066 +genl_allocate_reserve_groups_55705 genl_allocate_reserve_groups 1 55705 NULL
120067 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
120068 +tap_pwup_write_55723 tap_pwup_write 3 55723 NULL
120069 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 2 55738 NULL
120070 +set_local_name_55757 set_local_name 4 55757 NULL
120071 +strlen_55778 strlen 0 55778 NULL nohasharray
120072 +is_idx_node_in_tnc_55778 is_idx_node_in_tnc 0 55778 &strlen_55778
120073 +set_spte_55783 set_spte 5-4 55783 NULL
120074 +req_bio_endio_55786 req_bio_endio 3 55786 NULL nohasharray
120075 +conf_read_55786 conf_read 3 55786 &req_bio_endio_55786
120076 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
120077 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
120078 +ip_hdrlen_55849 ip_hdrlen 0 55849 NULL
120079 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
120080 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
120081 +hsc_write_55875 hsc_write 3 55875 NULL
120082 +ramdisk_store_55885 ramdisk_store 4 55885 NULL
120083 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
120084 +hash_ip4_expire_55911 hash_ip4_expire 4 55911 NULL
120085 +snd_pcm_hw_param_value_min_55917 snd_pcm_hw_param_value_min 0 55917 NULL
120086 +ext2_direct_IO_55932 ext2_direct_IO 4 55932 NULL
120087 +kvm_write_guest_virt_system_55944 kvm_write_guest_virt_system 4-2 55944 NULL
120088 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
120089 +ceph_get_direct_page_vector_55956 ceph_get_direct_page_vector 2 55956 NULL
120090 +simple_read_from_buffer_55957 simple_read_from_buffer 2-5 55957 NULL
120091 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
120092 +btrfs_clone_55977 btrfs_clone 5-3 55977 NULL
120093 +wa_xfer_create_subset_sg_55992 wa_xfer_create_subset_sg 3-2 55992 NULL
120094 +nvme_alloc_iod_56027 nvme_alloc_iod 1-2 56027 NULL
120095 +rtl8169_init_ring_56028 rtl8169_init_ring 0 56028 NULL
120096 +usb_ocp_write_56047 usb_ocp_write 4 56047 NULL
120097 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
120098 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
120099 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
120100 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
120101 +write_file_frameerrors_56145 write_file_frameerrors 3 56145 NULL
120102 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
120103 +ath9k_dump_legacy_btcoex_56194 ath9k_dump_legacy_btcoex 3-0 56194 NULL
120104 +vring_add_indirect_56222 vring_add_indirect 4 56222 NULL
120105 +ocfs2_find_xe_in_bucket_56224 ocfs2_find_xe_in_bucket 0 56224 NULL
120106 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
120107 +fd_copyin_56247 fd_copyin 3 56247 NULL
120108 +sk_rmem_schedule_56255 sk_rmem_schedule 3 56255 NULL
120109 +acpi_ex_get_serial_access_length_56275 acpi_ex_get_serial_access_length 0-2 56275 NULL
120110 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
120111 +ieee80211_if_fmt_user_power_level_56283 ieee80211_if_fmt_user_power_level 3 56283 NULL
120112 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
120113 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
120114 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
120115 +speakup_file_write_56310 speakup_file_write 3 56310 NULL
120116 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
120117 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
120118 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
120119 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
120120 +mite_device_bytes_transferred_56355 mite_device_bytes_transferred 0 56355 NULL
120121 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 4-0 56368 NULL
120122 +dev_read_56369 dev_read 3 56369 NULL
120123 +ath10k_read_simulate_fw_crash_56371 ath10k_read_simulate_fw_crash 3 56371 NULL
120124 +snd_pcm_common_ioctl1_56382 snd_pcm_common_ioctl1 0 56382 NULL
120125 +write_gssp_56404 write_gssp 3 56404 NULL
120126 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
120127 +store_msg_56417 store_msg 3 56417 NULL
120128 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
120129 +l2cap_segment_le_sdu_56426 l2cap_segment_le_sdu 4 56426 NULL
120130 +ec_dbgfs_cmd_read_56431 ec_dbgfs_cmd_read 3 56431 NULL
120131 +fl_create_56435 fl_create 5 56435 NULL
120132 +gnttab_map_56439 gnttab_map 2 56439 NULL
120133 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2-4 56453 NULL
120134 +set_connectable_56458 set_connectable 4 56458 NULL
120135 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
120136 +putused_user_56467 putused_user 3 56467 NULL
120137 +ocfs2_zero_extend_range_56468 ocfs2_zero_extend_range 3-2 56468 NULL
120138 +lbs_rdmac_write_56471 lbs_rdmac_write 3 56471 NULL
120139 +crypto_shash_alignmask_56486 crypto_shash_alignmask 0 56486 NULL
120140 +ieee80211_rx_mgmt_probe_beacon_56491 ieee80211_rx_mgmt_probe_beacon 3 56491 NULL
120141 +memblock_virt_alloc_56501 memblock_virt_alloc 1 56501 NULL
120142 +init_map_ip_56508 init_map_ip 5 56508 NULL
120143 +lustre_posix_acl_xattr_reduce_space_56512 lustre_posix_acl_xattr_reduce_space 3 56512 NULL
120144 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
120145 +ip_options_get_56538 ip_options_get 4 56538 NULL
120146 +ll_wr_track_id_56544 ll_wr_track_id 2 56544 NULL
120147 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
120148 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
120149 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
120150 +gro_pull_from_frag0_56593 gro_pull_from_frag0 2 56593 NULL
120151 +event_filter_write_56609 event_filter_write 3 56609 NULL
120152 +nvme_trans_log_temperature_56613 nvme_trans_log_temperature 3 56613 NULL
120153 +gather_array_56641 gather_array 3 56641 NULL
120154 +lookup_extent_backref_56644 lookup_extent_backref 9 56644 NULL
120155 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
120156 +tg3_nvram_write_block_56666 tg3_nvram_write_block 3 56666 NULL
120157 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
120158 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3-0 56702 NULL
120159 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
120160 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
120161 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
120162 +__copy_from_user_ll_56738 __copy_from_user_ll 0-3 56738 NULL
120163 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
120164 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
120165 +ttm_alloc_new_pages_56792 ttm_alloc_new_pages 5 56792 NULL
120166 +ion_ioctl_56806 ion_ioctl 2 56806 NULL
120167 +do_syslog_56807 do_syslog 3 56807 NULL
120168 +mtdchar_write_56831 mtdchar_write 3 56831 NULL
120169 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4-0 56847 NULL
120170 +si476x_radio_read_agc_blob_56849 si476x_radio_read_agc_blob 3 56849 NULL
120171 +ext3_xattr_ibody_get_56880 ext3_xattr_ibody_get 0 56880 NULL
120172 +pvr2_debugifc_print_status_56890 pvr2_debugifc_print_status 3 56890 NULL
120173 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
120174 +batadv_tt_update_changes_56895 batadv_tt_update_changes 3 56895 NULL nohasharray
120175 +le_auto_conn_write_56895 le_auto_conn_write 3 56895 &batadv_tt_update_changes_56895
120176 +hfsplus_find_cat_56899 hfsplus_find_cat 0 56899 NULL
120177 +strcspn_56913 strcspn 0 56913 NULL
120178 +__kfifo_out_56927 __kfifo_out 0-3 56927 NULL
120179 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
120180 +nouveau_xtensa_create__56952 nouveau_xtensa_create_ 8 56952 NULL
120181 +diva_get_driver_info_56967 diva_get_driver_info 0 56967 NULL
120182 +sptlrpc_secflags2str_56995 sptlrpc_secflags2str 3 56995 NULL
120183 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
120184 +btrfs_super_csum_size_57004 btrfs_super_csum_size 0 57004 NULL
120185 +aircable_process_packet_57027 aircable_process_packet 4 57027 NULL
120186 +ieee80211_if_fmt_state_57043 ieee80211_if_fmt_state 3 57043 NULL nohasharray
120187 +skb_network_offset_57043 skb_network_offset 0 57043 &ieee80211_if_fmt_state_57043
120188 +bytes_to_samples_57049 bytes_to_samples 0-2 57049 NULL
120189 +xfs_buf_read_map_57053 xfs_buf_read_map 3 57053 NULL
120190 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
120191 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
120192 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
120193 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
120194 +altera_get_note_57099 altera_get_note 6 57099 NULL
120195 +hpfs_readpages_57106 hpfs_readpages 4 57106 NULL
120196 +snd_pcm_hw_params_old_user_57108 snd_pcm_hw_params_old_user 0 57108 NULL
120197 +crypto_compress_ctxsize_57109 crypto_compress_ctxsize 0 57109 NULL
120198 +cipso_v4_gentag_loc_57119 cipso_v4_gentag_loc 0 57119 NULL
120199 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 NULL nohasharray
120200 +rds_ib_sub_signaled_57136 rds_ib_sub_signaled 2 57136 &ima_show_htable_value_57136 nohasharray
120201 +nl80211_send_deauth_57136 nl80211_send_deauth 4 57136 &rds_ib_sub_signaled_57136
120202 +snd_sonicvibes_getdmac_57140 snd_sonicvibes_getdmac 0 57140 NULL
120203 +_iwl_dbgfs_bf_params_write_57141 _iwl_dbgfs_bf_params_write 3 57141 NULL
120204 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
120205 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
120206 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
120207 +hash_netnet6_expire_57191 hash_netnet6_expire 4 57191 NULL
120208 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
120209 +dma_fifo_alloc_57236 dma_fifo_alloc 2-3-5 57236 NULL
120210 +flush_space_57241 flush_space 0 57241 NULL
120211 +rsxx_cram_write_57244 rsxx_cram_write 3 57244 NULL
120212 +ieee80211_if_fmt_tsf_57249 ieee80211_if_fmt_tsf 3 57249 NULL
120213 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
120214 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
120215 +lbs_sleepparams_write_57283 lbs_sleepparams_write 3 57283 NULL
120216 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
120217 +snd_pcm_read_57289 snd_pcm_read 3 57289 NULL
120218 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
120219 +write_file_regval_57313 write_file_regval 3 57313 NULL
120220 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
120221 +usblp_read_57342 usblp_read 3 57342 NULL
120222 +print_devstats_dot11RTSFailureCount_57347 print_devstats_dot11RTSFailureCount 3 57347 NULL
120223 +dio_send_cur_page_57348 dio_send_cur_page 0 57348 NULL
120224 +tipc_bclink_stats_57372 tipc_bclink_stats 2 57372 NULL
120225 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
120226 +read_file_blob_57406 read_file_blob 3 57406 NULL
120227 +enclosure_register_57412 enclosure_register 3 57412 NULL
120228 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL
120229 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
120230 +__roundup_pow_of_two_57461 __roundup_pow_of_two 0 57461 NULL
120231 +sisusb_clear_vram_57466 sisusb_clear_vram 2-3 57466 NULL
120232 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL
120233 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
120234 +skb_headlen_57501 skb_headlen 0 57501 NULL
120235 +copy_in_user_57502 copy_in_user 3 57502 NULL
120236 +ckhdid_printf_57505 ckhdid_printf 2 57505 NULL
120237 +init_tag_map_57515 init_tag_map 3 57515 NULL
120238 +wil_read_file_ssid_57517 wil_read_file_ssid 3 57517 NULL nohasharray
120239 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 &wil_read_file_ssid_57517
120240 +cmm_read_57520 cmm_read 3 57520 NULL
120241 +inode_permission_57531 inode_permission 0 57531 NULL
120242 +acpi_dev_get_resources_57534 acpi_dev_get_resources 0 57534 NULL
120243 +ptlrpc_lprocfs_hp_ratio_seq_write_57537 ptlrpc_lprocfs_hp_ratio_seq_write 3 57537 NULL
120244 +compat_SyS_process_vm_writev_57542 compat_SyS_process_vm_writev 3-5 57542 NULL
120245 +obd_unpackmd_57563 obd_unpackmd 0 57563 NULL
120246 +snd_pcm_playback_ioctl1_57569 snd_pcm_playback_ioctl1 0 57569 NULL
120247 +get_bridge_ifindices_57579 get_bridge_ifindices 0 57579 NULL
120248 +ldlm_cli_enqueue_local_57582 ldlm_cli_enqueue_local 11 57582 NULL
120249 +il_dbgfs_interrupt_write_57591 il_dbgfs_interrupt_write 3 57591 NULL
120250 +read_file_spectral_fft_period_57593 read_file_spectral_fft_period 3 57593 NULL
120251 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
120252 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 NULL
120253 +mem_read_57631 mem_read 3 57631 NULL
120254 +pci_enable_msi_block_57632 pci_enable_msi_block 0 57632 NULL
120255 +msi_compose_msg_57637 msi_compose_msg 0 57637 NULL
120256 +r3964_write_57662 r3964_write 4 57662 NULL
120257 +proc_ns_readlink_57664 proc_ns_readlink 3 57664 NULL
120258 +__lgwrite_57669 __lgwrite 4 57669 NULL
120259 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
120260 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
120261 +vm_find_vqs_57729 vm_find_vqs 0 57729 NULL
120262 +nouveau_gpio_create__57735 nouveau_gpio_create_ 4-5 57735 NULL
120263 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 NULL
120264 +ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval_57762 ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval 3 57762 NULL
120265 +SYSC_process_vm_writev_57776 SYSC_process_vm_writev 3-5 57776 NULL
120266 +security_inode_unlink_57791 security_inode_unlink 0 57791 NULL
120267 +ld2_57794 ld2 0 57794 NULL
120268 +ivtv_read_57796 ivtv_read 3 57796 NULL
120269 +ion_test_ioctl_57799 ion_test_ioctl 2 57799 NULL
120270 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
120271 +copy_to_user_57835 copy_to_user 0-3 57835 NULL
120272 +flash_read_57843 flash_read 3 57843 NULL
120273 +kiblnd_create_tx_pool_57846 kiblnd_create_tx_pool 2 57846 NULL
120274 +radeon_ttm_gtt_read_57879 radeon_ttm_gtt_read 3 57879 NULL
120275 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
120276 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
120277 +ll_xattr_find_get_lock_57912 ll_xattr_find_get_lock 0 57912 NULL
120278 +memcg_caches_array_size_57918 memcg_caches_array_size 0-1 57918 NULL
120279 +twl_i2c_write_57923 twl_i2c_write 3-4 57923 NULL
120280 +__snd_gf1_look16_57925 __snd_gf1_look16 0 57925 NULL
120281 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
120282 +xfs_mru_cache_create_57943 xfs_mru_cache_create 3 57943 NULL
120283 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
120284 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL nohasharray
120285 +ioat3_dca_count_dca_slots_57953 ioat3_dca_count_dca_slots 0 57953 &ip_set_alloc_57953
120286 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
120287 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
120288 +io_playback_transfer_58030 io_playback_transfer 4 58030 NULL
120289 +mce_async_out_58056 mce_async_out 3 58056 NULL
120290 +ocfs2_find_leaf_58065 ocfs2_find_leaf 0 58065 NULL
120291 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
120292 +cm4040_write_58079 cm4040_write 3 58079 NULL
120293 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
120294 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
120295 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
120296 +ieee80211_if_fmt_flags_58205 ieee80211_if_fmt_flags 3 58205 NULL
120297 +i40evf_allocate_virt_mem_d_58210 i40evf_allocate_virt_mem_d 3 58210 NULL
120298 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
120299 +read_file_debug_58256 read_file_debug 3 58256 NULL
120300 +osc_max_dirty_mb_seq_write_58263 osc_max_dirty_mb_seq_write 3 58263 NULL
120301 +cfg80211_mgmt_tx_status_58266 cfg80211_mgmt_tx_status 4 58266 NULL
120302 +profile_load_58267 profile_load 3 58267 NULL
120303 +kstrtos8_from_user_58268 kstrtos8_from_user 2 58268 NULL
120304 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
120305 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
120306 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
120307 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
120308 +ext4_ext_truncate_extend_restart_58331 ext4_ext_truncate_extend_restart 3 58331 NULL
120309 +__copy_from_user_swizzled_58337 __copy_from_user_swizzled 2-4 58337 NULL
120310 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
120311 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
120312 +_drbd_md_sync_page_io_58403 _drbd_md_sync_page_io 6 58403 NULL
120313 +idetape_pad_zeros_58406 idetape_pad_zeros 2 58406 NULL
120314 +i2400m_pld_size_58415 i2400m_pld_size 0 58415 NULL
120315 +capabilities_read_58457 capabilities_read 3 58457 NULL
120316 +usnic_vnic_get_resources_58462 usnic_vnic_get_resources 3 58462 NULL
120317 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 NULL nohasharray
120318 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 &compat_do_ipt_set_ctl_58466
120319 +nv_rd08_58472 nv_rd08 0 58472 NULL
120320 +acpi_tables_sysfs_init_58477 acpi_tables_sysfs_init 0 58477 NULL
120321 +snd_gf1_read_addr_58483 snd_gf1_read_addr 0 58483 NULL
120322 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
120323 +btrfs_cont_expand_58498 btrfs_cont_expand 2-3-0 58498 NULL
120324 +tcf_hash_create_58507 tcf_hash_create 4 58507 NULL
120325 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
120326 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
120327 +scnprint_mac_oui_58578 scnprint_mac_oui 3-0 58578 NULL
120328 +cur_wm_latency_write_58581 cur_wm_latency_write 3 58581 NULL
120329 +get_rhf_errstring_58582 get_rhf_errstring 3 58582 NULL
120330 +ea_read_inline_58589 ea_read_inline 0 58589 NULL
120331 +isku_sysfs_read_keys_thumbster_58590 isku_sysfs_read_keys_thumbster 6 58590 NULL
120332 +xip_file_read_58592 xip_file_read 3 58592 NULL
120333 +ecryptfs_write_end_58594 ecryptfs_write_end 5-3 58594 NULL
120334 +radeon_bo_size_58606 radeon_bo_size 0 58606 NULL
120335 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
120336 +filemap_fdatawrite_range_58630 filemap_fdatawrite_range 0 58630 NULL
120337 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
120338 +iwl_dbgfs_rx_handlers_write_58655 iwl_dbgfs_rx_handlers_write 3 58655 NULL
120339 +find_zero_58685 find_zero 0-1 58685 NULL
120340 +uwb_bce_print_IEs_58686 uwb_bce_print_IEs 4 58686 NULL
120341 +tps6586x_writes_58689 tps6586x_writes 2-3 58689 NULL
120342 +scsi_setup_command_freelist_58703 scsi_setup_command_freelist 0 58703 NULL
120343 +vx_send_msg_58711 vx_send_msg 0 58711 NULL
120344 +csum_exist_in_range_58730 csum_exist_in_range 2-3 58730 NULL
120345 +frames_to_bytes_58741 frames_to_bytes 0-2 58741 NULL
120346 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
120347 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
120348 +regmap_calc_reg_len_58795 regmap_calc_reg_len 0 58795 NULL
120349 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
120350 +isku_sysfs_read_58806 isku_sysfs_read 5 58806 NULL
120351 +ep_read_58813 ep_read 3 58813 NULL
120352 +command_write_58841 command_write 3 58841 NULL
120353 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
120354 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
120355 +esas2r_change_queue_depth_58886 esas2r_change_queue_depth 2 58886 NULL
120356 +lprocfs_wr_pinger_recov_58914 lprocfs_wr_pinger_recov 3 58914 NULL
120357 +print_devstats_dot11FCSErrorCount_58919 print_devstats_dot11FCSErrorCount 3 58919 NULL
120358 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
120359 +wait_table_hash_nr_entries_58962 wait_table_hash_nr_entries 0 58962 NULL
120360 +ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout_58965 ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout 3 58965 NULL
120361 +crypto_aead_ivsize_58970 crypto_aead_ivsize 0 58970 NULL
120362 +init_list_set_59005 init_list_set 3 59005 NULL
120363 +ep_write_59008 ep_write 3 59008 NULL
120364 +lpfc_idiag_baracc_write_59014 lpfc_idiag_baracc_write 3 59014 NULL
120365 +SyS_preadv_59029 SyS_preadv 3 59029 NULL
120366 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
120367 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
120368 +crypto_aead_reqsize_59039 crypto_aead_reqsize 0 59039 NULL
120369 +regmap_bulk_write_59049 regmap_bulk_write 2-4 59049 NULL nohasharray
120370 +i8042_enable_kbd_port_59049 i8042_enable_kbd_port 0 59049 &regmap_bulk_write_59049
120371 +mmc_sd_num_wr_blocks_59112 mmc_sd_num_wr_blocks 0 59112 NULL
120372 +sta_tx_latency_stat_table_59122 sta_tx_latency_stat_table 0-4-5 59122 NULL nohasharray
120373 +scsi_io_completion_59122 scsi_io_completion 2 59122 &sta_tx_latency_stat_table_59122
120374 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
120375 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 NULL nohasharray
120376 +print_devstats_dot11RTSSuccessCount_59145 print_devstats_dot11RTSSuccessCount 3 59145 &framebuffer_alloc_59145
120377 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
120378 +pvr2_hdw_report_clients_59152 pvr2_hdw_report_clients 3 59152 NULL
120379 +ksize_59176 ksize 0 59176 NULL
120380 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
120381 +ocfs2_move_extent_59187 ocfs2_move_extent 2-5 59187 NULL
120382 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
120383 +check_mapped_selector_name_59216 check_mapped_selector_name 5 59216 NULL
120384 +dt3155_read_59226 dt3155_read 3 59226 NULL
120385 +paging64_gpte_to_gfn_lvl_59229 paging64_gpte_to_gfn_lvl 0-2-1 59229 NULL
120386 +nla_len_59258 nla_len 0 59258 NULL
120387 +drbd_bm_write_page_59290 drbd_bm_write_page 2 59290 NULL
120388 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
120389 +fd_copyout_59323 fd_copyout 3 59323 NULL
120390 +read_9287_modal_eeprom_59327 read_9287_modal_eeprom 3 59327 NULL
120391 +set_state_private_59336 set_state_private 0 59336 NULL
120392 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
120393 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
120394 +f2fs_fallocate_59377 f2fs_fallocate 4-3 59377 NULL
120395 +pvr2_debugifc_print_info_59380 pvr2_debugifc_print_info 3 59380 NULL
120396 +journal_init_dev_59384 journal_init_dev 5 59384 NULL
120397 +__net_get_random_once_59389 __net_get_random_once 2 59389 NULL
120398 +isku_sysfs_read_keys_function_59412 isku_sysfs_read_keys_function 6 59412 NULL
120399 +pci_ctrl_read_59424 pci_ctrl_read 0 59424 NULL
120400 +vxge_hw_ring_rxds_per_block_get_59425 vxge_hw_ring_rxds_per_block_get 0 59425 NULL
120401 +snd_pcm_tstamp_59431 snd_pcm_tstamp 0 59431 NULL
120402 +SyS_sched_setaffinity_59442 SyS_sched_setaffinity 2 59442 NULL
120403 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
120404 +tipc_recv_stream_59456 tipc_recv_stream 4 59456 NULL
120405 +_iwl_dbgfs_bcast_filters_write_59491 _iwl_dbgfs_bcast_filters_write 3 59491 NULL
120406 +rtw_cfg80211_set_mgnt_wpsp2pie_59497 rtw_cfg80211_set_mgnt_wpsp2pie 3 59497 NULL
120407 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
120408 +C_SYSC_get_mempolicy_59516 C_SYSC_get_mempolicy 3 59516 NULL
120409 +mic_vringh_copy_59523 mic_vringh_copy 4 59523 NULL
120410 +msix_setup_entries_59545 msix_setup_entries 0 59545 NULL nohasharray
120411 +idr_alloc_59545 idr_alloc 0 59545 &msix_setup_entries_59545
120412 +mpi_get_nbits_59551 mpi_get_nbits 0 59551 NULL
120413 +tunables_write_59563 tunables_write 3 59563 NULL
120414 +bio_split_59564 bio_split 2 59564 NULL
120415 +__copy_from_user_ll_nozero_59571 __copy_from_user_ll_nozero 0-3 59571 NULL
120416 +memdup_user_59590 memdup_user 2 59590 NULL
120417 +xrcdn_free_res_59616 xrcdn_free_res 5 59616 NULL nohasharray
120418 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 &xrcdn_free_res_59616
120419 +ath6kl_endpoint_stats_write_59621 ath6kl_endpoint_stats_write 3 59621 NULL
120420 +mtrr_write_59622 mtrr_write 3 59622 NULL
120421 +find_first_zero_bit_59636 find_first_zero_bit 0 59636 NULL
120422 +SyS_setdomainname_59646 SyS_setdomainname 2 59646 NULL
120423 +file_update_time_59647 file_update_time 0 59647 NULL
120424 +hidraw_read_59650 hidraw_read 3 59650 NULL
120425 +v9fs_xattr_set_acl_59651 v9fs_xattr_set_acl 4 59651 NULL
120426 +__devcgroup_check_permission_59665 __devcgroup_check_permission 0 59665 NULL
120427 +iwl_dbgfs_mac_params_read_59666 iwl_dbgfs_mac_params_read 3 59666 NULL
120428 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
120429 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
120430 +ioperm_get_59701 ioperm_get 4-3 59701 NULL
120431 +snd_pcm_info_user_59711 snd_pcm_info_user 0 59711 NULL
120432 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
120433 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 NULL
120434 +fat_direct_IO_59741 fat_direct_IO 4 59741 NULL
120435 +qib_decode_7220_sdma_errs_59745 qib_decode_7220_sdma_errs 4 59745 NULL
120436 +strnlen_59746 strnlen 0 59746 NULL
120437 +ext3_acl_count_59754 ext3_acl_count 0-1 59754 NULL
120438 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL nohasharray
120439 +cap_inode_need_killpriv_59766 cap_inode_need_killpriv 0 59766 &long_retry_limit_read_59766
120440 +venus_remove_59781 venus_remove 4 59781 NULL
120441 +mei_nfc_recv_59784 mei_nfc_recv 3 59784 NULL
120442 +C_SYSC_preadv_59801 C_SYSC_preadv 3 59801 NULL
120443 +ipw_write_59807 ipw_write 3 59807 NULL
120444 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
120445 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
120446 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
120447 +regmap_raw_write_async_59849 regmap_raw_write_async 2-4 59849 NULL
120448 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
120449 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
120450 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
120451 +kvm_mmu_notifier_invalidate_range_start_59944 kvm_mmu_notifier_invalidate_range_start 3-4 59944 NULL
120452 +ath10k_read_dfs_stats_59949 ath10k_read_dfs_stats 3 59949 NULL
120453 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 NULL nohasharray
120454 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 &dapm_widget_power_read_file_59950
120455 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
120456 +__arch_hweight16_59975 __arch_hweight16 0 59975 NULL
120457 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
120458 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
120459 +ieee80211_if_fmt_dot11MeshAwakeWindowDuration_60006 ieee80211_if_fmt_dot11MeshAwakeWindowDuration 3 60006 NULL
120460 +copy_items_60009 copy_items 7 60009 NULL
120461 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
120462 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
120463 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
120464 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
120465 +bio_integrity_hw_sectors_60039 bio_integrity_hw_sectors 0-2 60039 NULL
120466 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
120467 +vcs_size_60050 vcs_size 0 60050 NULL
120468 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 NULL
120469 +compat_writev_60063 compat_writev 3 60063 NULL
120470 +ath6kl_listen_int_write_60066 ath6kl_listen_int_write 3 60066 NULL
120471 +c4iw_num_stags_60073 c4iw_num_stags 0 60073 NULL
120472 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
120473 +ieee80211_if_fmt_fwded_frames_60103 ieee80211_if_fmt_fwded_frames 3 60103 NULL
120474 +SYSC_msgsnd_60113 SYSC_msgsnd 3 60113 NULL
120475 +nfs_idmap_request_key_60124 nfs_idmap_request_key 2 60124 NULL
120476 +__mutex_lock_common_60134 __mutex_lock_common 0 60134 NULL
120477 +ld_usb_read_60156 ld_usb_read 3 60156 NULL
120478 +jmb38x_ms_count_slots_60164 jmb38x_ms_count_slots 0 60164 NULL
120479 +init_state_60165 init_state 2 60165 NULL
120480 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 NULL nohasharray
120481 +sg_build_sgat_60179 sg_build_sgat 3 60179 &jffs2_alloc_full_dirent_60179
120482 +fuse_async_req_send_60183 fuse_async_req_send 0-3 60183 NULL
120483 +arch_setup_msi_irqs_60193 arch_setup_msi_irqs 0 60193 NULL nohasharray
120484 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 &arch_setup_msi_irqs_60193
120485 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 NULL
120486 +btrfs_get_token_16_60220 btrfs_get_token_16 0 60220 NULL
120487 +irq_alloc_domain_generic_chips_60264 irq_alloc_domain_generic_chips 2-3 60264 NULL
120488 +display_crc_ctl_write_60273 display_crc_ctl_write 3 60273 NULL
120489 +printer_write_60276 printer_write 3 60276 NULL
120490 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
120491 +getDataLength_60301 getDataLength 0 60301 NULL
120492 +bch_subtract_dirty_60306 bch_subtract_dirty 3-4 60306 NULL
120493 +usb_alphatrack_write_60341 usb_alphatrack_write 3 60341 NULL
120494 +__kfifo_from_user_r_60345 __kfifo_from_user_r 5-3 60345 NULL
120495 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
120496 +ubi_eba_atomic_leb_change_60379 ubi_eba_atomic_leb_change 0 60379 NULL
120497 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
120498 +ocfs2_zero_extend_60396 ocfs2_zero_extend 3 60396 NULL
120499 +driver_names_read_60399 driver_names_read 3 60399 NULL
120500 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
120501 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
120502 +kmalloc_60432 kmalloc 1 60432 NULL nohasharray
120503 +tstats_write_60432 tstats_write 3 60432 &kmalloc_60432
120504 +snd_hda_get_num_raw_conns_60462 snd_hda_get_num_raw_conns 0 60462 NULL
120505 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
120506 +lustre_msg_early_size_60496 lustre_msg_early_size 0 60496 NULL
120507 +compat_SyS_get_mempolicy_60527 compat_SyS_get_mempolicy 3 60527 NULL
120508 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
120509 +nonpaging_map_60551 nonpaging_map 4 60551 NULL
120510 +osc_lockless_truncate_seq_write_60553 osc_lockless_truncate_seq_write 3 60553 NULL
120511 +tracing_entries_write_60563 tracing_entries_write 3 60563 NULL
120512 +memblock_virt_alloc_try_nid_nopanic_60604 memblock_virt_alloc_try_nid_nopanic 1 60604 NULL
120513 +inode_change_ok_60614 inode_change_ok 0 60614 NULL
120514 +skb_transport_offset_60619 skb_transport_offset 0 60619 NULL
120515 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
120516 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
120517 +__proc_lnet_stats_60647 __proc_lnet_stats 5 60647 NULL
120518 +if_sdio_host_to_card_60666 if_sdio_host_to_card 4 60666 NULL
120519 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
120520 +vga_rcrt_60731 vga_rcrt 0 60731 NULL
120521 +snd_ice1712_ds_read_60754 snd_ice1712_ds_read 0 60754 NULL
120522 +raid_status_60755 raid_status 5 60755 NULL
120523 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
120524 +opticon_write_60775 opticon_write 4 60775 NULL
120525 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
120526 +snd_pcm_oss_readv3_60792 snd_pcm_oss_readv3 3 60792 NULL
120527 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
120528 +__clone_and_map_data_bio_60861 __clone_and_map_data_bio 3-4 60861 NULL
120529 +alloc_buf_60864 alloc_buf 3-2 60864 NULL
120530 +generic_writepages_60871 generic_writepages 0 60871 NULL
120531 +ubifs_read_one_lp_60882 ubifs_read_one_lp 0 60882 NULL
120532 +ext4_update_inline_data_60888 ext4_update_inline_data 3 60888 NULL
120533 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
120534 +libcfs_sock_ioctl_60915 libcfs_sock_ioctl 0 60915 NULL
120535 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
120536 +submit_extent_page_60928 submit_extent_page 5 60928 NULL
120537 +pti_char_write_60960 pti_char_write 3 60960 NULL
120538 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
120539 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
120540 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
120541 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
120542 +graph_depth_write_61024 graph_depth_write 3 61024 NULL
120543 +sdhci_pltfm_register_61031 sdhci_pltfm_register 3 61031 NULL
120544 +lpfc_idiag_queacc_write_61043 lpfc_idiag_queacc_write 3 61043 NULL
120545 +symtab_init_61050 symtab_init 2 61050 NULL
120546 +fuse_send_write_61053 fuse_send_write 0-4 61053 NULL
120547 +snd_pcm_pause_61054 snd_pcm_pause 0 61054 NULL
120548 +bitmap_scnlistprintf_61062 bitmap_scnlistprintf 2-0 61062 NULL
120549 +ahash_align_buffer_size_61070 ahash_align_buffer_size 0-1-2 61070 NULL
120550 +snd_pcm_update_hw_ptr0_61084 snd_pcm_update_hw_ptr0 0 61084 NULL
120551 +get_derived_key_61100 get_derived_key 4 61100 NULL
120552 +i40e_calculate_l2fpm_size_61104 i40e_calculate_l2fpm_size 0-4-3-2-1 61104 NULL
120553 +alloc_chrdev_region_61112 alloc_chrdev_region 0 61112 NULL
120554 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
120555 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
120556 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
120557 +pair_device_61175 pair_device 4 61175 NULL nohasharray
120558 +event_oom_late_read_61175 event_oom_late_read 3 61175 &pair_device_61175
120559 +dio_bio_add_page_61178 dio_bio_add_page 0 61178 NULL
120560 +SyS_prctl_61202 SyS_prctl 4 61202 NULL
120561 +arch_hibernation_header_save_61212 arch_hibernation_header_save 0 61212 NULL
120562 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
120563 +v9fs_mmap_file_read_61262 v9fs_mmap_file_read 3 61262 NULL
120564 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 NULL nohasharray
120565 +find_get_pages_tag_61270 find_get_pages_tag 0 61270 &btrfs_bio_alloc_61270 nohasharray
120566 +ifalias_store_61270 ifalias_store 4 61270 &find_get_pages_tag_61270
120567 +vortex_adbdma_getlinearpos_61283 vortex_adbdma_getlinearpos 0 61283 NULL nohasharray
120568 +hfsplus_getxattr_finder_info_61283 hfsplus_getxattr_finder_info 0 61283 &vortex_adbdma_getlinearpos_61283
120569 +nvme_trans_copy_to_user_61288 nvme_trans_copy_to_user 3 61288 NULL
120570 +xfer_from_user_61307 xfer_from_user 3 61307 NULL
120571 +xfrm_user_sec_ctx_size_61320 xfrm_user_sec_ctx_size 0 61320 NULL
120572 +C_SYSC_msgsnd_61330 C_SYSC_msgsnd 3 61330 NULL
120573 +write_file_spectral_short_repeat_61335 write_file_spectral_short_repeat 3 61335 NULL
120574 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
120575 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
120576 +__dm_get_reserved_ios_61342 __dm_get_reserved_ios 0-3-2 61342 NULL
120577 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
120578 +system_enable_write_61396 system_enable_write 3 61396 NULL
120579 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
120580 +snd_pcm_lib_writev_transfer_61483 snd_pcm_lib_writev_transfer 5-4-2 61483 NULL
120581 +btrfs_item_size_61485 btrfs_item_size 0 61485 NULL
120582 +erst_errno_61526 erst_errno 0 61526 NULL
120583 +compat_SyS_select_61542 compat_SyS_select 1 61542 NULL
120584 +trace_options_core_write_61551 trace_options_core_write 3 61551 NULL
120585 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
120586 +fan_proc_write_61569 fan_proc_write 3 61569 NULL
120587 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
120588 +ldlm_pool_rw_atomic_seq_write_61572 ldlm_pool_rw_atomic_seq_write 3 61572 NULL
120589 +seq_open_private_61589 seq_open_private 3 61589 NULL
120590 +ept_gpte_to_gfn_lvl_61591 ept_gpte_to_gfn_lvl 0-2-1 61591 NULL
120591 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
120592 +nfs4_init_uniform_client_string_61601 nfs4_init_uniform_client_string 3 61601 NULL
120593 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
120594 +ieee80211_if_fmt_hw_queues_61629 ieee80211_if_fmt_hw_queues 3 61629 NULL
120595 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
120596 +snd_pcm_oss_read3_61643 snd_pcm_oss_read3 0-3 61643 NULL nohasharray
120597 +tcf_hashinfo_init_61643 tcf_hashinfo_init 2 61643 &snd_pcm_oss_read3_61643
120598 +resize_stripes_61650 resize_stripes 2 61650 NULL
120599 +ttm_page_pool_free_61661 ttm_page_pool_free 2-0 61661 NULL
120600 +insert_one_name_61668 insert_one_name 7 61668 NULL
120601 +snd_pcm_playback_avail_61671 snd_pcm_playback_avail 0 61671 NULL
120602 +qib_format_hwmsg_61679 qib_format_hwmsg 2 61679 NULL
120603 +lock_loop_61681 lock_loop 1 61681 NULL
120604 +__do_tune_cpucache_61684 __do_tune_cpucache 2 61684 NULL
120605 +filter_read_61692 filter_read 3 61692 NULL
120606 +iov_length_61716 iov_length 0 61716 NULL
120607 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
120608 +null_alloc_reqbuf_61719 null_alloc_reqbuf 3 61719 NULL
120609 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
120610 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
120611 +SyS_sendto_61763 SyS_sendto 6 61763 NULL
120612 +mls_compute_context_len_61812 mls_compute_context_len 0 61812 NULL
120613 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
120614 +regcache_sync_block_61846 regcache_sync_block 5-4 61846 NULL
120615 +ath9k_hw_def_dump_eeprom_61853 ath9k_hw_def_dump_eeprom 5-4 61853 NULL
120616 +evdev_compute_buffer_size_61863 evdev_compute_buffer_size 0 61863 NULL
120617 +SYSC_lsetxattr_61869 SYSC_lsetxattr 4 61869 NULL
120618 +get_fw_name_61874 get_fw_name 3 61874 NULL
120619 +btrfs_ioctl_clone_61886 btrfs_ioctl_clone 3-4-5 61886 NULL
120620 +lprocfs_write_frac_u64_helper_61897 lprocfs_write_frac_u64_helper 2 61897 NULL
120621 +lov_mds_md_stripecnt_61899 lov_mds_md_stripecnt 0-1 61899 NULL
120622 +clear_refs_write_61904 clear_refs_write 3 61904 NULL
120623 +kernfs_name_61910 kernfs_name 3 61910 NULL
120624 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
120625 +au0828_init_isoc_61917 au0828_init_isoc 3-2-4 61917 NULL
120626 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
120627 +SyS_kexec_load_61946 SyS_kexec_load 2 61946 NULL
120628 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
120629 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
120630 +fix_read_error_61965 fix_read_error 4 61965 NULL
120631 +cow_file_range_61979 cow_file_range 3 61979 NULL
120632 +set_extent_delalloc_61982 set_extent_delalloc 0 61982 NULL
120633 +dequeue_event_62000 dequeue_event 3 62000 NULL
120634 +xt_compat_match_offset_62011 xt_compat_match_offset 0 62011 NULL
120635 +SyS_setxattr_62019 SyS_setxattr 4 62019 NULL
120636 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
120637 +SYSC_select_62024 SYSC_select 1 62024 NULL
120638 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
120639 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
120640 +do_pselect_62061 do_pselect 1 62061 NULL
120641 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
120642 +fat_setattr_62084 fat_setattr 0 62084 NULL
120643 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
120644 +btrfs_direct_IO_62114 btrfs_direct_IO 4 62114 NULL
120645 +ip_recv_error_62117 ip_recv_error 3 62117 NULL
120646 +generic_block_fiemap_62122 generic_block_fiemap 4 62122 NULL
120647 +llc_ui_header_len_62131 llc_ui_header_len 0 62131 NULL
120648 +qib_diag_write_62133 qib_diag_write 3 62133 NULL nohasharray
120649 +kobject_add_varg_62133 kobject_add_varg 0 62133 &qib_diag_write_62133
120650 +ql_status_62135 ql_status 5 62135 NULL nohasharray
120651 +device_add_attrs_62135 device_add_attrs 0 62135 &ql_status_62135
120652 +video_usercopy_62151 video_usercopy 2 62151 NULL
120653 +SyS_getxattr_62166 SyS_getxattr 4 62166 NULL
120654 +prism54_wpa_bss_ie_get_62173 prism54_wpa_bss_ie_get 0 62173 NULL
120655 +write_file_dfs_62180 write_file_dfs 3 62180 NULL
120656 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
120657 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
120658 +smk_read_syslog_62227 smk_read_syslog 3 62227 NULL
120659 +SYSC_setgroups16_62232 SYSC_setgroups16 1 62232 NULL
120660 +nfsd_read_file_62241 nfsd_read_file 6 62241 NULL
120661 +ion_handle_test_dma_62262 ion_handle_test_dma 4-5 62262 NULL
120662 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
120663 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
120664 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
120665 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
120666 +subseq_list_62332 subseq_list 3-0 62332 NULL
120667 +ll_statahead_max_seq_write_62333 ll_statahead_max_seq_write 3 62333 NULL
120668 +flash_write_62354 flash_write 3 62354 NULL
120669 +xfpregs_set_62363 xfpregs_set 4 62363 NULL
120670 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
120671 +altera_irscan_62396 altera_irscan 2 62396 NULL
120672 +set_ssp_62411 set_ssp 4 62411 NULL
120673 +udf_expand_file_adinicb_62470 udf_expand_file_adinicb 0 62470 NULL
120674 +ext_rts51x_sd_execute_read_data_62501 ext_rts51x_sd_execute_read_data 9 62501 NULL
120675 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
120676 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
120677 +debugfs_read_62535 debugfs_read 3 62535 NULL
120678 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
120679 +qib_refresh_qsfp_cache_62547 qib_refresh_qsfp_cache 0 62547 NULL
120680 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
120681 +get_subdir_62581 get_subdir 3 62581 NULL
120682 +nfsd_vfs_read_62605 nfsd_vfs_read 6 62605 NULL
120683 +dut_mode_write_62630 dut_mode_write 3 62630 NULL
120684 +vfs_fsync_range_62635 vfs_fsync_range 0 62635 NULL
120685 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
120686 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
120687 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
120688 +gfs2_log_write_62717 gfs2_log_write 3 62717 NULL
120689 +rdm_62719 rdm 0 62719 NULL
120690 +obd_ioctl_popdata_62741 obd_ioctl_popdata 3 62741 NULL
120691 +key_replays_read_62746 key_replays_read 3 62746 NULL
120692 +lov_verify_lmm_62747 lov_verify_lmm 2 62747 NULL
120693 +mwifiex_rdeeprom_write_62754 mwifiex_rdeeprom_write 3 62754 NULL
120694 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 NULL
120695 +C_SYSC_ipc_62776 C_SYSC_ipc 3 62776 NULL
120696 +SyS_sched_getaffinity_62786 SyS_sched_getaffinity 2 62786 NULL
120697 +dm_stats_account_io_62787 dm_stats_account_io 3 62787 NULL
120698 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
120699 +__rounddown_pow_of_two_62836 __rounddown_pow_of_two 0 62836 NULL
120700 +bio_get_nr_vecs_62838 bio_get_nr_vecs 0 62838 NULL
120701 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
120702 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
120703 +read_nic_io_dword_62859 read_nic_io_dword 0 62859 NULL
120704 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
120705 +aoechr_write_62883 aoechr_write 3 62883 NULL
120706 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
120707 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
120708 +getdqbuf_62908 getdqbuf 1 62908 NULL
120709 +ll_statahead_agl_seq_write_62928 ll_statahead_agl_seq_write 3 62928 NULL
120710 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
120711 +kstrtoull_from_user_63026 kstrtoull_from_user 2 63026 NULL
120712 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
120713 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
120714 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
120715 +unlink1_63059 unlink1 3 63059 NULL
120716 +xen_set_nslabs_63066 xen_set_nslabs 0 63066 NULL
120717 +iwl_dbgfs_fw_rx_stats_read_63070 iwl_dbgfs_fw_rx_stats_read 3 63070 NULL
120718 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5 63087 NULL
120719 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
120720 +ext4_chunk_trans_blocks_63123 ext4_chunk_trans_blocks 0-2 63123 NULL
120721 +snd_pcm_status_user_63140 snd_pcm_status_user 0 63140 NULL
120722 +ubifs_change_one_lp_63157 ubifs_change_one_lp 0 63157 NULL
120723 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
120724 +SyS_syslog_63178 SyS_syslog 3 63178 NULL
120725 +vme_master_read_63221 vme_master_read 0 63221 NULL
120726 +SyS_gethostname_63227 SyS_gethostname 2 63227 NULL
120727 +ptp_read_63251 ptp_read 4 63251 NULL
120728 +xfs_dir2_leaf_getdents_63262 xfs_dir2_leaf_getdents 3 63262 NULL
120729 +iwl_dbgfs_fw_error_dump_read_63263 iwl_dbgfs_fw_error_dump_read 3 63263 NULL
120730 +raid5_resize_63306 raid5_resize 2 63306 NULL
120731 +ath10k_read_fw_dbglog_63323 ath10k_read_fw_dbglog 3 63323 NULL
120732 +proc_info_read_63344 proc_info_read 3 63344 NULL
120733 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
120734 +idmouse_read_63374 idmouse_read 3 63374 NULL
120735 +usbnet_read_cmd_nopm_63388 usbnet_read_cmd_nopm 7 63388 NULL nohasharray
120736 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 &usbnet_read_cmd_nopm_63388
120737 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
120738 +nouveau_event_create_63411 nouveau_event_create 1 63411 NULL
120739 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
120740 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
120741 +si5351_bulk_write_63468 si5351_bulk_write 2-3 63468 NULL
120742 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
120743 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
120744 +read_kcore_63488 read_kcore 3 63488 NULL
120745 +iwl_dbgfs_bcast_filters_read_63489 iwl_dbgfs_bcast_filters_read 3 63489 NULL
120746 +snd_pcm_plug_write_transfer_63503 snd_pcm_plug_write_transfer 0-3 63503 NULL
120747 +efx_mcdi_rpc_async_63529 efx_mcdi_rpc_async 4-5 63529 NULL
120748 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL nohasharray
120749 +generic_cont_expand_simple_63534 generic_cont_expand_simple 0 63534 &ubi_more_leb_change_data_63534
120750 +write_file_spectral_period_63536 write_file_spectral_period 3 63536 NULL
120751 +if_sdio_read_scratch_63540 if_sdio_read_scratch 0 63540 NULL
120752 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
120753 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 NULL
120754 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
120755 +write_debug_level_63613 write_debug_level 3 63613 NULL
120756 +__spi_validate_63618 __spi_validate 0 63618 NULL
120757 +symbol_build_supp_rates_63634 symbol_build_supp_rates 0 63634 NULL
120758 +hid_report_len_63637 hid_report_len 0 63637 NULL
120759 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
120760 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
120761 +ldlm_cli_enqueue_63657 ldlm_cli_enqueue 8 63657 NULL
120762 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
120763 +vbi_read_63673 vbi_read 3 63673 NULL
120764 +write_file_spectral_fft_period_63696 write_file_spectral_fft_period 3 63696 NULL
120765 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
120766 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
120767 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
120768 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
120769 +snd_pcm_link_63772 snd_pcm_link 0 63772 NULL
120770 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
120771 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
120772 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
120773 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
120774 +C_SYSC_process_vm_readv_63811 C_SYSC_process_vm_readv 3-5 63811 NULL
120775 +regmap_multi_reg_write_63826 regmap_multi_reg_write 3 63826 NULL
120776 +sel_write_load_63830 sel_write_load 3 63830 NULL
120777 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
120778 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
120779 +uvc_alloc_urb_buffers_63922 uvc_alloc_urb_buffers 0-2-3 63922 NULL
120780 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
120781 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
120782 +__team_options_register_63941 __team_options_register 3 63941 NULL
120783 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
120784 +set_bredr_63975 set_bredr 4 63975 NULL
120785 +construct_key_and_link_63985 construct_key_and_link 3 63985 NULL
120786 +rs_extent_to_bm_page_63996 rs_extent_to_bm_page 0-1 63996 NULL
120787 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
120788 +SyS_rt_sigpending_64018 SyS_rt_sigpending 2 64018 NULL
120789 +dbAllocDmapLev_64030 dbAllocDmapLev 0 64030 NULL
120790 +SyS_fsetxattr_64039 SyS_fsetxattr 4 64039 NULL
120791 +get_u8_64076 get_u8 0 64076 NULL
120792 +xilly_malloc_64077 xilly_malloc 2 64077 NULL
120793 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
120794 +vmci_handle_arr_get_size_64088 vmci_handle_arr_get_size 0 64088 NULL
120795 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
120796 +SyS_set_mempolicy_64096 SyS_set_mempolicy 3 64096 NULL
120797 +to_bytes_64103 to_bytes 0-1 64103 NULL
120798 +SyS_mq_timedsend_64107 SyS_mq_timedsend 3 64107 NULL
120799 +rdma_addr_size_64116 rdma_addr_size 0 64116 NULL
120800 +do_load_xattr_datum_64118 do_load_xattr_datum 0 64118 NULL
120801 +bypass_wd_write_64120 bypass_wd_write 3 64120 NULL
120802 +ext4_prepare_inline_data_64124 ext4_prepare_inline_data 3 64124 NULL
120803 +init_bch_64130 init_bch 1-2 64130 NULL
120804 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
120805 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
120806 +bnx2x_vf_mcast_64166 bnx2x_vf_mcast 4 64166 NULL
120807 +cpumask_scnprintf_64170 cpumask_scnprintf 0-2 64170 NULL
120808 +kernfs_iop_setxattr_64220 kernfs_iop_setxattr 4 64220 NULL
120809 +xfs_vm_direct_IO_64223 xfs_vm_direct_IO 4 64223 NULL
120810 +read_pulse_64227 read_pulse 0-3 64227 NULL
120811 +ea_len_64229 ea_len 0 64229 NULL
120812 +io_capture_transfer_64276 io_capture_transfer 4 64276 NULL
120813 +btrfs_file_extent_offset_64278 btrfs_file_extent_offset 0 64278 NULL
120814 +sta_current_tx_rate_read_64286 sta_current_tx_rate_read 3 64286 NULL
120815 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 NULL nohasharray
120816 +event_id_read_64288 event_id_read 3 64288 &xfs_dir_cilookup_result_64288
120817 +ocfs2_block_check_validate_bhs_64302 ocfs2_block_check_validate_bhs 0 64302 NULL
120818 +snd_hda_get_sub_nodes_64304 snd_hda_get_sub_nodes 0 64304 NULL
120819 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
120820 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
120821 +ts_write_64336 ts_write 3 64336 NULL
120822 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
120823 +qlcnic_82xx_calculate_msix_vector_64354 qlcnic_82xx_calculate_msix_vector 0 64354 NULL
120824 +user_regset_copyin_64360 user_regset_copyin 7 64360 NULL
120825 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
120826 +reg_create_64372 reg_create 5 64372 NULL nohasharray
120827 +bnx2_enable_msix_64372 bnx2_enable_msix 2 64372 &reg_create_64372
120828 +ilo_write_64378 ilo_write 3 64378 NULL
120829 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
120830 +vmcs_readl_64381 vmcs_readl 0 64381 NULL
120831 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
120832 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
120833 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
120834 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
120835 +keyctl_get_security_64418 keyctl_get_security 3 64418 NULL
120836 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
120837 +read_file_spectral_short_repeat_64431 read_file_spectral_short_repeat 3 64431 NULL
120838 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
120839 +__i2c_add_numbered_adapter_64445 __i2c_add_numbered_adapter 0 64445 NULL
120840 +single_open_size_64483 single_open_size 4 64483 NULL
120841 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
120842 +msg_data_sz_64503 msg_data_sz 0 64503 NULL
120843 +remove_uuid_64505 remove_uuid 4 64505 NULL
120844 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
120845 +iwl_dbgfs_ucode_tracing_write_64524 iwl_dbgfs_ucode_tracing_write 3 64524 NULL
120846 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
120847 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
120848 +SyS_bind_64544 SyS_bind 3 64544 NULL
120849 +rbd_obj_read_sync_64554 rbd_obj_read_sync 3-4 64554 NULL
120850 +__btrfs_prealloc_file_range_64557 __btrfs_prealloc_file_range 3 64557 NULL
120851 +ll_max_rw_chunk_seq_write_64561 ll_max_rw_chunk_seq_write 3 64561 NULL nohasharray
120852 +__spi_sync_64561 __spi_sync 0 64561 &ll_max_rw_chunk_seq_write_64561
120853 +__apei_exec_run_64563 __apei_exec_run 0 64563 NULL
120854 +kstrtoul_from_user_64569 kstrtoul_from_user 2 64569 NULL
120855 +do_erase_64574 do_erase 4 64574 NULL
120856 +fanotify_write_64623 fanotify_write 3 64623 NULL
120857 +_iwl_dbgfs_d0i3_refs_write_64642 _iwl_dbgfs_d0i3_refs_write 3 64642 NULL
120858 +regmap_read_debugfs_64658 regmap_read_debugfs 5 64658 NULL
120859 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 NULL nohasharray
120860 +ocfs2_read_xattr_block_64661 ocfs2_read_xattr_block 0 64661 &tlbflush_read_file_64661
120861 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
120862 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
120863 +nr_free_zone_pages_64680 nr_free_zone_pages 0 64680 NULL
120864 +snd_pcm_oss_capture_position_fixup_64713 snd_pcm_oss_capture_position_fixup 0 64713 NULL
120865 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
120866 +atomic_add_return_64720 atomic_add_return 0-1 64720 NULL
120867 +i2400m_msg_to_dev_64722 i2400m_msg_to_dev 3 64722 NULL
120868 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
120869 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
120870 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
120871 +message_for_md_64777 message_for_md 5 64777 NULL
120872 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
120873 +regmap_reg_ranges_read_file_64798 regmap_reg_ranges_read_file 3 64798 NULL
120874 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
120875 +rfkill_fop_write_64808 rfkill_fop_write 3 64808 NULL
120876 +proc_projid_map_write_64810 proc_projid_map_write 3 64810 NULL
120877 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
120878 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
120879 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
120880 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
120881 +pci_vc_do_save_buffer_64876 pci_vc_do_save_buffer 0 64876 NULL
120882 +lprocfs_write_u64_helper_64880 lprocfs_write_u64_helper 2 64880 NULL
120883 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
120884 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL nohasharray
120885 +tipc_port_iovec_reject_64958 tipc_port_iovec_reject 4 64958 &ip_options_get_from_user_64958
120886 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
120887 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
120888 +crypto_ahash_digestsize_65014 crypto_ahash_digestsize 0 65014 NULL
120889 +insert_dent_65034 insert_dent 7 65034 NULL
120890 +snd_hda_get_pin_label_65035 snd_hda_get_pin_label 5 65035 NULL
120891 +ext4_ind_trans_blocks_65053 ext4_ind_trans_blocks 0-2 65053 NULL
120892 +pcibios_enable_device_65059 pcibios_enable_device 0 65059 NULL
120893 +make_idx_node_65068 make_idx_node 0 65068 NULL
120894 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
120895 +batadv_socket_write_65083 batadv_socket_write 3 65083 NULL
120896 +ocfs2_truncate_cluster_pages_65086 ocfs2_truncate_cluster_pages 2 65086 NULL
120897 +ath9k_dump_mci_btcoex_65090 ath9k_dump_mci_btcoex 3-0 65090 NULL
120898 +scsi_add_host_with_dma_65093 scsi_add_host_with_dma 0 65093 NULL
120899 +generic_ocp_write_65107 generic_ocp_write 4 65107 NULL
120900 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
120901 +print_endpoint_stat_65232 print_endpoint_stat 0-3-4 65232 NULL
120902 +whci_n_caps_65247 whci_n_caps 0 65247 NULL
120903 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
120904 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
120905 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
120906 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
120907 +get_var_len_65304 get_var_len 0 65304 NULL
120908 +unpack_array_65318 unpack_array 0 65318 NULL
120909 +pci_vpd_find_tag_65325 pci_vpd_find_tag 0-2 65325 NULL
120910 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
120911 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
120912 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
120913 +SyS_writev_65372 SyS_writev 3 65372 NULL
120914 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
120915 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
120916 +__read_vmcore_65402 __read_vmcore 2 65402 NULL
120917 +ocfs2_write_begin_nolock_65410 ocfs2_write_begin_nolock 3-4 65410 NULL
120918 +device_add_groups_65423 device_add_groups 0 65423 NULL
120919 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
120920 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
120921 +il_dbgfs_wd_timeout_write_65464 il_dbgfs_wd_timeout_write 3 65464 NULL
120922 +clear_user_65470 clear_user 2 65470 NULL
120923 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
120924 +lookup_inline_extent_backref_65493 lookup_inline_extent_backref 9 65493 NULL
120925 +nvme_trans_standard_inquiry_page_65526 nvme_trans_standard_inquiry_page 4 65526 NULL
120926 +tree_mod_log_eb_copy_65535 tree_mod_log_eb_copy 6 65535 NULL
120927 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
120928 new file mode 100644
120929 index 0000000..560cd7b
120930 --- /dev/null
120931 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
120932 @@ -0,0 +1,92 @@
120933 +spa_set_aux_vdevs_746 spa_set_aux_vdevs 3 746 NULL
120934 +zfs_lookup_2144 zfs_lookup 0 2144 NULL
120935 +mappedread_2627 mappedread 2 2627 NULL
120936 +vdev_disk_dio_alloc_2957 vdev_disk_dio_alloc 1 2957 NULL
120937 +nv_alloc_pushpage_spl_4286 nv_alloc_pushpage_spl 2 4286 NULL
120938 +zpl_xattr_get_4574 zpl_xattr_get 0 4574 NULL
120939 +sa_replace_all_by_template_5699 sa_replace_all_by_template 3 5699 NULL
120940 +dmu_write_6048 dmu_write 4-3 6048 NULL
120941 +dmu_buf_hold_array_6095 dmu_buf_hold_array 4-3 6095 NULL
120942 +update_pages_6225 update_pages 2-3 6225 NULL
120943 +bio_nr_pages_7117 bio_nr_pages 0-2 7117 NULL
120944 +dmu_buf_hold_array_by_bonus_8562 dmu_buf_hold_array_by_bonus 3-2 8562 NULL
120945 +zpios_dmu_write_8858 zpios_dmu_write 4-5 8858 NULL
120946 +ddi_copyout_9401 ddi_copyout 3 9401 NULL
120947 +avl_numnodes_12384 avl_numnodes 0 12384 NULL
120948 +dmu_write_uio_dnode_12473 dmu_write_uio_dnode 3 12473 NULL
120949 +dmu_xuio_init_12866 dmu_xuio_init 2 12866 NULL
120950 +zpl_read_common_14389 zpl_read_common 0 14389 NULL
120951 +dmu_snapshot_realname_14632 dmu_snapshot_realname 4 14632 NULL
120952 +kmem_alloc_debug_14852 kmem_alloc_debug 1 14852 NULL
120953 +kmalloc_node_nofail_15151 kmalloc_node_nofail 1 15151 NULL
120954 +dmu_write_uio_16351 dmu_write_uio 4 16351 NULL
120955 +zfs_log_write_16524 zfs_log_write 6-5 16524 NULL
120956 +sa_build_layouts_16910 sa_build_layouts 3 16910 NULL
120957 +dsl_dir_namelen_17053 dsl_dir_namelen 0 17053 NULL
120958 +kcopy_copy_to_user_17336 kcopy_copy_to_user 5 17336 NULL
120959 +sa_add_layout_entry_17507 sa_add_layout_entry 3 17507 NULL
120960 +sa_attr_table_setup_18029 sa_attr_table_setup 3 18029 NULL
120961 +uiocopy_18680 uiocopy 2 18680 NULL
120962 +dmu_buf_hold_array_by_dnode_19125 dmu_buf_hold_array_by_dnode 2-3 19125 NULL
120963 +zpl_acl_from_xattr_21141 zpl_acl_from_xattr 2 21141 NULL
120964 +dsl_pool_tx_assign_init_22518 dsl_pool_tx_assign_init 2 22518 NULL
120965 +nvlist_lookup_byte_array_22527 nvlist_lookup_byte_array 0 22527 NULL
120966 +sa_replace_all_by_template_locked_22533 sa_replace_all_by_template_locked 3 22533 NULL
120967 +tsd_hash_table_init_22559 tsd_hash_table_init 1 22559 NULL
120968 +spa_vdev_remove_aux_23966 spa_vdev_remove_aux 4 23966 NULL
120969 +zpl_xattr_acl_set_access_24129 zpl_xattr_acl_set_access 4 24129 NULL
120970 +dmu_assign_arcbuf_24622 dmu_assign_arcbuf 2 24622 NULL
120971 +zap_lookup_norm_25166 zap_lookup_norm 9 25166 NULL
120972 +dmu_prealloc_25456 dmu_prealloc 4-3 25456 NULL
120973 +kmalloc_nofail_26347 kmalloc_nofail 1 26347 NULL
120974 +zfsctl_snapshot_zpath_27578 zfsctl_snapshot_zpath 2 27578 NULL
120975 +zpios_dmu_read_30015 zpios_dmu_read 4-5 30015 NULL
120976 +splat_write_30943 splat_write 3 30943 NULL
120977 +zpl_xattr_get_sa_31183 zpl_xattr_get_sa 0 31183 NULL
120978 +dmu_read_uio_31467 dmu_read_uio 4 31467 NULL
120979 +zfs_replay_fuids_31479 zfs_replay_fuids 4 31479 NULL
120980 +spa_history_log_to_phys_31632 spa_history_log_to_phys 0-1 31632 NULL
120981 +__zpl_xattr_get_32601 __zpl_xattr_get 0 32601 NULL
120982 +proc_copyout_string_34049 proc_copyout_string 2 34049 NULL
120983 +nv_alloc_sleep_spl_34544 nv_alloc_sleep_spl 2 34544 NULL
120984 +nv_alloc_nosleep_spl_34761 nv_alloc_nosleep_spl 2 34761 NULL
120985 +zap_leaf_array_match_36922 zap_leaf_array_match 4 36922 NULL
120986 +copyinstr_36980 copyinstr 3 36980 NULL
120987 +zpl_xattr_acl_set_default_37864 zpl_xattr_acl_set_default 4 37864 NULL
120988 +splat_read_38116 splat_read 3 38116 NULL
120989 +sa_setup_38756 sa_setup 4 38756 NULL
120990 +vdev_disk_physio_39898 vdev_disk_physio 3 39898 NULL
120991 +arc_buf_size_39982 arc_buf_size 0 39982 NULL
120992 +kzalloc_nofail_40719 kzalloc_nofail 1 40719 NULL
120993 +fuidstr_to_sid_40777 fuidstr_to_sid 4 40777 NULL
120994 +vdev_raidz_matrix_reconstruct_40852 vdev_raidz_matrix_reconstruct 2-3 40852 NULL
120995 +sa_find_layout_40892 sa_find_layout 4 40892 NULL
120996 +zpl_xattr_get_dir_41918 zpl_xattr_get_dir 0 41918 NULL
120997 +zfs_sa_get_xattr_42600 zfs_sa_get_xattr 0 42600 NULL
120998 +zpl_xattr_acl_set_42808 zpl_xattr_acl_set 4 42808 NULL
120999 +xdr_dec_array_43091 xdr_dec_array 5 43091 NULL
121000 +dsl_dataset_namelen_43136 dsl_dataset_namelen 0 43136 NULL
121001 +kcopy_write_43683 kcopy_write 3 43683 NULL
121002 +uiomove_44355 uiomove 2 44355 NULL
121003 +dmu_read_44418 dmu_read 4-3 44418 NULL
121004 +ddi_copyin_44846 ddi_copyin 3 44846 NULL
121005 +kcopy_do_get_45061 kcopy_do_get 5 45061 NULL
121006 +copyin_45945 copyin 3 45945 NULL
121007 +zil_itx_create_46555 zil_itx_create 2 46555 NULL
121008 +dmu_write_uio_dbuf_48064 dmu_write_uio_dbuf 3 48064 NULL
121009 +blk_rq_pos_48233 blk_rq_pos 0 48233 NULL
121010 +spa_history_write_49650 spa_history_write 3 49650 NULL
121011 +kcopy_copy_pages_to_user_49823 kcopy_copy_pages_to_user 3-4 49823 NULL
121012 +zfs_log_write_50162 zfs_log_write 6-5 50162 NULL
121013 +i_fm_alloc_51038 i_fm_alloc 2 51038 NULL
121014 +copyout_51409 copyout 3 51409 NULL
121015 +zvol_log_write_54898 zvol_log_write 4-3 54898 NULL
121016 +zfs_acl_node_alloc_55641 zfs_acl_node_alloc 1 55641 NULL
121017 +get_nvlist_56685 get_nvlist 2 56685 NULL
121018 +zprop_get_numprops_56820 zprop_get_numprops 0 56820 NULL
121019 +splat_taskq_test4_common_59829 splat_taskq_test4_common 5 59829 NULL
121020 +zfs_replay_domain_cnt_61399 zfs_replay_domain_cnt 0 61399 NULL
121021 +zpios_write_61823 zpios_write 3 61823 NULL
121022 +proc_copyin_string_62019 proc_copyin_string 4 62019 NULL
121023 +random_get_pseudo_bytes_64611 random_get_pseudo_bytes 2 64611 NULL
121024 +zpios_read_64734 zpios_read 3 64734 NULL
121025 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
121026 new file mode 100644
121027 index 0000000..95f7abd
121028 --- /dev/null
121029 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
121030 @@ -0,0 +1,259 @@
121031 +/*
121032 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
121033 + * Licensed under the GPL v2, or (at your option) v3
121034 + *
121035 + * Homepage:
121036 + * http://www.grsecurity.net/~ephox/overflow_plugin/
121037 + *
121038 + * Documentation:
121039 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
121040 + *
121041 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
121042 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
121043 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
121044 + *
121045 + * Usage:
121046 + * $ make
121047 + * $ make run
121048 + */
121049 +
121050 +#include "gcc-common.h"
121051 +#include "size_overflow.h"
121052 +
121053 +int plugin_is_GPL_compatible;
121054 +
121055 +tree report_size_overflow_decl;
121056 +
121057 +tree size_overflow_type_HI;
121058 +tree size_overflow_type_SI;
121059 +tree size_overflow_type_DI;
121060 +tree size_overflow_type_TI;
121061 +
121062 +static struct plugin_info size_overflow_plugin_info = {
121063 + .version = "20140725",
121064 + .help = "no-size-overflow\tturn off size overflow checking\n",
121065 +};
121066 +
121067 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
121068 +{
121069 + unsigned int arg_count;
121070 + enum tree_code code = TREE_CODE(*node);
121071 +
121072 + switch (code) {
121073 + case FUNCTION_DECL:
121074 + arg_count = type_num_arguments(TREE_TYPE(*node));
121075 + break;
121076 + case FUNCTION_TYPE:
121077 + case METHOD_TYPE:
121078 + arg_count = type_num_arguments(*node);
121079 + break;
121080 + default:
121081 + *no_add_attrs = true;
121082 + error("%s: %qE attribute only applies to functions", __func__, name);
121083 + return NULL_TREE;
121084 + }
121085 +
121086 + for (; args; args = TREE_CHAIN(args)) {
121087 + tree position = TREE_VALUE(args);
121088 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
121089 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
121090 + *no_add_attrs = true;
121091 + }
121092 + }
121093 + return NULL_TREE;
121094 +}
121095 +
121096 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
121097 +{
121098 + unsigned int arg_count;
121099 + enum tree_code code = TREE_CODE(*node);
121100 +
121101 + switch (code) {
121102 + case FUNCTION_DECL:
121103 + arg_count = type_num_arguments(TREE_TYPE(*node));
121104 + break;
121105 + case FUNCTION_TYPE:
121106 + case METHOD_TYPE:
121107 + arg_count = type_num_arguments(*node);
121108 + break;
121109 + case FIELD_DECL:
121110 + return NULL_TREE;
121111 + default:
121112 + *no_add_attrs = true;
121113 + error("%qE attribute only applies to functions", name);
121114 + return NULL_TREE;
121115 + }
121116 +
121117 + if (TREE_INT_CST_HIGH(TREE_VALUE(args)) != 0)
121118 + return NULL_TREE;
121119 +
121120 + for (; args; args = TREE_CHAIN(args)) {
121121 + tree position = TREE_VALUE(args);
121122 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
121123 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
121124 + *no_add_attrs = true;
121125 + }
121126 + }
121127 + return NULL_TREE;
121128 +}
121129 +
121130 +static struct attribute_spec size_overflow_attr = {
121131 + .name = "size_overflow",
121132 + .min_length = 1,
121133 + .max_length = -1,
121134 + .decl_required = true,
121135 + .type_required = false,
121136 + .function_type_required = false,
121137 + .handler = handle_size_overflow_attribute,
121138 +#if BUILDING_GCC_VERSION >= 4007
121139 + .affects_type_identity = false
121140 +#endif
121141 +};
121142 +
121143 +static struct attribute_spec intentional_overflow_attr = {
121144 + .name = "intentional_overflow",
121145 + .min_length = 1,
121146 + .max_length = -1,
121147 + .decl_required = true,
121148 + .type_required = false,
121149 + .function_type_required = false,
121150 + .handler = handle_intentional_overflow_attribute,
121151 +#if BUILDING_GCC_VERSION >= 4007
121152 + .affects_type_identity = false
121153 +#endif
121154 +};
121155 +
121156 +static void register_attributes(void __unused *event_data, void __unused *data)
121157 +{
121158 + register_attribute(&size_overflow_attr);
121159 + register_attribute(&intentional_overflow_attr);
121160 +}
121161 +
121162 +static tree create_typedef(tree type, const char* ident)
121163 +{
121164 + tree new_type, decl;
121165 +
121166 + new_type = build_variant_type_copy(type);
121167 + decl = build_decl(BUILTINS_LOCATION, TYPE_DECL, get_identifier(ident), new_type);
121168 + DECL_ORIGINAL_TYPE(decl) = type;
121169 + TYPE_NAME(new_type) = decl;
121170 + return new_type;
121171 +}
121172 +
121173 +// Create the noreturn report_size_overflow() function decl.
121174 +static void size_overflow_start_unit(void __unused *gcc_data, void __unused *user_data)
121175 +{
121176 + tree const_char_ptr_type_node;
121177 + tree fntype;
121178 +
121179 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
121180 +
121181 + size_overflow_type_HI = create_typedef(intHI_type_node, "size_overflow_type_HI");
121182 + size_overflow_type_SI = create_typedef(intSI_type_node, "size_overflow_type_SI");
121183 + size_overflow_type_DI = create_typedef(intDI_type_node, "size_overflow_type_DI");
121184 + size_overflow_type_TI = create_typedef(intTI_type_node, "size_overflow_type_TI");
121185 +
121186 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
121187 + fntype = build_function_type_list(void_type_node,
121188 + const_char_ptr_type_node,
121189 + unsigned_type_node,
121190 + const_char_ptr_type_node,
121191 + const_char_ptr_type_node,
121192 + NULL_TREE);
121193 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
121194 +
121195 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
121196 + TREE_PUBLIC(report_size_overflow_decl) = 1;
121197 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
121198 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
121199 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
121200 +}
121201 +
121202 +
121203 +extern struct gimple_opt_pass pass_dce;
121204 +
121205 +static struct opt_pass *make_dce_pass(void)
121206 +{
121207 +#if BUILDING_GCC_VERSION >= 4009
121208 + return make_pass_dce(g);
121209 +#else
121210 + return &pass_dce.pass;
121211 +#endif
121212 +}
121213 +
121214 +
121215 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
121216 +{
121217 + int i;
121218 + const char * const plugin_name = plugin_info->base_name;
121219 + const int argc = plugin_info->argc;
121220 + const struct plugin_argument * const argv = plugin_info->argv;
121221 + bool enable = true;
121222 + struct register_pass_info insert_size_overflow_asm_pass_info;
121223 + struct register_pass_info __unused dump_before_pass_info;
121224 + struct register_pass_info __unused dump_after_pass_info;
121225 + struct register_pass_info insert_size_overflow_check_info;
121226 + struct register_pass_info dce_pass_info;
121227 + static const struct ggc_root_tab gt_ggc_r_gt_size_overflow[] = {
121228 + {
121229 + .base = &report_size_overflow_decl,
121230 + .nelt = 1,
121231 + .stride = sizeof(report_size_overflow_decl),
121232 + .cb = &gt_ggc_mx_tree_node,
121233 + .pchw = &gt_pch_nx_tree_node
121234 + },
121235 + LAST_GGC_ROOT_TAB
121236 + };
121237 +
121238 + insert_size_overflow_asm_pass_info.pass = make_insert_size_overflow_asm_pass();
121239 + insert_size_overflow_asm_pass_info.reference_pass_name = "ssa";
121240 + insert_size_overflow_asm_pass_info.ref_pass_instance_number = 1;
121241 + insert_size_overflow_asm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
121242 +
121243 + dump_before_pass_info.pass = make_dump_pass();
121244 + dump_before_pass_info.reference_pass_name = "increase_alignment";
121245 + dump_before_pass_info.ref_pass_instance_number = 1;
121246 + dump_before_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
121247 +
121248 + insert_size_overflow_check_info.pass = make_insert_size_overflow_check();
121249 + insert_size_overflow_check_info.reference_pass_name = "increase_alignment";
121250 + insert_size_overflow_check_info.ref_pass_instance_number = 1;
121251 + insert_size_overflow_check_info.pos_op = PASS_POS_INSERT_BEFORE;
121252 +
121253 + dump_after_pass_info.pass = make_dump_pass();
121254 + dump_after_pass_info.reference_pass_name = "increase_alignment";
121255 + dump_after_pass_info.ref_pass_instance_number = 1;
121256 + dump_after_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
121257 +
121258 + dce_pass_info.pass = make_dce_pass();
121259 + dce_pass_info.reference_pass_name = "vrp";
121260 + dce_pass_info.ref_pass_instance_number = 1;
121261 + dce_pass_info.pos_op = PASS_POS_INSERT_AFTER;
121262 +
121263 + if (!plugin_default_version_check(version, &gcc_version)) {
121264 + error(G_("incompatible gcc/plugin versions"));
121265 + return 1;
121266 + }
121267 +
121268 + for (i = 0; i < argc; ++i) {
121269 + if (!strcmp(argv[i].key, "no-size-overflow")) {
121270 + enable = false;
121271 + continue;
121272 + }
121273 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
121274 + }
121275 +
121276 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
121277 + if (enable) {
121278 + register_callback(plugin_name, PLUGIN_START_UNIT, &size_overflow_start_unit, NULL);
121279 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_size_overflow);
121280 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_asm_pass_info);
121281 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_before_pass_info);
121282 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_check_info);
121283 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_after_pass_info);
121284 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dce_pass_info);
121285 + }
121286 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
121287 +
121288 + return 0;
121289 +}
121290 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
121291 new file mode 100644
121292 index 0000000..0888f6c
121293 --- /dev/null
121294 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
121295 @@ -0,0 +1,364 @@
121296 +/*
121297 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
121298 + * Licensed under the GPL v2, or (at your option) v3
121299 + *
121300 + * Homepage:
121301 + * http://www.grsecurity.net/~ephox/overflow_plugin/
121302 + *
121303 + * Documentation:
121304 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
121305 + *
121306 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
121307 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
121308 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
121309 + *
121310 + * Usage:
121311 + * $ make
121312 + * $ make run
121313 + */
121314 +
121315 +#include "gcc-common.h"
121316 +#include "size_overflow.h"
121317 +
121318 +#include "size_overflow_hash.h"
121319 +#include "size_overflow_hash_aux.h"
121320 +
121321 +#define CODES_LIMIT 32
121322 +
121323 +static unsigned char get_tree_code(const_tree type)
121324 +{
121325 + switch (TREE_CODE(type)) {
121326 + case ARRAY_TYPE:
121327 + return 0;
121328 + case BOOLEAN_TYPE:
121329 + return 1;
121330 + case ENUMERAL_TYPE:
121331 + return 2;
121332 + case FUNCTION_TYPE:
121333 + return 3;
121334 + case INTEGER_TYPE:
121335 + return 4;
121336 + case POINTER_TYPE:
121337 + return 5;
121338 + case RECORD_TYPE:
121339 + return 6;
121340 + case UNION_TYPE:
121341 + return 7;
121342 + case VOID_TYPE:
121343 + return 8;
121344 + case REAL_TYPE:
121345 + return 9;
121346 + case VECTOR_TYPE:
121347 + return 10;
121348 + case REFERENCE_TYPE:
121349 + return 11;
121350 + case OFFSET_TYPE:
121351 + return 12;
121352 + case COMPLEX_TYPE:
121353 + return 13;
121354 + default:
121355 + debug_tree((tree)type);
121356 + gcc_unreachable();
121357 + }
121358 +}
121359 +
121360 +struct function_hash {
121361 + size_t tree_codes_len;
121362 + unsigned char tree_codes[CODES_LIMIT];
121363 + const_tree fndecl;
121364 + unsigned int hash;
121365 +};
121366 +
121367 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
121368 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
121369 +{
121370 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
121371 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
121372 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
121373 +
121374 + unsigned int m = 0x57559429;
121375 + unsigned int n = 0x5052acdb;
121376 + const unsigned int *key4 = (const unsigned int *)key;
121377 + unsigned int h = len;
121378 + unsigned int k = len + seed + n;
121379 + unsigned long long p;
121380 +
121381 + while (len >= 8) {
121382 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
121383 + len -= 8;
121384 + }
121385 + if (len >= 4) {
121386 + cwmixb(key4[0]) key4 += 1;
121387 + len -= 4;
121388 + }
121389 + if (len)
121390 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
121391 + cwmixb(h ^ (k + n));
121392 + return k ^ h;
121393 +
121394 +#undef cwfold
121395 +#undef cwmixa
121396 +#undef cwmixb
121397 +}
121398 +
121399 +static void set_hash(const char *fn_name, struct function_hash *fn_hash_data)
121400 +{
121401 + unsigned int fn, codes, seed = 0;
121402 +
121403 + fn = CrapWow(fn_name, strlen(fn_name), seed) & 0xffff;
121404 + codes = CrapWow((const char*)fn_hash_data->tree_codes, fn_hash_data->tree_codes_len, seed) & 0xffff;
121405 +
121406 + fn_hash_data->hash = fn ^ codes;
121407 +}
121408 +
121409 +static void set_node_codes(const_tree type, struct function_hash *fn_hash_data)
121410 +{
121411 + gcc_assert(type != NULL_TREE);
121412 + gcc_assert(TREE_CODE_CLASS(TREE_CODE(type)) == tcc_type);
121413 +
121414 + while (type && fn_hash_data->tree_codes_len < CODES_LIMIT) {
121415 + fn_hash_data->tree_codes[fn_hash_data->tree_codes_len] = get_tree_code(type);
121416 + fn_hash_data->tree_codes_len++;
121417 + type = TREE_TYPE(type);
121418 + }
121419 +}
121420 +
121421 +static void set_result_codes(const_tree node, struct function_hash *fn_hash_data)
121422 +{
121423 + const_tree result;
121424 +
121425 + gcc_assert(node != NULL_TREE);
121426 +
121427 + if (DECL_P(node)) {
121428 + result = DECL_RESULT(node);
121429 + if (result != NULL_TREE)
121430 + return set_node_codes(TREE_TYPE(result), fn_hash_data);
121431 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
121432 + }
121433 +
121434 + gcc_assert(TYPE_P(node));
121435 +
121436 + if (TREE_CODE(node) == FUNCTION_TYPE)
121437 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
121438 +
121439 + return set_node_codes(node, fn_hash_data);
121440 +}
121441 +
121442 +static void set_function_codes(struct function_hash *fn_hash_data)
121443 +{
121444 + const_tree arg, type = TREE_TYPE(fn_hash_data->fndecl);
121445 + enum tree_code code = TREE_CODE(type);
121446 +
121447 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
121448 +
121449 + set_result_codes(fn_hash_data->fndecl, fn_hash_data);
121450 +
121451 + for (arg = TYPE_ARG_TYPES(type); arg != NULL_TREE && fn_hash_data->tree_codes_len < CODES_LIMIT; arg = TREE_CHAIN(arg))
121452 + set_node_codes(TREE_VALUE(arg), fn_hash_data);
121453 +}
121454 +
121455 +static const struct size_overflow_hash *get_proper_hash_chain(const struct size_overflow_hash *entry, const char *func_name)
121456 +{
121457 + while (entry) {
121458 + if (!strcmp(entry->name, func_name))
121459 + return entry;
121460 + entry = entry->next;
121461 + }
121462 + return NULL;
121463 +}
121464 +
121465 +const struct size_overflow_hash *get_function_hash(const_tree fndecl)
121466 +{
121467 + const struct size_overflow_hash *entry;
121468 + struct function_hash fn_hash_data;
121469 + const char *func_name;
121470 +
121471 + // skip builtins __builtin_constant_p
121472 + if (DECL_BUILT_IN(fndecl))
121473 + return NULL;
121474 +
121475 + fn_hash_data.fndecl = fndecl;
121476 + fn_hash_data.tree_codes_len = 0;
121477 +
121478 + set_function_codes(&fn_hash_data);
121479 + gcc_assert(fn_hash_data.tree_codes_len != 0);
121480 +
121481 + func_name = DECL_NAME_POINTER(fn_hash_data.fndecl);
121482 + set_hash(func_name, &fn_hash_data);
121483 +
121484 + entry = size_overflow_hash[fn_hash_data.hash];
121485 + entry = get_proper_hash_chain(entry, func_name);
121486 + if (entry)
121487 + return entry;
121488 + entry = size_overflow_hash_aux[fn_hash_data.hash];
121489 + return get_proper_hash_chain(entry, func_name);
121490 +}
121491 +
121492 +static void print_missing_msg(const_tree func, unsigned int argnum)
121493 +{
121494 + location_t loc;
121495 + const char *curfunc;
121496 + struct function_hash fn_hash_data;
121497 +
121498 + fn_hash_data.fndecl = DECL_ORIGIN(func);
121499 + fn_hash_data.tree_codes_len = 0;
121500 +
121501 + loc = DECL_SOURCE_LOCATION(fn_hash_data.fndecl);
121502 + curfunc = DECL_NAME_POINTER(fn_hash_data.fndecl);
121503 +
121504 + set_function_codes(&fn_hash_data);
121505 + set_hash(curfunc, &fn_hash_data);
121506 +
121507 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, fn_hash_data.hash);
121508 +}
121509 +
121510 +unsigned int find_arg_number_tree(const_tree arg, const_tree func)
121511 +{
121512 + tree var;
121513 + unsigned int argnum = 1;
121514 +
121515 + if (TREE_CODE(arg) == SSA_NAME)
121516 + arg = SSA_NAME_VAR(arg);
121517 +
121518 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var), argnum++) {
121519 + if (!operand_equal_p(arg, var, 0) && strcmp(DECL_NAME_POINTER(var), DECL_NAME_POINTER(arg)))
121520 + continue;
121521 + if (!skip_types(var))
121522 + return argnum;
121523 + }
121524 +
121525 + return CANNOT_FIND_ARG;
121526 +}
121527 +
121528 +static const char *get_asm_string(const_gimple stmt)
121529 +{
121530 + if (!stmt)
121531 + return NULL;
121532 + if (gimple_code(stmt) != GIMPLE_ASM)
121533 + return NULL;
121534 +
121535 + return gimple_asm_string(stmt);
121536 +}
121537 +
121538 +bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt)
121539 +{
121540 + const char *str;
121541 +
121542 + str = get_asm_string(stmt);
121543 + if (!str)
121544 + return false;
121545 + return !strncmp(str, TURN_OFF_ASM_STR, sizeof(TURN_OFF_ASM_STR) - 1);
121546 +}
121547 +
121548 +bool is_size_overflow_intentional_asm_yes(const_gimple stmt)
121549 +{
121550 + const char *str;
121551 +
121552 + str = get_asm_string(stmt);
121553 + if (!str)
121554 + return false;
121555 + return !strncmp(str, YES_ASM_STR, sizeof(YES_ASM_STR) - 1);
121556 +}
121557 +
121558 +bool is_size_overflow_asm(const_gimple stmt)
121559 +{
121560 + const char *str;
121561 +
121562 + str = get_asm_string(stmt);
121563 + if (!str)
121564 + return false;
121565 + return !strncmp(str, OK_ASM_STR, sizeof(OK_ASM_STR) - 1);
121566 +}
121567 +
121568 +bool is_a_return_check(const_tree node)
121569 +{
121570 + if (TREE_CODE(node) == FUNCTION_DECL)
121571 + return true;
121572 +
121573 + gcc_assert(TREE_CODE(node) == PARM_DECL);
121574 + return false;
121575 +}
121576 +
121577 +// Get the argnum of a function decl, if node is a return then the argnum is 0
121578 +unsigned int get_function_num(const_tree node, const_tree orig_fndecl)
121579 +{
121580 + if (is_a_return_check(node))
121581 + return 0;
121582 + else
121583 + return find_arg_number_tree(node, orig_fndecl);
121584 +}
121585 +
121586 +unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl)
121587 +{
121588 + const struct size_overflow_hash *hash;
121589 + unsigned int new_argnum;
121590 + tree arg;
121591 + const_tree origarg;
121592 +
121593 + if (argnum == 0)
121594 + return argnum;
121595 +
121596 + hash = get_function_hash(fndecl);
121597 + if (hash && hash->param & (1U << argnum))
121598 + return argnum;
121599 +
121600 + if (DECL_EXTERNAL(fndecl))
121601 + return argnum;
121602 +
121603 + origarg = DECL_ARGUMENTS(DECL_ORIGIN(fndecl));
121604 + argnum--;
121605 + while (origarg && argnum) {
121606 + origarg = TREE_CHAIN(origarg);
121607 + argnum--;
121608 + }
121609 + gcc_assert(argnum == 0);
121610 + gcc_assert(origarg != NULL_TREE);
121611 +
121612 + for (arg = DECL_ARGUMENTS(fndecl), new_argnum = 1; arg; arg = TREE_CHAIN(arg), new_argnum++)
121613 + if (operand_equal_p(origarg, arg, 0) || !strcmp(DECL_NAME_POINTER(origarg), DECL_NAME_POINTER(arg)))
121614 + return new_argnum;
121615 +
121616 + return CANNOT_FIND_ARG;
121617 +}
121618 +
121619 +static bool is_in_hash_table(const_tree fndecl, unsigned int num)
121620 +{
121621 + const struct size_overflow_hash *hash;
121622 +
121623 + hash = get_function_hash(fndecl);
121624 + if (hash && (hash->param & (1U << num)))
121625 + return true;
121626 + return false;
121627 +}
121628 +
121629 +/* Check if the function has a size_overflow attribute or it is in the size_overflow hash table.
121630 + * If the function is missing everywhere then print the missing message into stderr.
121631 + */
121632 +bool is_missing_function(const_tree orig_fndecl, unsigned int num)
121633 +{
121634 + switch (DECL_FUNCTION_CODE(orig_fndecl)) {
121635 +#if BUILDING_GCC_VERSION >= 4008
121636 + case BUILT_IN_BSWAP16:
121637 +#endif
121638 + case BUILT_IN_BSWAP32:
121639 + case BUILT_IN_BSWAP64:
121640 + case BUILT_IN_EXPECT:
121641 + case BUILT_IN_MEMCMP:
121642 + return false;
121643 + default:
121644 + break;
121645 + }
121646 +
121647 + // skip test.c
121648 + if (strcmp(DECL_NAME_POINTER(current_function_decl), "coolmalloc")) {
121649 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(orig_fndecl)))
121650 + warning(0, "unnecessary size_overflow attribute on: %s\n", DECL_NAME_POINTER(orig_fndecl));
121651 + }
121652 +
121653 + if (is_in_hash_table(orig_fndecl, num))
121654 + return false;
121655 +
121656 + print_missing_msg(orig_fndecl, num);
121657 + return true;
121658 +}
121659 +
121660 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
121661 new file mode 100644
121662 index 0000000..924652b
121663 --- /dev/null
121664 +++ b/tools/gcc/stackleak_plugin.c
121665 @@ -0,0 +1,395 @@
121666 +/*
121667 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
121668 + * Licensed under the GPL v2
121669 + *
121670 + * Note: the choice of the license means that the compilation process is
121671 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
121672 + * but for the kernel it doesn't matter since it doesn't link against
121673 + * any of the gcc libraries
121674 + *
121675 + * gcc plugin to help implement various PaX features
121676 + *
121677 + * - track lowest stack pointer
121678 + *
121679 + * TODO:
121680 + * - initialize all local variables
121681 + *
121682 + * BUGS:
121683 + * - none known
121684 + */
121685 +
121686 +#include "gcc-common.h"
121687 +
121688 +int plugin_is_GPL_compatible;
121689 +
121690 +static int track_frame_size = -1;
121691 +static const char track_function[] = "pax_track_stack";
121692 +static const char check_function[] = "pax_check_alloca";
121693 +static tree track_function_decl, check_function_decl;
121694 +static bool init_locals;
121695 +
121696 +static struct plugin_info stackleak_plugin_info = {
121697 + .version = "201408011900",
121698 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
121699 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
121700 +};
121701 +
121702 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
121703 +{
121704 + gimple check_alloca;
121705 + tree alloca_size;
121706 +
121707 + // insert call to void pax_check_alloca(unsigned long size)
121708 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
121709 + check_alloca = gimple_build_call(check_function_decl, 1, alloca_size);
121710 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
121711 +}
121712 +
121713 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
121714 +{
121715 + gimple track_stack;
121716 +
121717 + // insert call to void pax_track_stack(void)
121718 + track_stack = gimple_build_call(track_function_decl, 0);
121719 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
121720 +}
121721 +
121722 +static bool is_alloca(gimple stmt)
121723 +{
121724 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
121725 + return true;
121726 +
121727 +#if BUILDING_GCC_VERSION >= 4007
121728 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
121729 + return true;
121730 +#endif
121731 +
121732 + return false;
121733 +}
121734 +
121735 +static unsigned int execute_stackleak_tree_instrument(void)
121736 +{
121737 + basic_block bb, entry_bb;
121738 + bool prologue_instrumented = false, is_leaf = true;
121739 +
121740 + entry_bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb;
121741 +
121742 + // 1. loop through BBs and GIMPLE statements
121743 + FOR_EACH_BB_FN(bb, cfun) {
121744 + gimple_stmt_iterator gsi;
121745 +
121746 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
121747 + gimple stmt;
121748 +
121749 + stmt = gsi_stmt(gsi);
121750 +
121751 + if (is_gimple_call(stmt))
121752 + is_leaf = false;
121753 +
121754 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
121755 + if (!is_alloca(stmt))
121756 + continue;
121757 +
121758 + // 2. insert stack overflow check before each __builtin_alloca call
121759 + stackleak_check_alloca(&gsi);
121760 +
121761 + // 3. insert track call after each __builtin_alloca call
121762 + stackleak_add_instrumentation(&gsi);
121763 + if (bb == entry_bb)
121764 + prologue_instrumented = true;
121765 + }
121766 + }
121767 +
121768 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
121769 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
121770 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
121771 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
121772 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
121773 + return 0;
121774 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
121775 + return 0;
121776 +
121777 + // 4. insert track call at the beginning
121778 + if (!prologue_instrumented) {
121779 + gimple_stmt_iterator gsi;
121780 +
121781 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
121782 + if (dom_info_available_p(CDI_DOMINATORS))
121783 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
121784 + gsi = gsi_start_bb(bb);
121785 + stackleak_add_instrumentation(&gsi);
121786 + }
121787 +
121788 + return 0;
121789 +}
121790 +
121791 +static unsigned int execute_stackleak_final(void)
121792 +{
121793 + rtx insn, next;
121794 +
121795 + if (cfun->calls_alloca)
121796 + return 0;
121797 +
121798 + // keep calls only if function frame is big enough
121799 + if (get_frame_size() >= track_frame_size)
121800 + return 0;
121801 +
121802 + // 1. find pax_track_stack calls
121803 + for (insn = get_insns(); insn; insn = next) {
121804 + // 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))
121805 + rtx body;
121806 +
121807 + next = NEXT_INSN(insn);
121808 + if (!CALL_P(insn))
121809 + continue;
121810 + body = PATTERN(insn);
121811 + if (GET_CODE(body) != CALL)
121812 + continue;
121813 + body = XEXP(body, 0);
121814 + if (GET_CODE(body) != MEM)
121815 + continue;
121816 + body = XEXP(body, 0);
121817 + if (GET_CODE(body) != SYMBOL_REF)
121818 + continue;
121819 +// if (strcmp(XSTR(body, 0), track_function))
121820 + if (SYMBOL_REF_DECL(body) != track_function_decl)
121821 + continue;
121822 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
121823 + // 2. delete call
121824 + delete_insn_and_edges(insn);
121825 +#if BUILDING_GCC_VERSION >= 4007
121826 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
121827 + insn = next;
121828 + next = NEXT_INSN(insn);
121829 + delete_insn_and_edges(insn);
121830 + }
121831 +#endif
121832 + }
121833 +
121834 +// print_simple_rtl(stderr, get_insns());
121835 +// print_rtl(stderr, get_insns());
121836 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
121837 +
121838 + return 0;
121839 +}
121840 +
121841 +static bool gate_stackleak_track_stack(void)
121842 +{
121843 + tree section;
121844 +
121845 + if (ix86_cmodel != CM_KERNEL)
121846 + return false;
121847 +
121848 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
121849 + if (section && TREE_VALUE(section)) {
121850 + section = TREE_VALUE(TREE_VALUE(section));
121851 +
121852 + if (!strncmp(TREE_STRING_POINTER(section), ".init.text", 10))
121853 + return false;
121854 + if (!strncmp(TREE_STRING_POINTER(section), ".devinit.text", 13))
121855 + return false;
121856 + if (!strncmp(TREE_STRING_POINTER(section), ".cpuinit.text", 13))
121857 + return false;
121858 + if (!strncmp(TREE_STRING_POINTER(section), ".meminit.text", 13))
121859 + return false;
121860 + }
121861 +
121862 + return track_frame_size >= 0;
121863 +}
121864 +
121865 +static void stackleak_start_unit(void *gcc_data, void *user_data)
121866 +{
121867 + tree fntype;
121868 +
121869 + // void pax_track_stack(void)
121870 + fntype = build_function_type_list(void_type_node, NULL_TREE);
121871 + track_function_decl = build_fn_decl(track_function, fntype);
121872 + DECL_ASSEMBLER_NAME(track_function_decl); // for LTO
121873 + TREE_PUBLIC(track_function_decl) = 1;
121874 + DECL_EXTERNAL(track_function_decl) = 1;
121875 + DECL_ARTIFICIAL(track_function_decl) = 1;
121876 +
121877 + // void pax_check_alloca(unsigned long)
121878 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
121879 + check_function_decl = build_fn_decl(check_function, fntype);
121880 + DECL_ASSEMBLER_NAME(check_function_decl); // for LTO
121881 + TREE_PUBLIC(check_function_decl) = 1;
121882 + DECL_EXTERNAL(check_function_decl) = 1;
121883 + DECL_ARTIFICIAL(check_function_decl) = 1;
121884 +}
121885 +
121886 +#if BUILDING_GCC_VERSION >= 4009
121887 +static const struct pass_data stackleak_tree_instrument_pass_data = {
121888 +#else
121889 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
121890 + .pass = {
121891 +#endif
121892 + .type = GIMPLE_PASS,
121893 + .name = "stackleak_tree_instrument",
121894 +#if BUILDING_GCC_VERSION >= 4008
121895 + .optinfo_flags = OPTGROUP_NONE,
121896 +#endif
121897 +#if BUILDING_GCC_VERSION >= 4009
121898 + .has_gate = true,
121899 + .has_execute = true,
121900 +#else
121901 + .gate = gate_stackleak_track_stack,
121902 + .execute = execute_stackleak_tree_instrument,
121903 + .sub = NULL,
121904 + .next = NULL,
121905 + .static_pass_number = 0,
121906 +#endif
121907 + .tv_id = TV_NONE,
121908 + .properties_required = PROP_gimple_leh | PROP_cfg,
121909 + .properties_provided = 0,
121910 + .properties_destroyed = 0,
121911 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
121912 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa | TODO_rebuild_cgraph_edges
121913 +#if BUILDING_GCC_VERSION < 4009
121914 + }
121915 +#endif
121916 +};
121917 +
121918 +#if BUILDING_GCC_VERSION >= 4009
121919 +static const struct pass_data stackleak_final_rtl_opt_pass_data = {
121920 +#else
121921 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
121922 + .pass = {
121923 +#endif
121924 + .type = RTL_PASS,
121925 + .name = "stackleak_final",
121926 +#if BUILDING_GCC_VERSION >= 4008
121927 + .optinfo_flags = OPTGROUP_NONE,
121928 +#endif
121929 +#if BUILDING_GCC_VERSION >= 4009
121930 + .has_gate = true,
121931 + .has_execute = true,
121932 +#else
121933 + .gate = gate_stackleak_track_stack,
121934 + .execute = execute_stackleak_final,
121935 + .sub = NULL,
121936 + .next = NULL,
121937 + .static_pass_number = 0,
121938 +#endif
121939 + .tv_id = TV_NONE,
121940 + .properties_required = 0,
121941 + .properties_provided = 0,
121942 + .properties_destroyed = 0,
121943 + .todo_flags_start = 0,
121944 + .todo_flags_finish = TODO_dump_func
121945 +#if BUILDING_GCC_VERSION < 4009
121946 + }
121947 +#endif
121948 +};
121949 +
121950 +#if BUILDING_GCC_VERSION >= 4009
121951 +namespace {
121952 +class stackleak_tree_instrument_pass : public gimple_opt_pass {
121953 +public:
121954 + stackleak_tree_instrument_pass() : gimple_opt_pass(stackleak_tree_instrument_pass_data, g) {}
121955 + bool gate() { return gate_stackleak_track_stack(); }
121956 + unsigned int execute() { return execute_stackleak_tree_instrument(); }
121957 +};
121958 +
121959 +class stackleak_final_rtl_opt_pass : public rtl_opt_pass {
121960 +public:
121961 + stackleak_final_rtl_opt_pass() : rtl_opt_pass(stackleak_final_rtl_opt_pass_data, g) {}
121962 + bool gate() { return gate_stackleak_track_stack(); }
121963 + unsigned int execute() { return execute_stackleak_final(); }
121964 +};
121965 +}
121966 +
121967 +static opt_pass *make_stackleak_tree_instrument_pass(void)
121968 +{
121969 + return new stackleak_tree_instrument_pass();
121970 +}
121971 +
121972 +static opt_pass *make_stackleak_final_rtl_opt_pass(void)
121973 +{
121974 + return new stackleak_final_rtl_opt_pass();
121975 +}
121976 +#else
121977 +static struct opt_pass *make_stackleak_tree_instrument_pass(void)
121978 +{
121979 + return &stackleak_tree_instrument_pass.pass;
121980 +}
121981 +
121982 +static struct opt_pass *make_stackleak_final_rtl_opt_pass(void)
121983 +{
121984 + return &stackleak_final_rtl_opt_pass.pass;
121985 +}
121986 +#endif
121987 +
121988 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
121989 +{
121990 + const char * const plugin_name = plugin_info->base_name;
121991 + const int argc = plugin_info->argc;
121992 + const struct plugin_argument * const argv = plugin_info->argv;
121993 + int i;
121994 + struct register_pass_info stackleak_tree_instrument_pass_info;
121995 + struct register_pass_info stackleak_final_pass_info;
121996 + static const struct ggc_root_tab gt_ggc_r_gt_stackleak[] = {
121997 + {
121998 + .base = &track_function_decl,
121999 + .nelt = 1,
122000 + .stride = sizeof(track_function_decl),
122001 + .cb = &gt_ggc_mx_tree_node,
122002 + .pchw = &gt_pch_nx_tree_node
122003 + },
122004 + {
122005 + .base = &check_function_decl,
122006 + .nelt = 1,
122007 + .stride = sizeof(check_function_decl),
122008 + .cb = &gt_ggc_mx_tree_node,
122009 + .pchw = &gt_pch_nx_tree_node
122010 + },
122011 + LAST_GGC_ROOT_TAB
122012 + };
122013 +
122014 + stackleak_tree_instrument_pass_info.pass = make_stackleak_tree_instrument_pass();
122015 +// stackleak_tree_instrument_pass_info.reference_pass_name = "tree_profile";
122016 + stackleak_tree_instrument_pass_info.reference_pass_name = "optimized";
122017 + stackleak_tree_instrument_pass_info.ref_pass_instance_number = 1;
122018 + stackleak_tree_instrument_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
122019 +
122020 + stackleak_final_pass_info.pass = make_stackleak_final_rtl_opt_pass();
122021 + stackleak_final_pass_info.reference_pass_name = "final";
122022 + stackleak_final_pass_info.ref_pass_instance_number = 1;
122023 + stackleak_final_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
122024 +
122025 + if (!plugin_default_version_check(version, &gcc_version)) {
122026 + error(G_("incompatible gcc/plugin versions"));
122027 + return 1;
122028 + }
122029 +
122030 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
122031 +
122032 + for (i = 0; i < argc; ++i) {
122033 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
122034 + if (!argv[i].value) {
122035 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
122036 + continue;
122037 + }
122038 + track_frame_size = atoi(argv[i].value);
122039 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
122040 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
122041 + continue;
122042 + }
122043 + if (!strcmp(argv[i].key, "initialize-locals")) {
122044 + if (argv[i].value) {
122045 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
122046 + continue;
122047 + }
122048 + init_locals = true;
122049 + continue;
122050 + }
122051 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
122052 + }
122053 +
122054 + register_callback(plugin_name, PLUGIN_START_UNIT, &stackleak_start_unit, NULL);
122055 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_stackleak);
122056 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
122057 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
122058 +
122059 + return 0;
122060 +}
122061 diff --git a/tools/gcc/structleak_plugin.c b/tools/gcc/structleak_plugin.c
122062 new file mode 100644
122063 index 0000000..4ee2231
122064 --- /dev/null
122065 +++ b/tools/gcc/structleak_plugin.c
122066 @@ -0,0 +1,274 @@
122067 +/*
122068 + * Copyright 2013-2014 by PaX Team <pageexec@freemail.hu>
122069 + * Licensed under the GPL v2
122070 + *
122071 + * Note: the choice of the license means that the compilation process is
122072 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
122073 + * but for the kernel it doesn't matter since it doesn't link against
122074 + * any of the gcc libraries
122075 + *
122076 + * gcc plugin to forcibly initialize certain local variables that could
122077 + * otherwise leak kernel stack to userland if they aren't properly initialized
122078 + * by later code
122079 + *
122080 + * Homepage: http://pax.grsecurity.net/
122081 + *
122082 + * Usage:
122083 + * $ # for 4.5/4.6/C based 4.7
122084 + * $ 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
122085 + * $ # for C++ based 4.7/4.8+
122086 + * $ 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
122087 + * $ gcc -fplugin=./structleak_plugin.so test.c -O2
122088 + *
122089 + * TODO: eliminate redundant initializers
122090 + * increase type coverage
122091 + */
122092 +
122093 +#include "gcc-common.h"
122094 +
122095 +// unused C type flag in all versions 4.5-4.9
122096 +#define TYPE_USERSPACE(TYPE) TYPE_LANG_FLAG_3(TYPE)
122097 +
122098 +int plugin_is_GPL_compatible;
122099 +
122100 +static struct plugin_info structleak_plugin_info = {
122101 + .version = "201401260140",
122102 + .help = "disable\tdo not activate plugin\n",
122103 +};
122104 +
122105 +static tree handle_user_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
122106 +{
122107 + *no_add_attrs = true;
122108 +
122109 + // check for types? for now accept everything linux has to offer
122110 + if (TREE_CODE(*node) != FIELD_DECL)
122111 + return NULL_TREE;
122112 +
122113 + *no_add_attrs = false;
122114 + return NULL_TREE;
122115 +}
122116 +
122117 +static struct attribute_spec user_attr = {
122118 + .name = "user",
122119 + .min_length = 0,
122120 + .max_length = 0,
122121 + .decl_required = false,
122122 + .type_required = false,
122123 + .function_type_required = false,
122124 + .handler = handle_user_attribute,
122125 +#if BUILDING_GCC_VERSION >= 4007
122126 + .affects_type_identity = true
122127 +#endif
122128 +};
122129 +
122130 +static void register_attributes(void *event_data, void *data)
122131 +{
122132 + register_attribute(&user_attr);
122133 +// register_attribute(&force_attr);
122134 +}
122135 +
122136 +static tree get_field_type(tree field)
122137 +{
122138 + return strip_array_types(TREE_TYPE(field));
122139 +}
122140 +
122141 +static bool is_userspace_type(tree type)
122142 +{
122143 + tree field;
122144 +
122145 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
122146 + tree fieldtype = get_field_type(field);
122147 + enum tree_code code = TREE_CODE(fieldtype);
122148 +
122149 + if (code == RECORD_TYPE || code == UNION_TYPE)
122150 + if (is_userspace_type(fieldtype))
122151 + return true;
122152 +
122153 + if (lookup_attribute("user", DECL_ATTRIBUTES(field)))
122154 + return true;
122155 + }
122156 + return false;
122157 +}
122158 +
122159 +static void finish_type(void *event_data, void *data)
122160 +{
122161 + tree type = (tree)event_data;
122162 +
122163 + if (TYPE_USERSPACE(type))
122164 + return;
122165 +
122166 + if (is_userspace_type(type))
122167 + TYPE_USERSPACE(type) = 1;
122168 +}
122169 +
122170 +static void initialize(tree var)
122171 +{
122172 + basic_block bb;
122173 + gimple_stmt_iterator gsi;
122174 + tree initializer;
122175 + gimple init_stmt;
122176 +
122177 + // this is the original entry bb before the forced split
122178 + // TODO: check further BBs in case more splits occured before us
122179 + bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb->next_bb;
122180 +
122181 + // first check if the variable is already initialized, warn otherwise
122182 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
122183 + gimple stmt = gsi_stmt(gsi);
122184 + tree rhs1;
122185 +
122186 + // we're looking for an assignment of a single rhs...
122187 + if (!gimple_assign_single_p(stmt))
122188 + continue;
122189 + rhs1 = gimple_assign_rhs1(stmt);
122190 +#if BUILDING_GCC_VERSION >= 4007
122191 + // ... of a non-clobbering expression...
122192 + if (TREE_CLOBBER_P(rhs1))
122193 + continue;
122194 +#endif
122195 + // ... to our variable...
122196 + if (gimple_get_lhs(stmt) != var)
122197 + continue;
122198 + // if it's an initializer then we're good
122199 + if (TREE_CODE(rhs1) == CONSTRUCTOR)
122200 + return;
122201 + }
122202 +
122203 + // these aren't the 0days you're looking for
122204 +// inform(DECL_SOURCE_LOCATION(var), "userspace variable will be forcibly initialized");
122205 +
122206 + // build the initializer expression
122207 + initializer = build_constructor(TREE_TYPE(var), NULL);
122208 +
122209 + // build the initializer stmt
122210 + init_stmt = gimple_build_assign(var, initializer);
122211 + gsi = gsi_start_bb(ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb);
122212 + gsi_insert_before(&gsi, init_stmt, GSI_NEW_STMT);
122213 + update_stmt(init_stmt);
122214 +}
122215 +
122216 +static unsigned int handle_function(void)
122217 +{
122218 + basic_block bb;
122219 + unsigned int ret = 0;
122220 + tree var;
122221 + unsigned int i;
122222 +
122223 + // split the first bb where we can put the forced initializers
122224 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
122225 + if (dom_info_available_p(CDI_DOMINATORS))
122226 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
122227 +
122228 + // enumarate all local variables and forcibly initialize our targets
122229 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
122230 + tree type = TREE_TYPE(var);
122231 +
122232 + gcc_assert(DECL_P(var));
122233 + if (!auto_var_in_fn_p(var, current_function_decl))
122234 + continue;
122235 +
122236 + // only care about structure types
122237 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
122238 + continue;
122239 +
122240 + // if the type is of interest, examine the variable
122241 + if (TYPE_USERSPACE(type))
122242 + initialize(var);
122243 + }
122244 +
122245 + return ret;
122246 +}
122247 +
122248 +#if BUILDING_GCC_VERSION >= 4009
122249 +static const struct pass_data structleak_pass_data = {
122250 +#else
122251 +static struct gimple_opt_pass structleak_pass = {
122252 + .pass = {
122253 +#endif
122254 + .type = GIMPLE_PASS,
122255 + .name = "structleak",
122256 +#if BUILDING_GCC_VERSION >= 4008
122257 + .optinfo_flags = OPTGROUP_NONE,
122258 +#endif
122259 +#if BUILDING_GCC_VERSION >= 4009
122260 + .has_gate = false,
122261 + .has_execute = true,
122262 +#else
122263 + .gate = NULL,
122264 + .execute = handle_function,
122265 + .sub = NULL,
122266 + .next = NULL,
122267 + .static_pass_number = 0,
122268 +#endif
122269 + .tv_id = TV_NONE,
122270 + .properties_required = PROP_cfg,
122271 + .properties_provided = 0,
122272 + .properties_destroyed = 0,
122273 + .todo_flags_start = 0,
122274 + .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
122275 +#if BUILDING_GCC_VERSION < 4009
122276 + }
122277 +#endif
122278 +};
122279 +
122280 +#if BUILDING_GCC_VERSION >= 4009
122281 +namespace {
122282 +class structleak_pass : public gimple_opt_pass {
122283 +public:
122284 + structleak_pass() : gimple_opt_pass(structleak_pass_data, g) {}
122285 + unsigned int execute() { return handle_function(); }
122286 +};
122287 +}
122288 +
122289 +static opt_pass *make_structleak_pass(void)
122290 +{
122291 + return new structleak_pass();
122292 +}
122293 +#else
122294 +static struct opt_pass *make_structleak_pass(void)
122295 +{
122296 + return &structleak_pass.pass;
122297 +}
122298 +#endif
122299 +
122300 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
122301 +{
122302 + int i;
122303 + const char * const plugin_name = plugin_info->base_name;
122304 + const int argc = plugin_info->argc;
122305 + const struct plugin_argument * const argv = plugin_info->argv;
122306 + bool enable = true;
122307 + struct register_pass_info structleak_pass_info;
122308 +
122309 + structleak_pass_info.pass = make_structleak_pass();
122310 + structleak_pass_info.reference_pass_name = "ssa";
122311 + structleak_pass_info.ref_pass_instance_number = 1;
122312 + structleak_pass_info.pos_op = PASS_POS_INSERT_AFTER;
122313 +
122314 + if (!plugin_default_version_check(version, &gcc_version)) {
122315 + error(G_("incompatible gcc/plugin versions"));
122316 + return 1;
122317 + }
122318 +
122319 + if (strcmp(lang_hooks.name, "GNU C")) {
122320 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
122321 + enable = false;
122322 + }
122323 +
122324 + for (i = 0; i < argc; ++i) {
122325 + if (!strcmp(argv[i].key, "disable")) {
122326 + enable = false;
122327 + continue;
122328 + }
122329 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
122330 + }
122331 +
122332 + register_callback(plugin_name, PLUGIN_INFO, NULL, &structleak_plugin_info);
122333 + if (enable) {
122334 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &structleak_pass_info);
122335 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
122336 + }
122337 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
122338 +
122339 + return 0;
122340 +}
122341 diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h
122342 index fbc6665..5e9ce79 100644
122343 --- a/tools/include/linux/compiler.h
122344 +++ b/tools/include/linux/compiler.h
122345 @@ -35,4 +35,12 @@
122346 # define unlikely(x) __builtin_expect(!!(x), 0)
122347 #endif
122348
122349 +#ifndef __size_overflow
122350 +# define __size_overflow(...)
122351 +#endif
122352 +
122353 +#ifndef __intentional_overflow
122354 +# define __intentional_overflow(...)
122355 +#endif
122356 +
122357 #endif /* _TOOLS_LINUX_COMPILER_H */
122358 diff --git a/tools/lib/api/Makefile b/tools/lib/api/Makefile
122359 index ce00f7e..0aca5e4 100644
122360 --- a/tools/lib/api/Makefile
122361 +++ b/tools/lib/api/Makefile
122362 @@ -16,7 +16,7 @@ LIB_OBJS += $(OUTPUT)fs/fs.o
122363
122364 LIBFILE = libapikfs.a
122365
122366 -CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
122367 +CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
122368 EXTLIBS = -lelf -lpthread -lrt -lm
122369 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
122370 ALL_LDFLAGS = $(LDFLAGS)
122371 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
122372 index 6789d788..4afd019e 100644
122373 --- a/tools/perf/util/include/asm/alternative-asm.h
122374 +++ b/tools/perf/util/include/asm/alternative-asm.h
122375 @@ -5,4 +5,7 @@
122376
122377 #define altinstruction_entry #
122378
122379 + .macro pax_force_retaddr rip=0, reload=0
122380 + .endm
122381 +
122382 #endif
122383 diff --git a/tools/virtio/linux/uaccess.h b/tools/virtio/linux/uaccess.h
122384 index 0a578fe..b81f62d 100644
122385 --- a/tools/virtio/linux/uaccess.h
122386 +++ b/tools/virtio/linux/uaccess.h
122387 @@ -13,7 +13,7 @@ static inline void __chk_user_ptr(const volatile void *p, size_t size)
122388 ({ \
122389 typeof(ptr) __pu_ptr = (ptr); \
122390 __chk_user_ptr(__pu_ptr, sizeof(*__pu_ptr)); \
122391 - ACCESS_ONCE(*(__pu_ptr)) = x; \
122392 + ACCESS_ONCE_RW(*(__pu_ptr)) = x; \
122393 0; \
122394 })
122395
122396 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
122397 index 56baae8..2c889c2 100644
122398 --- a/virt/kvm/kvm_main.c
122399 +++ b/virt/kvm/kvm_main.c
122400 @@ -76,12 +76,17 @@ LIST_HEAD(vm_list);
122401
122402 static cpumask_var_t cpus_hardware_enabled;
122403 static int kvm_usage_count = 0;
122404 -static atomic_t hardware_enable_failed;
122405 +static atomic_unchecked_t hardware_enable_failed;
122406
122407 struct kmem_cache *kvm_vcpu_cache;
122408 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
122409
122410 -static __read_mostly struct preempt_ops kvm_preempt_ops;
122411 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
122412 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
122413 +static struct preempt_ops kvm_preempt_ops = {
122414 + .sched_in = kvm_sched_in,
122415 + .sched_out = kvm_sched_out,
122416 +};
122417
122418 struct dentry *kvm_debugfs_dir;
122419
122420 @@ -755,7 +760,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
122421 /* We can read the guest memory with __xxx_user() later on. */
122422 if ((mem->slot < KVM_USER_MEM_SLOTS) &&
122423 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
122424 - !access_ok(VERIFY_WRITE,
122425 + !access_ok_noprefault(VERIFY_WRITE,
122426 (void __user *)(unsigned long)mem->userspace_addr,
122427 mem->memory_size)))
122428 goto out;
122429 @@ -1612,9 +1617,17 @@ EXPORT_SYMBOL_GPL(kvm_read_guest_cached);
122430
122431 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len)
122432 {
122433 - const void *zero_page = (const void *) __va(page_to_phys(ZERO_PAGE(0)));
122434 + int r;
122435 + unsigned long addr;
122436
122437 - return kvm_write_guest_page(kvm, gfn, zero_page, offset, len);
122438 + addr = gfn_to_hva(kvm, gfn);
122439 + if (kvm_is_error_hva(addr))
122440 + return -EFAULT;
122441 + r = __clear_user((void __user *)addr + offset, len);
122442 + if (r)
122443 + return -EFAULT;
122444 + mark_page_dirty(kvm, gfn);
122445 + return 0;
122446 }
122447 EXPORT_SYMBOL_GPL(kvm_clear_guest_page);
122448
122449 @@ -1864,7 +1877,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
122450 return 0;
122451 }
122452
122453 -static struct file_operations kvm_vcpu_fops = {
122454 +static file_operations_no_const kvm_vcpu_fops __read_only = {
122455 .release = kvm_vcpu_release,
122456 .unlocked_ioctl = kvm_vcpu_ioctl,
122457 #ifdef CONFIG_COMPAT
122458 @@ -2534,7 +2547,7 @@ out:
122459 }
122460 #endif
122461
122462 -static struct file_operations kvm_vm_fops = {
122463 +static file_operations_no_const kvm_vm_fops __read_only = {
122464 .release = kvm_vm_release,
122465 .unlocked_ioctl = kvm_vm_ioctl,
122466 #ifdef CONFIG_COMPAT
122467 @@ -2634,7 +2647,7 @@ out:
122468 return r;
122469 }
122470
122471 -static struct file_operations kvm_chardev_ops = {
122472 +static file_operations_no_const kvm_chardev_ops __read_only = {
122473 .unlocked_ioctl = kvm_dev_ioctl,
122474 .compat_ioctl = kvm_dev_ioctl,
122475 .llseek = noop_llseek,
122476 @@ -2660,7 +2673,7 @@ static void hardware_enable_nolock(void *junk)
122477
122478 if (r) {
122479 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
122480 - atomic_inc(&hardware_enable_failed);
122481 + atomic_inc_unchecked(&hardware_enable_failed);
122482 printk(KERN_INFO "kvm: enabling virtualization on "
122483 "CPU%d failed\n", cpu);
122484 }
122485 @@ -2716,10 +2729,10 @@ static int hardware_enable_all(void)
122486
122487 kvm_usage_count++;
122488 if (kvm_usage_count == 1) {
122489 - atomic_set(&hardware_enable_failed, 0);
122490 + atomic_set_unchecked(&hardware_enable_failed, 0);
122491 on_each_cpu(hardware_enable_nolock, NULL, 1);
122492
122493 - if (atomic_read(&hardware_enable_failed)) {
122494 + if (atomic_read_unchecked(&hardware_enable_failed)) {
122495 hardware_disable_all_nolock();
122496 r = -EBUSY;
122497 }
122498 @@ -3123,7 +3136,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
122499 kvm_arch_vcpu_put(vcpu);
122500 }
122501
122502 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
122503 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
122504 struct module *module)
122505 {
122506 int r;
122507 @@ -3170,7 +3183,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
122508 if (!vcpu_align)
122509 vcpu_align = __alignof__(struct kvm_vcpu);
122510 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
122511 - 0, NULL);
122512 + SLAB_USERCOPY, NULL);
122513 if (!kvm_vcpu_cache) {
122514 r = -ENOMEM;
122515 goto out_free_3;
122516 @@ -3180,9 +3193,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
122517 if (r)
122518 goto out_free;
122519
122520 + pax_open_kernel();
122521 kvm_chardev_ops.owner = module;
122522 kvm_vm_fops.owner = module;
122523 kvm_vcpu_fops.owner = module;
122524 + pax_close_kernel();
122525
122526 r = misc_register(&kvm_dev);
122527 if (r) {
122528 @@ -3192,9 +3207,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
122529
122530 register_syscore_ops(&kvm_syscore_ops);
122531
122532 - kvm_preempt_ops.sched_in = kvm_sched_in;
122533 - kvm_preempt_ops.sched_out = kvm_sched_out;
122534 -
122535 r = kvm_init_debug();
122536 if (r) {
122537 printk(KERN_ERR "kvm: create debugfs files failed\n");